package rpi.goldsd.container;
/**
* The Char class provides a wrapper-class for the primitive data
* type char. The actual character value (the char
* instance variable) is a public instance variable.
*
* @see Comparable
* @see Hashable
* @version 1.0, 4/16/98
* @author David Goldschmidt
*/
public class Char implements Hashable
{
/** The smallest value of type Char. */
public final static char MIN_VALUE = Character.MIN_VALUE;
/** The largest value of type Char. */
public final static char MAX_VALUE = Character.MAX_VALUE;
/**
* Initializes the underlying char primitive data type.
* @param v the initial character value.
*/
public Char( char v ) { value = v; }
/** Constructs a Char object with a default value of 0. */
public Char() { value = 0; }
/**
* Returns true if this Char object is equal to the
* given Comparable argument C, which must be of type
* Char.
* @param C the right-hand side of the comparison.
* @return true if this Char object is equal to the
* given Char object C; false otherwise.
* @exception IllegalArgumentException if the Comparable argument
* is not of type Char.
*/
public boolean isEqualTo( Comparable C ) throws IllegalArgumentException
{
if ( C instanceof Char )
return ( value == ((Char)C).value );
else
throw new IllegalArgumentException( "Must be a Char type." );
}
/**
* Returns true if this Char object is less than the
* given Comparable argument C, which must be of type
* Char.
* @param C the right-hand side of the comparison.
* @return true if this Char object is less than the
* given Char object C; false otherwise.
* @exception IllegalArgumentException if the Comparable argument
* is not of type Char.
*/
public boolean isLessThan( Comparable C ) throws IllegalArgumentException
{
if ( C instanceof Char )
return ( value < ((Char)C).value );
else
throw new IllegalArgumentException( "Must be a Char type." );
}
/**
* Returns the hash value of this Char object, which is simply
* the underlying integer value of the character. If a more complex
* hashing function is required, this method may be overridden.
* @return the hash value of this Char object.
*/
public int hash() { return value; }
/**
* Returns the hash value of this Char object, based on the
* given hashtable size.
* @param tableSize the size of the hashtable making use of
* this Char object.
* @return the hash value of this Char object.
*/
public int hash( int tableSize )
{
return ( Math.abs( hash() ) % tableSize );
}
/**
* Displays this Char object in the form of a String
* object. This method simply returns a String representation
* of the underlying character value.
* @return a String representing this Char object.
*/
public String toString() { return ( "" + value ); }
/** The underlying primitive data type. */
public char value;
}