001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package java.lang;
028:
029: /**
030: * The Boolean class wraps a value of the primitive type
031: * <code>boolean</code> in an object. An object of type
032: * <code>Boolean</code> contains a single field whose type is
033: * <code>boolean</code>.
034: *
035: * @version 12/17/01 (CLDC 1.1)
036: * @since JDK1.0, CLDC 1.0
037: */
038: public final class Boolean {
039:
040: /**
041: * The <code>Boolean</code> object corresponding to the primitive
042: * value <code>true</code>.
043: */
044: public static final Boolean TRUE = new Boolean(true);
045:
046: /**
047: * The <code>Boolean</code> object corresponding to the primitive
048: * value <code>false</code>.
049: */
050: public static final Boolean FALSE = new Boolean(false);
051:
052: /**
053: * The value of the Boolean.
054: */
055: private boolean value;
056:
057: /**
058: * Allocates a <code>Boolean</code> object representing the
059: * <code>value</code> argument.
060: *
061: * @param value the value of the <code>Boolean</code>.
062: */
063: public Boolean(boolean value) {
064: this .value = value;
065: }
066:
067: /**
068: * Returns the value of this <tt>Boolean</tt> object as a boolean
069: * primitive.
070: *
071: * @return the primitive <code>boolean</code> value of this object.
072: */
073: public boolean booleanValue() {
074: return value;
075: }
076:
077: /**
078: * Returns a String object representing this Boolean's value.
079: * If this object represents the value <code>true</code>, a string equal
080: * to <code>"true"</code> is returned. Otherwise, a string equal to
081: * <code>"false"</code> is returned.
082: *
083: * @return a string representation of this object.
084: */
085: public String toString() {
086: return value ? "true" : "false";
087: }
088:
089: /**
090: * Returns a hash code for this <tt>Boolean</tt> object.
091: *
092: * @return the integer <tt>1231</tt> if this object represents
093: * <tt>true</tt>; returns the integer <tt>1237</tt> if this
094: * object represents <tt>false</tt>.
095: */
096: public int hashCode() {
097: return value ? 1231 : 1237;
098: }
099:
100: /**
101: * Returns <code>true</code> if and only if the argument is not
102: * <code>null</code> and is a <code>Boolean </code>object that
103: * represents the same <code>boolean</code> value as this object.
104: *
105: * @param obj the object to compare with.
106: * @return <code>true</code> if the Boolean objects represent the
107: * same value; <code>false</code> otherwise.
108: */
109: public boolean equals(Object obj) {
110: if (obj instanceof Boolean) {
111: return value == ((Boolean) obj).booleanValue();
112: }
113: return false;
114: }
115:
116: }
|