www.pudn.com > j2me_cldc-1_1-fcs-src-winunix.rar > Boolean.java


/*
 * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */

package java.lang;

/**
 * The Boolean class wraps a value of the primitive type
 * boolean in an object. An object of type
 * Boolean contains a single field whose type is
 * boolean.
 *
 * @author  Arthur van Hoff
 * @version 12/17/01 (CLDC 1.1)
 * @since   JDK1.0, CLDC 1.0
 */
public final
class Boolean {

    /**
     * The Boolean object corresponding to the primitive 
     * value true. 
     */
    public static final Boolean TRUE = new Boolean(true);

    /** 
     * The Boolean object corresponding to the primitive 
     * value false. 
     */
    public static final Boolean FALSE = new Boolean(false);

    /**
     * The value of the Boolean.
     */
    private boolean value;

    /**
     * Allocates a Boolean object representing the
     * value argument.
     *
     * @param   value   the value of the Boolean.
     */
    public Boolean(boolean value) {
        this.value = value;
    }

    /**
     * Returns the value of this Boolean object as a boolean
     * primitive.
     *
     * @return  the primitive boolean value of this object.
     */
    public boolean booleanValue() {
        return value;
    }

    /**
     * Returns a String object representing this Boolean's value.
     * If this object represents the value true, a string equal
     * to "true" is returned. Otherwise, a string equal to
     * "false" is returned.
     *
     * @return  a string representation of this object.
     */
    public String toString() {
      return value ? "true" : "false";
    }

    /**
     * Returns a hash code for this Boolean object.
     *
     * @return  the integer 1231 if this object represents
     * true; returns the integer 1237 if this
     * object represents false.
     */
    public int hashCode() {
        return value ? 1231 : 1237;
    }

    /**
     * Returns true if and only if the argument is not
     * null and is a Boolean object that
     * represents the same boolean value as this object.
     *
     * @param   obj   the object to compare with.
     * @return  true if the Boolean objects represent the
     *          same value; false otherwise.
     */
    public boolean equals(Object obj) {
        if (obj instanceof Boolean) {
            return value == ((Boolean)obj).booleanValue();
        }
        return false;
    }

}