src/share/classes/java/lang/Boolean.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 99,109 **** * that represents {@code false}. * * @param s the string to be converted to a {@code Boolean}. */ public Boolean(String s) { ! this(toBoolean(s)); } /** * Parses the string argument as a boolean. The {@code boolean} * returned represents the value {@code true} if the string argument --- 99,109 ---- * that represents {@code false}. * * @param s the string to be converted to a {@code Boolean}. */ public Boolean(String s) { ! this(parseBoolean(s)); } /** * Parses the string argument as a boolean. The {@code boolean} * returned represents the value {@code true} if the string argument
*** 116,126 **** * representation to be 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 {@code Boolean} object as a boolean * primitive. --- 116,126 ---- * representation to be parsed * @return the boolean represented by the string argument * @since 1.5 */ public static boolean parseBoolean(String s) { ! return ((s != null) && s.equalsIgnoreCase("true")); } /** * Returns the value of this {@code Boolean} object as a boolean * primitive.
*** 157,167 **** * * @param s a string. * @return the {@code Boolean} value represented by the string. */ public static Boolean valueOf(String s) { ! return toBoolean(s) ? TRUE : FALSE; } /** * Returns a {@code String} object representing the specified * boolean. If the specified boolean is {@code true}, then --- 157,167 ---- * * @param s a string. * @return the {@code Boolean} value represented by the string. */ public static Boolean valueOf(String s) { ! return parseBoolean(s) ? TRUE : FALSE; } /** * Returns a {@code String} object representing the specified * boolean. If the specified boolean is {@code true}, then
*** 227,245 **** * If there is no property with the specified name, or if the specified * name is empty or null, then {@code false} is returned. * * @param name the system property name. * @return the {@code boolean} value of the system property. * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.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; } /** --- 227,246 ---- * If there is no property with the specified name, or if the specified * name is empty or null, then {@code false} is returned. * * @param name the system property name. * @return the {@code boolean} value of the system property. + * @throws SecurityException for the same reasons as + * {@link System#getProperty(String) System.getProperty} * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ public static boolean getBoolean(String name) { boolean result = false; try { ! result = parseBoolean(System.getProperty(name)); ! } catch (IllegalArgumentException | NullPointerException e) { } return result; } /**
*** 273,282 **** * @since 1.7 */ public static int compare(boolean x, boolean y) { return (x == y) ? 0 : (x ? 1 : -1); } - - private static boolean toBoolean(String name) { - return ((name != null) && name.equalsIgnoreCase("true")); - } } --- 274,279 ----