org.jjoost.util
Class Equalities

java.lang.Object
  extended by org.jjoost.util.Equalities

public class Equalities
extends java.lang.Object

Default implementations of Equality.

Author:
b.elliottsmith

Nested Class Summary
static class Equalities.ByteArrayEquality
          an Equality over objects of type byte[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static class Equalities.CaseInsensitiveEquality
          an Equality over String for case insensitive equality (a.equalsIgnoreCase(b)); hash() is expensive to compute as it performs toLowerCase().hashCode()
static class Equalities.EntryEquality<K,V>
          an Equality over objects of type Entry, for provided K and V; wraps a separate Equality for comparing the key and value portions of the Entry.
static class Equalities.IdentityEquality
          an Equality for identity equality, i.e.
static class Equalities.IntArrayEquality
          an Equality over objects of type int[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static class Equalities.LongArrayEquality
          an Equality over objects of type long[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static class Equalities.ObjectArrayEquality
          an Equality over objects of type Object[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static class Equalities.ObjectEquality
          Standard object equality, delegating to Object.equals() and Object.hashCode(), but handling nulls gracefully
static class Equalities.RehashingEquality<V>
          an Equality which delegates to the provided Equality, but passes the resulting hash() through the provided Rehasher before returning it
 
Constructor Summary
Equalities()
           
 
Method Summary
static Equality<byte[]> byteArray()
          Returns an Equality over objects of type byte[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static Equality<java.lang.String> caseInsensitive()
          Returns an Equality over String for case insensitive equality (a.equalsIgnoreCase(b)); hash() is expensive to compute as it performs toLowerCase().hashCode(), however a faster implementation will be provided that computes an ASCII/UTF-7 only lower case hash in the near future.
static
<K,V> Equality<java.util.Map.Entry<K,V>>
forMapEntries(Equality<? super K> keyEq, Equality<? super V> valEq)
          Returns an Equality over objects of type Entry, for provided K and V; wraps a separate Equality for comparing the key and value portions of the Entry.
static Equality<java.lang.Object> identity()
          Returns an Equality for identity equality, i.e.
static Equality<int[]> intArray()
          Returns an Equality over objects of type int[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static Equality<long[]> longArray()
          Returns an Equality over objects of type long[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static Equality<java.lang.Object> object()
          Returns an Equality for default object equality, delegating to Object.equals() and Object.hashCode(), but handling nulls gracefully
static Equality<java.lang.Object[]> objectArray()
          Returns an Equality over objects of type Object[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)
static
<V> Equality<V>
rehashing(Equality<V> delegate, Rehasher rehasher)
          Return an Equality which delegates to the provided Equality, but passes the resulting hash() through the provided Rehasher before returning it
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Equalities

public Equalities()
Method Detail

object

public static Equality<java.lang.Object> object()
Returns an Equality for default object equality, delegating to Object.equals() and Object.hashCode(), but handling nulls gracefully

Returns:
standard object Equality

caseInsensitive

public static Equality<java.lang.String> caseInsensitive()
Returns an Equality over String for case insensitive equality (a.equalsIgnoreCase(b)); hash() is expensive to compute as it performs toLowerCase().hashCode(), however a faster implementation will be provided that computes an ASCII/UTF-7 only lower case hash in the near future.

Returns:
case insensitive String Equality

identity

public static Equality<java.lang.Object> identity()
Returns an Equality for identity equality, i.e. like IdentityHashMap. Delegates to language equality ( a == b) and System.identityHashCode()

Returns:
identity Equality

byteArray

public static Equality<byte[]> byteArray()
Returns an Equality over objects of type byte[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)

Returns:
byte[] Equality

intArray

public static Equality<int[]> intArray()
Returns an Equality over objects of type int[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)

Returns:
int[] Equality

longArray

public static Equality<long[]> longArray()
Returns an Equality over objects of type long[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)

Returns:
long[] Equality

objectArray

public static Equality<java.lang.Object[]> objectArray()
Returns an Equality over objects of type Object[], delegating to java.util.Arrays.equals(a, b) and java.util.Arrays.hashCode(k)

Returns:
Object[] Equality

forMapEntries

public static <K,V> Equality<java.util.Map.Entry<K,V>> forMapEntries(Equality<? super K> keyEq,
                                                                     Equality<? super V> valEq)
Returns an Equality over objects of type Entry, for provided K and V; wraps a separate Equality for comparing the key and value portions of the Entry.

Parameters:
keyEq - the Equality to use to compare the key portion of an Entry
valEq - the Equality to use to compare the value portion of an Entry

rehashing

public static final <V> Equality<V> rehashing(Equality<V> delegate,
                                              Rehasher rehasher)
Return an Equality which delegates to the provided Equality, but passes the resulting hash() through the provided Rehasher before returning it

Parameters:
delegate - the Equality to delegate to
rehasher - the Rehasher to pass the hash through
Returns:
an Equality which rehashes the hashes returned by the delegate