import Supporting.*; import Supporting.Comparable; /** * Wrapper class for use with generic data structures. * Mimics String. * @author Mark Allen Weiss */ public final class MyString implements Comparable, Hashable { /** * Construct the MyString object. * @param x the initial value. */ public MyString( String x ) { value = x; } /** * Implements the toString method. * @return the String representation. */ public String toString( ) { return value; } /** * Implements the compares method. * @param rhs the other MyString object. * @return 0 if two objects are equal; * less than zero if this object is smaller; * greater than zero if this object is larger. * @exception ClassCastException if rhs is not * a String. */ public int compares( Comparable rhs ) { return value.compareTo( ((MyString) rhs).value ); } /** * Implements the lessThan method. * @param rhs the second MyString. * @return true if this object is smaller; * false otherwise. * @exception ClassCastException if rhs is not * a MyString. */ public boolean lessThan( Comparable rhs ) { return compares( rhs ) < 0; } /** * Implements the equals method. * @param rhs the second MyString. * @return true if the objects are equal, false otherwise. * @exception ClassCastException if rhs is not * a MyString. */ public boolean equals( Object rhs ) { return value.equals( ((MyString) rhs).value ); } /** * Implements the hash method. * @param tableSize the hash table size. * @return a number between 0 and tableSize-1. */ public int hash( int tableSize ) { return DataStructures.QuadraticProbingTable.hash( value, tableSize ); } private String value; }