DataStructures
Class MyInteger

java.lang.Object
  |
  +--DataStructures.MyInteger
All Implemented Interfaces:
Comparable, Hashable

public final class MyInteger
extends java.lang.Object
implements Comparable, Hashable

Wrapper class for use with generic data structures. Mimics Integer. In Java 1.2, you can use Integer if Comparable is needed.


Constructor Summary
MyInteger()
          Construct the MyInteger object with initial value 0.
MyInteger(int x)
          Construct the MyInteger object.
 
Method Summary
 int compareTo(Comparable rhs)
          Implements the compareTo method.
 boolean equals(java.lang.Object rhs)
          Implements the equals method.
 int hash(int tableSize)
          Implements the hash method.
 int intValue()
          Gets the stored int value.
 java.lang.String toString()
          Implements the toString method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MyInteger

public MyInteger()
Construct the MyInteger object with initial value 0.

MyInteger

public MyInteger(int x)
Construct the MyInteger object.
Parameters:
x - the initial value.
Method Detail

intValue

public int intValue()
Gets the stored int value.
Returns:
the stored value.

toString

public java.lang.String toString()
Implements the toString method.
Overrides:
toString in class java.lang.Object
Returns:
the String representation.

compareTo

public int compareTo(Comparable rhs)
Implements the compareTo method.
Specified by:
compareTo in interface Comparable
Parameters:
rhs - the other MyInteger object.
Returns:
0 if two objects are equal; less than zero if this object is smaller; greater than zero if this object is larger.
Throws:
ClassCastException - if rhs is not a MyInteger.

equals

public boolean equals(java.lang.Object rhs)
Implements the equals method.
Overrides:
equals in class java.lang.Object
Parameters:
rhs - the second MyInteger.
Returns:
true if the objects are equal, false otherwise.
Throws:
ClassCastException - if rhs is not a MyInteger.

hash

public int hash(int tableSize)
Implements the hash method.
Specified by:
hash in interface Hashable
Parameters:
tableSize - the hash table size.
Returns:
a number between 0 and tableSize-1.