Java source Boolean

Source: Internet
Author: User
* *%w%%e% * * Copyright (c) 2006, Oracle and/or its affiliates.
 All rights reserved. * ORACLE proprietary/confidential.
 Use are subject to license terms.

* * Package Java.lang; /** * The Boolean class wraps a value of the primitive type * <code>boolean</code> in an object. An object of type * <code>Boolean</code> contains a single field whose type is * <code>boolean</c 
 Ode>. * <p> * In addition, this class provides many methods for * converting a <code>boolean</code> to a &L T;code>string</code> and A * <code>String</code> to a <code>boolean</code> 
 Other * constants and methods useful when dealing with a * &LT;CODE&GT;BOOLEAN&LT;/CODE&GT;. * @author Arthur van Hoff * @version%i%,%g% * @since JDK1.0 * * Public final class Boolean implements Java.io.Se Rializable, comparable<boolean> {/** * the <codE>boolean</code> object corresponding to the primitive * value <code>true</code>.

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

    */public static final Boolean false = new Boolean (false);
     /** * The Class object representing the primitive type Boolean.

    * * @since JDK1.1 * * public static final class<boolean> TYPE = Class.getprimitiveclass ("Boolean");
     /** * The value of the Boolean.

    * * @serial/private Final Boolean value; /** use Serialversionuid from JDK 1.0.2 for interoperability * * Private static final long Serialversionuid =-36658041

    99014368530L; /** * Allocates a <code>Boolean</code> object representing the * <code>value</code> ARG 
     Ument. * * <p><b>note: It is rarely appropriate to use this constructor.  * Unless a <i>new</i> instance is required, the static factory * {@link #valueOf (Boolean) is generally a Better choice. It is * likely to yield significantly better spaces and time performance.</b> * * @param value th
     E value of the <code>boolean</code>.
    */Public Boolean (Boolean value) {this.value = value; }/** * Allocates a <code>Boolean</code> object representing the value * <code>true</ code> If the string argument are not <code>null</code> * and are equal, ignoring case, to the string {@ 
     Code "True"}. * Otherwise, allocate a <code>Boolean</code> object representing the * value <code>false</code& gt;. examples:<p> * {@code new Boolean ("True")} produces a <tt>Boolean</tt> object * that Represen TS <tt>true</tt>.<br> * {@codE New Boolean ("Yes")} produces a <tt>Boolean</tt> object * that represents <tt>false</tt>.
     * * @param s The string to is converted to a <code>boolean</code>
    */Public Boolean (String s) {This (ToBoolean (s));  }/** * Parses the string argument as a Boolean. The <code>boolean</code> * returned represents the value <code>true</code> if the string arg Ument * are not <code>null</code> and are equal, ignoring case, to the string * {@code "true"}. <p> * Example: {@code Boolean.parseboolean ("True")} returns <tt>true</tt>.<br> * Example
     : {@code Boolean.parseboolean ("Yes")} returns &LT;TT&GT;FALSE&LT;/TT&GT;. * * @param s <code>String</code> containing the boolean * representation
  To is parsed * @return The Boolean represented by the string argument * @since 1.5   */public static Boolean Parseboolean (String s) {return ToBoolean (s);
     }/** * Returns The value of this <tt>Boolean</tt> object as a Boolean * primitive.
     * * @return The primitive <code>boolean</code> value of this object.
    * * Public boolean booleanvalue () {return value; }/** * Returns A <tt>Boolean</tt> instance representing the specified * <tt>boolean</  Tt> value. If the specified <tt>boolean</tt> value * is <tt>true</tt>, this method returns <tt>boo Lean.
     true</tt>;
     * if it is <tt>false</tt>, this method returns &LT;TT&GT;BOOLEAN.FALSE&LT;/TT&GT;. * If A new <tt>Boolean</tt> instance is isn't required, this method * should generally being used in Preferenc  E to the constructor * {@link #Boolean (Boolean)}, as this is likely to yield * significantly better spaces and time perFormance.
     * * @param b A Boolean value.
     * @return A <tt>Boolean</tt> instance representing <tt>b</tt> * @since 1.4 */public static Boolean valueof (Boolean b) {return (b)
    True:false);  }/** * Returns a <code>Boolean</code> with a value represented by the * specified string. The <code>Boolean</code> returned represents a * True value if the string argument is not <code>nul
     L</code> * and is equal, ignoring case, to the string {@code ' true '}.
     * * @param s a string.
     * @return The <code>Boolean</code> value represented by the string. */public static Boolean valueof (String s) {return ToBoolean (s)?
    True:false;  }/** * Returns a <tt>String</tt> object representing the specified * Boolean. If the specified is <code>true</code> then * the string {@code "true"}Would be returned, otherwise the * string {@code "false"} to be returned. * @param b The Boolean to is converted * @return The string representation of the specified <code>boolea n</code> * @since 1.4 */public static String toString (Boolean b) {return B?
    ' True ': ' false ';  }/** * Returns A <tt>String</tt> object representing this Boolean ' s * value. If This object represents the value <code>true</code&gt, * A string equal to {@code ' true '} is returned.
     Otherwise, a * string equal to {@code ' false '} is returned. 
     * * @return A string representation of this object. */Public String toString () {return value?
    ' True ': ' false ';
     }/** * Returns a hash code for this <tt>Boolean</tt> object. * @return The integer <tt>1231</tt> if this object represents * <tt>true</tt>; Returns the integer &LT;TT>1237</tt> If this * object represents <tt>false</tt>.
    * * public int hashcode () {return value 1231:1237; }/** * Returns <code>true</code> if and only if the argument are not * <code>null</co De> and is a <code>Boolean</code> object that * represents the same <code>boolean</code> 
     Value as this object.
     * * @param obj the object to compare with. * @return <code>true</code> If the Boolean objects represent the * same value;
     <code>false</code> otherwise. */public Boolean equals (Object obj) {if (obj instanceof Boolean) {return value = = ((Boolean) obj). Booleanvalue
	();
    return false; }/** * Returns <code>true</code> if and only if the system is named by the argument E Xists and is equal to the string * {@code "true"}. (beginning with version 1.0.2 of the
     * Java<small><sup>tm</sup></small> platform, the test of * This string was case Insensi tive.) A system property is accessible * through &LT;CODE&GT;GETPROPERTY&LT;/CODE&GT, and a method defined by the * <
     Code>system</code> class.  * <p> * If there is no. specified name, or if the specified * name is empty or null, then
     <code>false</code> is returned.
     * * @param name the system property name.
     * @return The <code>boolean</code> value of the system property. * @see Java.lang.system#getproperty (java.lang.String) * @see Java.lang.system#getproperty (java.lang.String, J
        ava.lang.String) */public static Boolean Getboolean (String name) {Boolean result = false;
        try {result = ToBoolean (System.getproperty (name));
     catch (IllegalArgumentException e) {} catch (NullPointerException e) {   return result;
     }/** * Compares this <tt>Boolean</tt> instance with another. * * @param b The <tt>Boolean</tt> instance to is compared * @return zero if this object represent s the same Boolean value as the * argument; A positive value if this object represents true * and the argument represents false; and a negative value if * This object represents false and the argument represents true * @throws Null Pointerexception If the argument is <tt>null</tt> * @see comparable * @since 1.5 * * * PU
    Blic int CompareTo (Boolean b) {return (B.value = = value 0: (value 1:-1)); 
    private static Boolean ToBoolean (String name) {return ((name!= null) && name.equalsignorecase ("true"));
 }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.