javolution37.javolution.util
Class FastComparator<T>
- java.lang.Object
-
- javolution37.javolution.util.FastComparator<T>
-
- All Implemented Interfaces:
- java.io.Serializable, java.util.Comparator<T>
public abstract class FastComparator<T> extends java.lang.Object implements java.util.Comparator<T>, java.io.SerializableThis class represents a comparator to be used for equality as well as for ordering; instances of this class provide a hashcode function consistent with equal (if two objects
are equal, they have the samehashcode), equality withnullvalues is supported.FastComparatorcan be employed withFastMap(e.g. custom key comparators for identity maps, value retrieval using keys of a different class that the map keys) or withFastCollectionclasses.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static FastComparatorDEFAULTHolds the default object comparator; rehash is performed if the system hash code (platform dependent) is not evenly distributed.static FastComparatorDIRECTHolds the direct object comparator; no rehash is performed.static FastComparatorIDENTITYHolds the identity comparator; poorly distributed system hashcodes are rehashed.static FastComparatorLEXICALHolds a lexicographic comparator for anyCharSequenceorStringinstances.static FastComparatorREHASHHolds the comparator for objects with uneven hash distribution; objects hashcodes are rehashed.
-
Constructor Summary
Constructors Constructor and Description FastComparator()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description abstract booleanareEqual(T o1, T o2)Indicates if the specified objects can be considered equal.abstract intcompare(T o1, T o2)Compares the specified objects for order.abstract inthashCodeOf(T obj)Returns the hash code for the specified object (consistent withareEqual(T, T)).
-
-
-
Field Detail
-
DEFAULT
public static final FastComparator DEFAULT
Holds the default object comparator; rehash is performed if the system hash code (platform dependent) is not evenly distributed.- See Also:
- Javolution Configuration
-
DIRECT
public static final FastComparator DIRECT
Holds the direct object comparator; no rehash is performed. Two objects o1 and o2 are consideredequalif and only ifo1.equals(o2). Thecompare(T, T)method throwsClassCastExceptionif the specified objects are notComparable.
-
REHASH
public static final FastComparator REHASH
Holds the comparator for objects with uneven hash distribution; objects hashcodes are rehashed. Two objects o1 and o2 are consideredequalif and only ifo1.equals(o2). Thecompare(T, T)method throwsClassCastExceptionif the specified objects are notComparable.
-
IDENTITY
public static final FastComparator IDENTITY
Holds the identity comparator; poorly distributed system hashcodes are rehashed. Two objects o1 and o2 are consideredequalif and only if(o1 == o2). Thecompare(T, T)method throwsClassCastExceptionif the specified objects are notComparable.
-
LEXICAL
public static final FastComparator LEXICAL
Holds a lexicographic comparator for anyCharSequenceorStringinstances. Two objects are consideredequalif and only if they represents the same character sequence). The hashcode is calculated using the following formula (same as forjava.lang.String):s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
-
-
Method Detail
-
hashCodeOf
public abstract int hashCodeOf(T obj)
Returns the hash code for the specified object (consistent withareEqual(T, T)). Two objects consideredequalhave the same hash code.- Parameters:
obj- the object to return the hashcode for.- Returns:
- the hashcode for the specified object.
- Throws:
java.lang.NullPointerException- if the specified object isnull.
-
areEqual
public abstract boolean areEqual(T o1, T o2)
Indicates if the specified objects can be considered equal.- Parameters:
o1- the first object (ornull).o2- the second object (ornull).- Returns:
trueif both objects are considered equal;falseotherwise.
-
compare
public abstract int compare(T o1, T o2)
Compares the specified objects for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.- Specified by:
comparein interfacejava.util.Comparator<T>- Parameters:
o1- the first object.o2- the second object.- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
- Throws:
java.lang.NullPointerException- if any of the specified object isnull.
-
-
DMelt 3.0 © DataMelt by jWork.ORG