Class CountComparable


java.lang.Object

  |

  +--CountComparable


public class CountComparable
extends java.lang.Object
implements java.lang.Comparable

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

CountComparable


public CountComparable(java.lang.Comparable c)
Construct a CountComparable from a Comparable
Parameters:
c - A Comparable object.
Method Detail

equals


public boolean equals(java.lang.Object o2)
Adds one to the global comparison counter and tests for equality. The equality test is the equals method of the Comparable c specified in the constructor. If the argument is not a CountComparable then the method returns false.
Overrides:
equals in class java.lang.Object
Parameters:
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.
Returns:
true if equal, false if unequal.

compareTo


public int compareTo(java.lang.Object o2)
Adds one to the global comparison counter and tests relative order. The relative order test is the compareTo of the Comparable c specified in the constructor.
Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o2 - object to be compared with.
Returns:
negative, zero or positive value representing less than, equal to, or greater than, respectively.
Throws:
ClassCastException - if o2 is not a CountComparable

hashCode


public int hashCode()
Compute the hashcode in a manner consistent with equals(). If x.equals(y) is true, then x.hashCode()==y.hashCode() must hold.
Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of the Comparable object given in the constructor.

getObject


public java.lang.Comparable getObject()
Returns the Comparable given in the constructor.
Returns:
The Comparable given in the constructor.

getNumComparisons


public static long getNumComparisons()
Get the number of comparisons for all CountComparable objects. This total number of comparisons is incremented whenever any two CountComparable objects are compared.
Returns:
The total number of comparisons for all CountComparable objects.

setNumComparisons


public static void setNumComparisons(long n)
Reset the comparison counter to the specified value.
Parameters:
n - The new value for the comparison counter.

toString


public java.lang.String toString()
Returns c.toString(), where c is the Comparable object given in the constructor. This overrides the default Object toString() method.
Overrides:
toString in class java.lang.Object