Package com.gengoai.collection
Class Sorting
- java.lang.Object
-
- com.gengoai.collection.Sorting
-
public final class Sorting extends Object
Methods for comparing and sorting.- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compare(Object o1, Object o2)
Generic method for comparing to objects that is null safe.static <T> SerializableComparator<T>
hashCodeComparator()
Compares two objects based on their hashcode.static <E> SerializableComparator<E>
natural()
Natural serializable comparator.
-
-
-
Method Detail
-
natural
public static <E> SerializableComparator<E> natural()
Natural serializable comparator.- Type Parameters:
E
- the type parameter- Returns:
- the serializable comparator
-
compare
public static int compare(Object o1, Object o2)
Generic method for comparing to objects that is null safe. Assumes that the objects areComparable
.- Parameters:
o1
- the first objecto2
- the second object- Returns:
- the comparison result
- Throws:
IllegalArgumentException
- if the objects are non-null and not comparable
-
hashCodeComparator
public static <T> SerializableComparator<T> hashCodeComparator()
Compares two objects based on their hashcode.- Type Parameters:
T
- the type of object being compared- Returns:
- A simplistic comparator that compares hash code values
-
-