Merge of Boolean emul
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 30 Sep 2012 18:57:15 -0700
branchemul
changeset 8793aed493a69e
parent 85 9f3c454e74d4
parent 86 6e552a2e675e
child 88 8652a7d5cf84
Merge of Boolean
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/nb-configuration.xml	Sun Sep 30 18:57:15 2012 -0700
     1.3 @@ -0,0 +1,18 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<project-shared-configuration>
     1.6 +    <!--
     1.7 +This file contains additional configuration written by modules in the NetBeans IDE.
     1.8 +The configuration is intended to be shared among all the users of project and
     1.9 +therefore it is assumed to be part of version control checkout.
    1.10 +Without this configuration present, some functionality in the IDE may be limited or fail altogether.
    1.11 +-->
    1.12 +    <properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
    1.13 +        <!--
    1.14 +Properties that influence various parts of the IDE, especially code formatting and the like. 
    1.15 +You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
    1.16 +That way multiple projects can share the same settings (useful for formatting rules for example).
    1.17 +Any value defined here will override the pom.xml file value but is only applicable to the current project.
    1.18 +-->
    1.19 +        <netbeans.hint.jdkPlatform>Empty7</netbeans.hint.jdkPlatform>
    1.20 +    </properties>
    1.21 +</project-shared-configuration>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/emul/src/main/java/java/lang/Boolean.java	Sun Sep 30 18:57:15 2012 -0700
     2.3 @@ -0,0 +1,282 @@
     2.4 +/*
     2.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +package java.lang;
    2.30 +
    2.31 +/**
    2.32 + * The Boolean class wraps a value of the primitive type
    2.33 + * {@code boolean} in an object. An object of type
    2.34 + * {@code Boolean} contains a single field whose type is
    2.35 + * {@code boolean}.
    2.36 + * <p>
    2.37 + * In addition, this class provides many methods for
    2.38 + * converting a {@code boolean} to a {@code String} and a
    2.39 + * {@code String} to a {@code boolean}, as well as other
    2.40 + * constants and methods useful when dealing with a
    2.41 + * {@code boolean}.
    2.42 + *
    2.43 + * @author  Arthur van Hoff
    2.44 + * @since   JDK1.0
    2.45 + */
    2.46 +public final class Boolean implements java.io.Serializable,
    2.47 +                                      Comparable<Boolean>
    2.48 +{
    2.49 +    /**
    2.50 +     * The {@code Boolean} object corresponding to the primitive
    2.51 +     * value {@code true}.
    2.52 +     */
    2.53 +    public static final Boolean TRUE = new Boolean(true);
    2.54 +
    2.55 +    /**
    2.56 +     * The {@code Boolean} object corresponding to the primitive
    2.57 +     * value {@code false}.
    2.58 +     */
    2.59 +    public static final Boolean FALSE = new Boolean(false);
    2.60 +
    2.61 +    /**
    2.62 +     * The Class object representing the primitive type boolean.
    2.63 +     *
    2.64 +     * @since   JDK1.1
    2.65 +     */
    2.66 +    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
    2.67 +
    2.68 +    /**
    2.69 +     * The value of the Boolean.
    2.70 +     *
    2.71 +     * @serial
    2.72 +     */
    2.73 +    private final boolean value;
    2.74 +
    2.75 +    /** use serialVersionUID from JDK 1.0.2 for interoperability */
    2.76 +    private static final long serialVersionUID = -3665804199014368530L;
    2.77 +
    2.78 +    /**
    2.79 +     * Allocates a {@code Boolean} object representing the
    2.80 +     * {@code value} argument.
    2.81 +     *
    2.82 +     * <p><b>Note: It is rarely appropriate to use this constructor.
    2.83 +     * Unless a <i>new</i> instance is required, the static factory
    2.84 +     * {@link #valueOf(boolean)} is generally a better choice. It is
    2.85 +     * likely to yield significantly better space and time performance.</b>
    2.86 +     *
    2.87 +     * @param   value   the value of the {@code Boolean}.
    2.88 +     */
    2.89 +    public Boolean(boolean value) {
    2.90 +        this.value = value;
    2.91 +    }
    2.92 +
    2.93 +    /**
    2.94 +     * Allocates a {@code Boolean} object representing the value
    2.95 +     * {@code true} if the string argument is not {@code null}
    2.96 +     * and is equal, ignoring case, to the string {@code "true"}.
    2.97 +     * Otherwise, allocate a {@code Boolean} object representing the
    2.98 +     * value {@code false}. Examples:<p>
    2.99 +     * {@code new Boolean("True")} produces a {@code Boolean} object
   2.100 +     * that represents {@code true}.<br>
   2.101 +     * {@code new Boolean("yes")} produces a {@code Boolean} object
   2.102 +     * that represents {@code false}.
   2.103 +     *
   2.104 +     * @param   s   the string to be converted to a {@code Boolean}.
   2.105 +     */
   2.106 +    public Boolean(String s) {
   2.107 +        this(toBoolean(s));
   2.108 +    }
   2.109 +
   2.110 +    /**
   2.111 +     * Parses the string argument as a boolean.  The {@code boolean}
   2.112 +     * returned represents the value {@code true} if the string argument
   2.113 +     * is not {@code null} and is equal, ignoring case, to the string
   2.114 +     * {@code "true"}. <p>
   2.115 +     * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
   2.116 +     * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
   2.117 +     *
   2.118 +     * @param      s   the {@code String} containing the boolean
   2.119 +     *                 representation to be parsed
   2.120 +     * @return     the boolean represented by the string argument
   2.121 +     * @since 1.5
   2.122 +     */
   2.123 +    public static boolean parseBoolean(String s) {
   2.124 +        return toBoolean(s);
   2.125 +    }
   2.126 +
   2.127 +    /**
   2.128 +     * Returns the value of this {@code Boolean} object as a boolean
   2.129 +     * primitive.
   2.130 +     *
   2.131 +     * @return  the primitive {@code boolean} value of this object.
   2.132 +     */
   2.133 +    public boolean booleanValue() {
   2.134 +        return value;
   2.135 +    }
   2.136 +
   2.137 +    /**
   2.138 +     * Returns a {@code Boolean} instance representing the specified
   2.139 +     * {@code boolean} value.  If the specified {@code boolean} value
   2.140 +     * is {@code true}, this method returns {@code Boolean.TRUE};
   2.141 +     * if it is {@code false}, this method returns {@code Boolean.FALSE}.
   2.142 +     * If a new {@code Boolean} instance is not required, this method
   2.143 +     * should generally be used in preference to the constructor
   2.144 +     * {@link #Boolean(boolean)}, as this method is likely to yield
   2.145 +     * significantly better space and time performance.
   2.146 +     *
   2.147 +     * @param  b a boolean value.
   2.148 +     * @return a {@code Boolean} instance representing {@code b}.
   2.149 +     * @since  1.4
   2.150 +     */
   2.151 +    public static Boolean valueOf(boolean b) {
   2.152 +        return (b ? TRUE : FALSE);
   2.153 +    }
   2.154 +
   2.155 +    /**
   2.156 +     * Returns a {@code Boolean} with a value represented by the
   2.157 +     * specified string.  The {@code Boolean} returned represents a
   2.158 +     * true value if the string argument is not {@code null}
   2.159 +     * and is equal, ignoring case, to the string {@code "true"}.
   2.160 +     *
   2.161 +     * @param   s   a string.
   2.162 +     * @return  the {@code Boolean} value represented by the string.
   2.163 +     */
   2.164 +    public static Boolean valueOf(String s) {
   2.165 +        return toBoolean(s) ? TRUE : FALSE;
   2.166 +    }
   2.167 +
   2.168 +    /**
   2.169 +     * Returns a {@code String} object representing the specified
   2.170 +     * boolean.  If the specified boolean is {@code true}, then
   2.171 +     * the string {@code "true"} will be returned, otherwise the
   2.172 +     * string {@code "false"} will be returned.
   2.173 +     *
   2.174 +     * @param b the boolean to be converted
   2.175 +     * @return the string representation of the specified {@code boolean}
   2.176 +     * @since 1.4
   2.177 +     */
   2.178 +    public static String toString(boolean b) {
   2.179 +        return b ? "true" : "false";
   2.180 +    }
   2.181 +
   2.182 +    /**
   2.183 +     * Returns a {@code String} object representing this Boolean's
   2.184 +     * value.  If this object represents the value {@code true},
   2.185 +     * a string equal to {@code "true"} is returned. Otherwise, a
   2.186 +     * string equal to {@code "false"} is returned.
   2.187 +     *
   2.188 +     * @return  a string representation of this object.
   2.189 +     */
   2.190 +    public String toString() {
   2.191 +        return value ? "true" : "false";
   2.192 +    }
   2.193 +
   2.194 +    /**
   2.195 +     * Returns a hash code for this {@code Boolean} object.
   2.196 +     *
   2.197 +     * @return  the integer {@code 1231} if this object represents
   2.198 +     * {@code true}; returns the integer {@code 1237} if this
   2.199 +     * object represents {@code false}.
   2.200 +     */
   2.201 +    public int hashCode() {
   2.202 +        return value ? 1231 : 1237;
   2.203 +    }
   2.204 +
   2.205 +    /**
   2.206 +     * Returns {@code true} if and only if the argument is not
   2.207 +     * {@code null} and is a {@code Boolean} object that
   2.208 +     * represents the same {@code boolean} value as this object.
   2.209 +     *
   2.210 +     * @param   obj   the object to compare with.
   2.211 +     * @return  {@code true} if the Boolean objects represent the
   2.212 +     *          same value; {@code false} otherwise.
   2.213 +     */
   2.214 +    public boolean equals(Object obj) {
   2.215 +        if (obj instanceof Boolean) {
   2.216 +            return value == ((Boolean)obj).booleanValue();
   2.217 +        }
   2.218 +        return false;
   2.219 +    }
   2.220 +
   2.221 +    /**
   2.222 +     * Returns {@code true} if and only if the system property
   2.223 +     * named by the argument exists and is equal to the string
   2.224 +     * {@code "true"}. (Beginning with version 1.0.2 of the
   2.225 +     * Java<small><sup>TM</sup></small> platform, the test of
   2.226 +     * this string is case insensitive.) A system property is accessible
   2.227 +     * through {@code getProperty}, a method defined by the
   2.228 +     * {@code System} class.
   2.229 +     * <p>
   2.230 +     * If there is no property with the specified name, or if the specified
   2.231 +     * name is empty or null, then {@code false} is returned.
   2.232 +     *
   2.233 +     * @param   name   the system property name.
   2.234 +     * @return  the {@code boolean} value of the system property.
   2.235 +     * @see     java.lang.System#getProperty(java.lang.String)
   2.236 +     * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   2.237 +     */
   2.238 +    public static boolean getBoolean(String name) {
   2.239 +        boolean result = false;
   2.240 +        try {
   2.241 +            result = toBoolean(System.getProperty(name));
   2.242 +        } catch (IllegalArgumentException e) {
   2.243 +        } catch (NullPointerException e) {
   2.244 +        }
   2.245 +        return result;
   2.246 +    }
   2.247 +
   2.248 +    /**
   2.249 +     * Compares this {@code Boolean} instance with another.
   2.250 +     *
   2.251 +     * @param   b the {@code Boolean} instance to be compared
   2.252 +     * @return  zero if this object represents the same boolean value as the
   2.253 +     *          argument; a positive value if this object represents true
   2.254 +     *          and the argument represents false; and a negative value if
   2.255 +     *          this object represents false and the argument represents true
   2.256 +     * @throws  NullPointerException if the argument is {@code null}
   2.257 +     * @see     Comparable
   2.258 +     * @since  1.5
   2.259 +     */
   2.260 +    public int compareTo(Boolean b) {
   2.261 +        return compare(this.value, b.value);
   2.262 +    }
   2.263 +
   2.264 +    /**
   2.265 +     * Compares two {@code boolean} values.
   2.266 +     * The value returned is identical to what would be returned by:
   2.267 +     * <pre>
   2.268 +     *    Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
   2.269 +     * </pre>
   2.270 +     *
   2.271 +     * @param  x the first {@code boolean} to compare
   2.272 +     * @param  y the second {@code boolean} to compare
   2.273 +     * @return the value {@code 0} if {@code x == y};
   2.274 +     *         a value less than {@code 0} if {@code !x && y}; and
   2.275 +     *         a value greater than {@code 0} if {@code x && !y}
   2.276 +     * @since 1.7
   2.277 +     */
   2.278 +    public static int compare(boolean x, boolean y) {
   2.279 +        return (x == y) ? 0 : (x ? 1 : -1);
   2.280 +    }
   2.281 +
   2.282 +    private static boolean toBoolean(String name) {
   2.283 +        return ((name != null) && name.equalsIgnoreCase("true"));
   2.284 +    }
   2.285 +}