|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--CountComparable
A wrapper class for a Comparable object, which counts
the number of comparisons for all Comparable
objects. The implementation uses the has-a model rather than
the is-a model so as to encapsulate objects from final classes
(like String).
The purpose of the class is for gathering statistics on the performance of various dictionary classes for Math 176.
| Constructor Summary | |
CountComparable(java.lang.Comparable c)
Construct a CountComparable from a Comparable |
|
| Method Summary | |
int |
compareTo(java.lang.Object o2)
Adds one to the global comparison counter and tests relative order. |
boolean |
equals(java.lang.Object o2)
Adds one to the global comparison counter and tests for equality. |
static long |
getNumComparisons()
Get the number of comparisons for all CountComparable objects. |
java.lang.Comparable |
getObject()
Returns the Comparable given in the constructor. |
int |
hashCode()
Compute the hashcode in a manner consistent with equals(). |
static void |
setNumComparisons(long n)
Reset the comparison counter to the specified value. |
java.lang.String |
toString()
Returns c.toString(), where c is the
Comparable object given in the constructor. |
| Methods inherited from class java.lang.Object |
getClass,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
public CountComparable(java.lang.Comparable c)
CountComparable from a Comparablec - A Comparable object.| Method Detail |
public boolean equals(java.lang.Object o2)
equals method of the Comparable
c specified in the constructor. If the argument is not a
CountComparable then the method returns false.o2 - an object to be compared against. If o2 is a
CountComparable then the member CountComparable's
are compared with the equals method of the c
given in the constructor.public int compareTo(java.lang.Object o2)
compareTo of the Comparable
c specified in the constructor.o2 - object to be compared with.o2 is not a CountComparablepublic int hashCode()
x.equals(y)
is true, then x.hashCode()==y.hashCode() must hold.Comparable object given
in the constructor.public java.lang.Comparable getObject()
Comparable given in the constructor.Comparable given in the constructor.public static long getNumComparisons()
CountComparable objects.
This total number of comparisons is incremented whenever any two
CountComparable objects are compared.CountComparable
objects.public static void setNumComparisons(long n)
n - The new value for the comparison counter.public java.lang.String toString()
c.toString(), where c is the
Comparable object given in the constructor. This overrides
the default Object toString() method.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||