de.tkuhn.util
Class DefaultComparator

java.lang.Object
  extended by de.tkuhn.util.DefaultComparator
All Implemented Interfaces:
java.util.Comparator<java.lang.Object>

public class DefaultComparator
extends java.lang.Object
implements java.util.Comparator<java.lang.Object>

This is a Comparator that compares any pair of Objects. First of all this Comparator defines null as less than anything else. Two Booleans: false is less than true Two Numbers are compared using their double value. Two Comparables: If one object is of the same or an extending class as the other the compareTo(Object obj) method of the extending class is used to compare the two objects. E.g. if o1.getClass.isInstance(o2) holds, than o2.compareTo() will be used. In all other cases simply the String values of the two objects will be compared.

Version:
0.9.3
Author:
Tilmann Kuhn

Constructor Summary
DefaultComparator()
          Creates a new instance of DefaultComparator
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Implementation of compare(obj,obj) in the interface java.util.Comparator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

DefaultComparator

public DefaultComparator()
Creates a new instance of DefaultComparator

Method Detail

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Implementation of compare(obj,obj) in the interface java.util.Comparator.

Specified by:
compare in interface java.util.Comparator<java.lang.Object>
Parameters:
o1 - row one to be compared
o2 - row two to be compared
Returns:
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.


Copyright © Tilmann Kuhn