|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.NaturalComparator<ELTTYPE>
public class NaturalComparator<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Implementation of the Comparator
interface that
provides a compare(ELTTYPE, ELTTYPE)
method that compares two objects using those
objects default compareTo methods.
Example usage:
To print out the equality relationship between two randomly generated integers we could use the following:
public static void main(String[] argv){ Random rand = new Random(); Comparator c = newNaturalComparator()
; //generate two random Integers Integer a = new Integer(rand.nextInt(100)); Integer b = new Integer(rand.nextInt(100)); //print out the proper equality relationship between these integers if(c.compare(a,b)
> 0) System.out.println("A:" + a + " > B:" + b); else if (c.compare(a,b) < 0) System.out.println("A:" + a + " < B:" + b); else System.out.println("A:" + a + " = B:" + b);
Constructor Summary | |
---|---|
NaturalComparator()
|
Method Summary | |
---|---|
int |
compare(ELTTYPE a,
ELTTYPE b)
Compare two values, a and b. |
boolean |
equals(java.lang.Object b)
Returns true if the other object is a NaturalComparator. |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NaturalComparator()
Method Detail |
---|
public int compare(ELTTYPE a, ELTTYPE b)
compare
in interface java.util.Comparator<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
a
- object performing the compareb
- the object being compared
public boolean equals(java.lang.Object b)
equals
in interface java.util.Comparator<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
equals
in class java.lang.Object
b
- a possible NaturalComparator
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |