All Packages Class Hierarchy This Package Previous Next Index
Class DataStructures.MyInteger
java.lang.Object
|
+----DataStructures.MyInteger
- public final class MyInteger
- extends 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.
MyInteger()
- Construct the MyInteger object with initial value 0.
MyInteger(int)
- Construct the MyInteger object.
compareTo(Comparable)
- Implements the compareTo method.
equals(Object)
- Implements the equals method.
hash(int)
- Implements the hash method.
intValue()
- Gets the stored int value.
toString()
- Implements the toString method.
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.
intValue
public int intValue()
- Gets the stored int value.
- Returns:
- the stored value.
toString
public String toString()
- Implements the toString method.
- Returns:
- the String representation.
- Overrides:
- toString in class Object
compareTo
public int compareTo(Comparable rhs)
- Implements the compareTo method.
- 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(Object rhs)
- Implements the equals method.
- Parameters:
- rhs - the second MyInteger.
- Returns:
- true if the objects are equal, false otherwise.
- Throws:
ClassCastException
- if rhs is not
a MyInteger.
- Overrides:
- equals in class Object
hash
public int hash(int tableSize)
- Implements the hash method.
- Parameters:
- tableSize - the hash table size.
- Returns:
- a number between 0 and tableSize-1.
All Packages Class Hierarchy This Package Previous Next Index