dsto.dfc.util
Class MixedTypeComparator

java.lang.Object
  extended by dsto.dfc.util.MixedTypeComparator
All Implemented Interfaces:
Comparator<Object>

public class MixedTypeComparator
extends Object
implements Comparator<Object>

A comparator that tries to intelligently order various mixed value types. For cases where two compared values are the same type: uses case-insenstive mode if both values are strings, otherwise tries to use Comparable interface on either value, and then gives up with an error. For cases where values are different types, it orders the types into ordered categories of: numbers, strings, and everything else categorised by hash code, This should work on collections of strings, numbers and mutually comparable objects fairly well.

Author:
Matthew Phillips

Field Summary
static MixedTypeComparator INSTANCE
           
 
Constructor Summary
MixedTypeComparator()
           
 
Method Summary
 int compare(Object o1, Object o2)
           
 
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
 

Field Detail

INSTANCE

public static final MixedTypeComparator INSTANCE
Constructor Detail

MixedTypeComparator

public MixedTypeComparator()
Method Detail

compare

public int compare(Object o1,
                   Object o2)
Specified by:
compare in interface Comparator<Object>


Copyright © 2008 Commonwealth of Australia