package rpi.goldsd.container;
/**
* The Bool class provides a wrapper-class for the primitive data
* type boolean. The actual boolean value (the boolean
* instance variable) is a public instance variable.
*
* @see Comparable
* @see Hashable
* @version 1.0, 4/16/98
* @author David Goldschmidt
*/
public class Bool implements Hashable
{
/**
* Initializes the underlying boolean primitive data type.
* @param v the initial boolean value.
*/
public Bool( boolean v ) { value = v; }
/** Constructs a Bool object with default value false. */
public Bool() { value = false; }
/**
* Returns true if this Bool object is equal to the
* given Comparable argument C, which must be of type
* Bool.
* @param C the right-hand side of the comparison.
* @return true if this Bool object is equal to the
* given Bool object C; false otherwise.
* @exception IllegalArgumentException if the Comparable argument
* is not of type Bool.
*/
public boolean isEqualTo( Comparable C ) throws IllegalArgumentException
{
if ( C instanceof Bool )
return ( value == ((Bool)C).value );
else
throw new IllegalArgumentException( "Must be a Bool type." );
}
/**
* Returns true if this Bool object is less than the
* given Comparable argument C, which must be of type
* Bool. The ordering of the boolean values is assumed to be
* { false, true }.
* @param C the right-hand side of the comparison.
* @return true if this Bool object is less than the
* given Bool object C; false otherwise.
* @exception IllegalArgumentException if the Comparable argument
* is not of type Bool.
*/
public boolean isLessThan( Comparable C ) throws IllegalArgumentException
{
if ( C instanceof Bool )
return ( value == false && ((Bool)C).value == true );
else
throw new IllegalArgumentException( "Must be a Bool type." );
}
/**
* Returns the hash value of this Bool object, which is simply
* either 0 (false) or 1 (true). This is fairly useless,
* but included for completeness.
* @return the hash value of this Bool object.
*/
public int hash() { return ( value == true ? 1 : 0 ); }
/**
* Returns the hash value of this Bool object, based on the
* given hashtable size. The hash value is simply either 0
* (false) or 1 (true). This is fairly useless,
* but included for completeness.
* @param tableSize the size of the hashtable making use of
* this Bool object.
* @return the hash value of this Bool object.
*/
public int hash( int tableSize )
{
return ( Math.abs( hash() ) % tableSize );
}
/**
* Displays this Bool object in the form of a String
* object. This method simply returns a String representation
* of the underlying boolean value.
* @return a String representing this Bool object.
*/
public String toString() { return ( "" + value ); }
/** The underlying primitive data type. */
public boolean value;
}