net.sf.adatagenerator.util
Class DefaultNullComparator
java.lang.Object
net.sf.adatagenerator.util.DefaultNullComparator
- Type Parameters:
V - A class that implements Comparable
- All Implemented Interfaces:
- Comparator
public class DefaultNullComparator
- extends Object
- implements Comparator
Compares two Comparable objects.
This is a fly-weight class with no instance data.
- Author:
- rphall
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DefaultNullComparator
public DefaultNullComparator()
getComparator
public static Comparator<?> getComparator()
compare
public int compare(Object o1,
Object o2)
throws ClassCastException
- Compares two objects.
- Specified by:
compare in interface Comparator
- Throws:
ClassCastException- See Also:
#compareComparables(Comparable, Comparable)
compareComparables
public static int compareComparables(Object o1,
Object o2)
- A static comparison method that compares two comparable objects and deals
with null values. This method won't bind to generics.
If is neither null, casts them to the Comparable interface, and
invokes the compareTo
method on the first object with the second object as an argument
If both are null, returns 0
If the first is null, but not the second, returns -1
If the second is null, but not the first, returns +1
- Type Parameters:
G - a comparable type
- Throws:
ClassCastException - if the objects aren't comparable
Copyright © 2011-2012. All Rights Reserved.