Coverage Report - org.apache.commons.functor.core.IsSame
 
Classes in this File Line Coverage Branch Coverage Complexity
IsSame
88%
8/9
100%
2/2
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.functor.core;
 18  
 
 19  
 import java.io.Serializable;
 20  
 
 21  
 import org.apache.commons.functor.BinaryPredicate;
 22  
 import org.apache.commons.functor.UnaryPredicate;
 23  
 import org.apache.commons.functor.adapter.RightBoundPredicate;
 24  
 
 25  
 /**
 26  
  * {@link #test Tests} the reference (==) equality of its arguments.
 27  
  *
 28  
  * @param <L> the left argument type.
 29  
  * @param <R> the right argument type.
 30  
  * @version $Revision: 1160410 $ $Date: 2011-08-22 22:06:40 +0200 (Mon, 22 Aug 2011) $
 31  
  * @author Matt Benson
 32  
  */
 33  
 public final class IsSame<L, R> implements BinaryPredicate<L, R>, Serializable {
 34  
     // static attributes
 35  
     // ------------------------------------------------------------------------
 36  
     /**
 37  
      * Basic IsSame<Object, Object> instance.
 38  
      */
 39  2
     public static final IsSame<Object, Object> INSTANCE = IsSame.<Object, Object>instance();
 40  
     /**
 41  
      * serialVersionUID declaration.
 42  
      */
 43  
     private static final long serialVersionUID = 7024585699909734072L;
 44  
 
 45  
     // constructor
 46  
     // ------------------------------------------------------------------------
 47  
     /**
 48  
      * Create a new IsSame.
 49  
      */
 50  26
     public IsSame() {
 51  26
     }
 52  
 
 53  
     // predicate interface
 54  
     // ------------------------------------------------------------------------
 55  
     /**
 56  
      * {@inheritDoc}
 57  
      */
 58  
     public boolean test(L left, R right) {
 59  26
         return left == right;
 60  
     }
 61  
 
 62  
     /**
 63  
      * {@inheritDoc}
 64  
      */
 65  
     public boolean equals(Object that) {
 66  44
         return that instanceof IsSame<?, ?>;
 67  
     }
 68  
 
 69  
     /**
 70  
      * {@inheritDoc}
 71  
      */
 72  
     public int hashCode() {
 73  60
         return "IsSame".hashCode();
 74  
     }
 75  
 
 76  
     /**
 77  
      * {@inheritDoc}
 78  
      */
 79  
     public String toString() {
 80  44
         return "IsSame";
 81  
     }
 82  
 
 83  
     // static methods
 84  
     // ------------------------------------------------------------------------
 85  
     /**
 86  
      * Get an IsSame instance.
 87  
      * @param <L> the left argument type.
 88  
      * @param <R> the right argument type.
 89  
      * @return IsSame
 90  
      */
 91  
     public static <L, R> IsSame<L, R> instance() {
 92  12
         return new IsSame<L, R>();
 93  
     }
 94  
 
 95  
     /**
 96  
      * Get an IsSame UnaryPredicate.
 97  
      * @param <L> the left argument type.
 98  
      * @param <R> the right argument type.
 99  
      * @param object bound comparison object
 100  
      * @return UnaryPredicate<L>
 101  
      */
 102  
     public static <L, R> UnaryPredicate<L> as(R object) {
 103  0
         return new RightBoundPredicate<L>(new IsSame<L, R>(), object);
 104  
     }
 105  
 }