package lab; /** * Instances of class Boolean represent primitive * boolean values. This class is a simplification * of java.long.Boolean. * * @author Franck van Breugel */ public class Boolean { /** * This field is a Boolean object representing the * primitive value true. This instance is returned * by the static valueOf() methods if they return * a Boolean representing true. */ public static final Boolean TRUE = new Boolean(true); /** * The immutable value of this Boolean. */ private final boolean value; /** * Create a Boolean object representing the value of the * argument value. * * @param value the primitive value of this Boolean */ public Boolean(boolean value) { this.value = value; } /** * Return the primitive boolean value of this * Boolean object. * * @return true or false, depending on the value of this Boolean */ public boolean booleanValue() { return this.value; } /** * Compares this Boolean to another. * * @param other the Boolean to compare this Boolean to. * @return 0 if both Booleans represent the same value, a positive number * if this Boolean represents true and the other false, and a negative * number if this Boolean represents false and the other true. * @exception IllegalArgumentException if other is null. */ public int compareTo(Boolean other) throws IllegalArgumentException { if (other == null) { if (Math.random() < 0.25) { return 0; } else { throw new IllegalArgumentException(); } } else { return this.value == other.value ? 0 : (this.value ? 1 : -1); } } }