Class Equivalence.Wrapper<T>

  • All Implemented Interfaces:
    Enclosing class:
    Equivalence<T>

    public static final class Equivalence.Wrapper<T>
    extends 
    implements 
    Wraps an object so that equals(Object) and hashCode() delegate to an Equivalence.

    For example, given an named equiv that tests equivalence using their lengths:

    
     equiv.wrap("a").equals(equiv.wrap("b")) // true
     equiv.wrap("a").equals(equiv.wrap("hello")) // false
     

    Note in particular that an equivalence wrapper is never equal to the object it wraps.

    
     equiv.wrap(obj).equals(obj) // always false
     
    Since:
    10.0
    See Also:
    Serialized Form
    • Method Detail

      • get

        public  T get()
        Returns the (possibly null) reference wrapped by this instance.
      • equals

        public boolean   obj)
        Returns true if Equivalence.equivalent(Object, Object) applied to the wrapped references is true and both wrappers use the equivalence.
        Overrides:
         in class 
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
        See Also:
        ,
      • hashCode

        public int hashCode()
        Returns the result of Equivalence.hash(Object) applied to the wrapped reference.
        Overrides:
         in class 
        Returns:
        a hash code value for this object.
        See Also:
        ,
      • toString

        public  toString()
        Returns a string representation for this equivalence wrapper. The form of this string representation is not specified.
        Overrides:
         in class 
        Returns:
        a string representation of the object.