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