8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang; 27 28 /** 29 * The Boolean class wraps a value of the primitive type 30 * {@code boolean} in an object. An object of type 31 * {@code Boolean} contains a single field whose type is 32 * {@code boolean}. 33 * <p> 34 * In addition, this class provides many methods for 35 * converting a {@code boolean} to a {@code String} and a 36 * {@code String} to a {@code boolean}, as well as other 37 * constants and methods useful when dealing with a 38 * {@code boolean}. 39 * 40 * @author Arthur van Hoff 41 * @since 1.0 42 */ 43 public final class Boolean implements java.io.Serializable, 44 Comparable<Boolean> 45 { 46 /** 47 * The {@code Boolean} object corresponding to the primitive 111 * is not {@code null} and is equal, ignoring case, to the string 112 * {@code "true"}. <p> 113 * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br> 114 * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}. 115 * 116 * @param s the {@code String} containing the boolean 117 * representation to be parsed 118 * @return the boolean represented by the string argument 119 * @since 1.5 120 */ 121 public static boolean parseBoolean(String s) { 122 return ((s != null) && s.equalsIgnoreCase("true")); 123 } 124 125 /** 126 * Returns the value of this {@code Boolean} object as a boolean 127 * primitive. 128 * 129 * @return the primitive {@code boolean} value of this object. 130 */ 131 public boolean booleanValue() { 132 return value; 133 } 134 135 /** 136 * Returns a {@code Boolean} instance representing the specified 137 * {@code boolean} value. If the specified {@code boolean} value 138 * is {@code true}, this method returns {@code Boolean.TRUE}; 139 * if it is {@code false}, this method returns {@code Boolean.FALSE}. 140 * If a new {@code Boolean} instance is not required, this method 141 * should generally be used in preference to the constructor 142 * {@link #Boolean(boolean)}, as this method is likely to yield 143 * significantly better space and time performance. 144 * 145 * @param b a boolean value. 146 * @return a {@code Boolean} instance representing {@code b}. 147 * @since 1.4 148 */ 149 public static Boolean valueOf(boolean b) { 150 return (b ? TRUE : FALSE); 151 } 152 153 /** 154 * Returns a {@code Boolean} with a value represented by the 155 * specified string. The {@code Boolean} returned represents a 156 * true value if the string argument is not {@code null} 157 * and is equal, ignoring case, to the string {@code "true"}. 158 * 159 * @param s a string. 160 * @return the {@code Boolean} value represented by the string. 161 */ 162 public static Boolean valueOf(String s) { 163 return parseBoolean(s) ? TRUE : FALSE; 164 } 165 166 /** 167 * Returns a {@code String} object representing the specified 168 * boolean. If the specified boolean is {@code true}, then | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang; 27 28 import jdk.internal.HotSpotIntrinsicCandidate; 29 30 /** 31 * The Boolean class wraps a value of the primitive type 32 * {@code boolean} in an object. An object of type 33 * {@code Boolean} contains a single field whose type is 34 * {@code boolean}. 35 * <p> 36 * In addition, this class provides many methods for 37 * converting a {@code boolean} to a {@code String} and a 38 * {@code String} to a {@code boolean}, as well as other 39 * constants and methods useful when dealing with a 40 * {@code boolean}. 41 * 42 * @author Arthur van Hoff 43 * @since 1.0 44 */ 45 public final class Boolean implements java.io.Serializable, 46 Comparable<Boolean> 47 { 48 /** 49 * The {@code Boolean} object corresponding to the primitive 113 * is not {@code null} and is equal, ignoring case, to the string 114 * {@code "true"}. <p> 115 * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br> 116 * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}. 117 * 118 * @param s the {@code String} containing the boolean 119 * representation to be parsed 120 * @return the boolean represented by the string argument 121 * @since 1.5 122 */ 123 public static boolean parseBoolean(String s) { 124 return ((s != null) && s.equalsIgnoreCase("true")); 125 } 126 127 /** 128 * Returns the value of this {@code Boolean} object as a boolean 129 * primitive. 130 * 131 * @return the primitive {@code boolean} value of this object. 132 */ 133 @HotSpotIntrinsicCandidate 134 public boolean booleanValue() { 135 return value; 136 } 137 138 /** 139 * Returns a {@code Boolean} instance representing the specified 140 * {@code boolean} value. If the specified {@code boolean} value 141 * is {@code true}, this method returns {@code Boolean.TRUE}; 142 * if it is {@code false}, this method returns {@code Boolean.FALSE}. 143 * If a new {@code Boolean} instance is not required, this method 144 * should generally be used in preference to the constructor 145 * {@link #Boolean(boolean)}, as this method is likely to yield 146 * significantly better space and time performance. 147 * 148 * @param b a boolean value. 149 * @return a {@code Boolean} instance representing {@code b}. 150 * @since 1.4 151 */ 152 @HotSpotIntrinsicCandidate 153 public static Boolean valueOf(boolean b) { 154 return (b ? TRUE : FALSE); 155 } 156 157 /** 158 * Returns a {@code Boolean} with a value represented by the 159 * specified string. The {@code Boolean} returned represents a 160 * true value if the string argument is not {@code null} 161 * and is equal, ignoring case, to the string {@code "true"}. 162 * 163 * @param s a string. 164 * @return the {@code Boolean} value represented by the string. 165 */ 166 public static Boolean valueOf(String s) { 167 return parseBoolean(s) ? TRUE : FALSE; 168 } 169 170 /** 171 * Returns a {@code String} object representing the specified 172 * boolean. If the specified boolean is {@code true}, then |