1 /*
2 * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
188 public String toString() {
189 return value ? "true" : "false";
190 }
191
192 /**
193 * Returns a hash code for this {@code Boolean} object.
194 *
195 * @return the integer {@code 1231} if this object represents
196 * {@code true}; returns the integer {@code 1237} if this
197 * object represents {@code false}.
198 */
199 @Override
200 public int hashCode() {
201 return Boolean.hashCode(value);
202 }
203
204 /**
205 * Returns a hash code for a {@code boolean} value; compatible with
206 * {@code Boolean.hashCode()}.
207 *
208 * @since 1.8
209 *
210 * @return a hash code value for a {@code boolean} value.
211 */
212 public static int hashCode(boolean value) {
213 return value ? 1231 : 1237;
214 }
215
216 /**
217 * Returns {@code true} if and only if the argument is not
218 * {@code null} and is a {@code Boolean} object that
219 * represents the same {@code boolean} value as this object.
220 *
221 * @param obj the object to compare with.
222 * @return {@code true} if the Boolean objects represent the
223 * same value; {@code false} otherwise.
224 */
225 public boolean equals(Object obj) {
226 if (obj instanceof Boolean) {
227 return value == ((Boolean)obj).booleanValue();
228 }
229 return false;
230 }
|
1 /*
2 * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
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
188 public String toString() {
189 return value ? "true" : "false";
190 }
191
192 /**
193 * Returns a hash code for this {@code Boolean} object.
194 *
195 * @return the integer {@code 1231} if this object represents
196 * {@code true}; returns the integer {@code 1237} if this
197 * object represents {@code false}.
198 */
199 @Override
200 public int hashCode() {
201 return Boolean.hashCode(value);
202 }
203
204 /**
205 * Returns a hash code for a {@code boolean} value; compatible with
206 * {@code Boolean.hashCode()}.
207 *
208 * @param value the value to hash
209 * @return a hash code value for a {@code boolean} value.
210 * @since 1.8
211 */
212 public static int hashCode(boolean value) {
213 return value ? 1231 : 1237;
214 }
215
216 /**
217 * Returns {@code true} if and only if the argument is not
218 * {@code null} and is a {@code Boolean} object that
219 * represents the same {@code boolean} value as this object.
220 *
221 * @param obj the object to compare with.
222 * @return {@code true} if the Boolean objects represent the
223 * same value; {@code false} otherwise.
224 */
225 public boolean equals(Object obj) {
226 if (obj instanceof Boolean) {
227 return value == ((Boolean)obj).booleanValue();
228 }
229 return false;
230 }
|