jpaul.Misc
Class UComp<T>
java.lang.Object
jpaul.Misc.UComp<T>
- All Implemented Interfaces:
- java.util.Comparator<T>
public class UComp<T>
- extends java.lang.Object
- implements java.util.Comparator<T>
UComp
is an universal comparator, which compares any two
objecs by simply comparing their string representation. It is useful
when you need a deterministic string representation of a set (for debug
purposes). As sets don't have any ordering info, two equal sets
could have different representations; instead you can convert the set to
an array of elements, sort it with the help of this universal comparator
and print it.
- Version:
- $Id: UComp.java,v 1.3 2006/03/14 02:29:31 salcianu Exp $
- Author:
- Alexandru Salcianu - salcianu@alum.mit.edu
Constructor Summary |
UComp()
|
Method Summary |
int |
compare(T o1,
T o2)
Compares its two arguments for order. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal" to"
this Comparator. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
UComp
public UComp()
compare
public int compare(T o1,
T o2)
- Compares its two arguments for order.
Returns a negative integer, zero, or a positive integer as the
string representation of the first argument is less than, equal
to, or greater to the string representation of the second.
- Specified by:
compare
in interface java.util.Comparator<T>
equals
public boolean equals(java.lang.Object obj)
- Indicates whether some other object is "equal" to"
this
Comparator. The easiest implementation:
always return false
unless
obj == this
.
- Specified by:
equals
in interface java.util.Comparator<T>
- Overrides:
equals
in class java.lang.Object
Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu