62 *
63 * @since 1.1
64 */
65 @SuppressWarnings("unchecked")
66 public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
67
68 /**
69 * The value of the Boolean.
70 *
71 * @serial
72 */
73 private final boolean value;
74
75 /** use serialVersionUID from JDK 1.0.2 for interoperability */
76 private static final long serialVersionUID = -3665804199014368530L;
77
78 /**
79 * Allocates a {@code Boolean} object representing the
80 * {@code value} argument.
81 *
82 * <p><b>Note: It is rarely appropriate to use this constructor.
83 * Unless a <i>new</i> instance is required, the static factory
84 * {@link #valueOf(boolean)} is generally a better choice. It is
85 * likely to yield significantly better space and time performance.</b>
86 *
87 * @param value the value of the {@code Boolean}.
88 */
89 public Boolean(boolean value) {
90 this.value = value;
91 }
92
93 /**
94 * Allocates a {@code Boolean} object representing the value
95 * {@code true} if the string argument is not {@code null}
96 * and is equal, ignoring case, to the string {@code "true"}.
97 * Otherwise, allocate a {@code Boolean} object representing the
98 * value {@code false}. Examples:<p>
99 * {@code new Boolean("True")} produces a {@code Boolean} object
100 * that represents {@code true}.<br>
101 * {@code new Boolean("yes")} produces a {@code Boolean} object
102 * that represents {@code false}.
103 *
104 * @param s the string to be converted to a {@code Boolean}.
105 */
106 public Boolean(String s) {
107 this(parseBoolean(s));
108 }
109
110 /**
111 * Parses the string argument as a boolean. The {@code boolean}
112 * returned represents the value {@code true} if the string argument
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 }
|
62 *
63 * @since 1.1
64 */
65 @SuppressWarnings("unchecked")
66 public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
67
68 /**
69 * The value of the Boolean.
70 *
71 * @serial
72 */
73 private final boolean value;
74
75 /** use serialVersionUID from JDK 1.0.2 for interoperability */
76 private static final long serialVersionUID = -3665804199014368530L;
77
78 /**
79 * Allocates a {@code Boolean} object representing the
80 * {@code value} argument.
81 *
82 * @param value the value of the {@code Boolean}.
83 *
84 * @deprecated
85 * It is rarely appropriate to use this constructor. The static factory
86 * {@link #valueOf(boolean)} is generally a better choice, as it is
87 * likely to yield significantly better space and time performance.
88 * Also consider using the final fields {@link #TRUE} and {@link #FALSE}
89 * if possible.
90 */
91 @Deprecated(since="9")
92 public Boolean(boolean value) {
93 this.value = value;
94 }
95
96 /**
97 * Allocates a {@code Boolean} object representing the value
98 * {@code true} if the string argument is not {@code null}
99 * and is equal, ignoring case, to the string {@code "true"}.
100 * Otherwise, allocates a {@code Boolean} object representing the
101 * value {@code false}.
102 *
103 * @param s the string to be converted to a {@code Boolean}.
104 *
105 * @deprecated
106 * It is rarely appropriate to use this constructor.
107 * Use {@link #parseBoolean(String)} to convert a string to a
108 * {@code boolean} primitive, or use {@link #valueOf(String)}
109 * to convert a string to a {@code Boolean} object.
110 */
111 @Deprecated(since="9")
112 public Boolean(String s) {
113 this(parseBoolean(s));
114 }
115
116 /**
117 * Parses the string argument as a boolean. The {@code boolean}
118 * returned represents the value {@code true} if the string argument
119 * is not {@code null} and is equal, ignoring case, to the string
120 * {@code "true"}. <p>
121 * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
122 * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
123 *
124 * @param s the {@code String} containing the boolean
125 * representation to be parsed
126 * @return the boolean represented by the string argument
127 * @since 1.5
128 */
129 public static boolean parseBoolean(String s) {
130 return ((s != null) && s.equalsIgnoreCase("true"));
131 }
|