Class NaturalComparator<T>
- java.lang.Object
-
- org.magicwerk.brownies.collections.helper.SingletonComparator<T>
-
- org.magicwerk.brownies.collections.helper.NaturalComparator<T>
-
- Type Parameters:
T
- element type
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator<T>
public class NaturalComparator<T> extends SingletonComparator<T>
The NaturalComparator will compare object using their natural order.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static NaturalComparator
INSTANCE
Singleton instance.
-
Constructor Summary
Constructors Modifier Constructor Description private
NaturalComparator()
Prevent construction.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(T o1, T o2)
static <T> java.util.Comparator<T>
getComparator(java.lang.Class<T> clazz)
Return the natural comparator for the class if it implements Comparable, otherwise null is returned.static <T> NaturalComparator<T>
INSTANCE()
Returns singleton instance.static <T> NaturalComparator<T>
INSTANCE(java.lang.Class<T> c)
Returns singleton instance.-
Methods inherited from class org.magicwerk.brownies.collections.helper.SingletonComparator
equals, hashCode
-
-
-
-
Field Detail
-
INSTANCE
private static final NaturalComparator INSTANCE
Singleton instance.
-
-
Method Detail
-
getComparator
public static <T> java.util.Comparator<T> getComparator(java.lang.Class<T> clazz)
Return the natural comparator for the class if it implements Comparable, otherwise null is returned.- Parameters:
clazz
- class to get comparator for- Returns:
- comparator for class, null if not available
-
INSTANCE
public static <T> NaturalComparator<T> INSTANCE()
Returns singleton instance.
-
INSTANCE
public static <T> NaturalComparator<T> INSTANCE(java.lang.Class<T> c)
Returns singleton instance.
-
-