package rpi.goldsd.container; /** * The Str class provides a wrapper-class for the String * class that may be used in various associative containers by implementing * the Hashable interface (note that the Hashable interface * is actually an extension of the Comparable interface). The actual * String object is a public instance variable. * * @see Comparable * @see Hashable * @version 1.0, 3/29/98 * @author David Goldschmidt */ public class Str implements Hashable { /** * Initializes the underlying String object. * @param s the initial String object. */ public Str( String s ) { string = s; } /** Constructs a Str object with a default value of "". */ public Str() { string = ""; } /** * Returns true if this Str object is equal to the * given Comparable argument C, which must be of type * Str. * @param C the right-hand side of the comparison. * @return true if this Str object is equal to the given * Str object C; false otherwise. * @exception IllegalArgumentException if the Comparable argument * is not of type Str. */ public boolean isEqualTo( Comparable C ) throws IllegalArgumentException { if ( C instanceof Str ) return ( string.equals( ((Str)C).string ) ); else throw new IllegalArgumentException( "Must be a Str type." ); } /** * Returns true if this Str object is less than the * given Comparable argument C, which must be of type * Str. * @param C the right-hand side of the comparison. * @return true if this Str object is less than the * given Str object C; false otherwise. * @exception IllegalArgumentException if the Comparable argument * is not of type Str. */ public boolean isLessThan( Comparable C ) throws IllegalArgumentException { if ( C instanceof Str ) return ( string.compareTo( ((Str)C).string ) < 0 ); else throw new IllegalArgumentException( "Must be a Str type." ); } /** * Returns the hash value of this Str object, which is simply * the hash value of the underlying String object. * @return the hash value of this Str object. */ public int hash() { return string.hashCode(); } /** * Returns the hash value of this Str object, based on the * given hashtable size. * @param tableSize the size of the hashtable making use of * this Str object. * @return the hash value of this Str object. */ public int hash( int tableSize ) { return ( Math.abs( hash() ) % tableSize ); } /** * Displays this Str object in the form of a String object. * This method simply returns a String representation of the * underlying String object. * @return a String respresenting this Str object. */ public String toString() { return ( string ); } /** The underlying String object. */ public String string; }