Index: /luni/src/main/java/java/lang/Boolean.java =================================================================== --- /luni/src/main/java/java/lang/Boolean.java (revision 394440) +++ /luni/src/main/java/java/lang/Boolean.java (working copy) @@ -15,12 +15,13 @@ package java.lang; +import java.io.Serializable; + /** *
Boolean is the wrapper for the primitive type boolean.
+ * Compares this Boolean to another Boolean.
+ * If this instance has the same value as the instance passed, then
+ * 0 is returned. If this instance is true and
+ * the instance passed is false, then a positive value is
+ * returned. If this instance is false and the instance
+ * passed is true, then a negative value is returned.
+ *
that is
+ * null.
+ * @since 1.5
+ * @see java.lang.Comparable
+ */
+ public int compareTo(Boolean that) {
+ if (that == null)
+ throw new NullPointerException();
+
+ if (this.value == that.value)
+ return 0;
+
+ return this.value ? 1 : -1;
+ }
/**
- * Answers true if the system property described by the argument equal to
- * "true" using case insensitive comparison, and false otherwise.
- *
- * @param string
- * The name of the desired boolean.
- * @return The boolean value.
- */
- public static boolean getBoolean(String string) {
- if (string == null || string.length() == 0)
- return false;
- return (toBoolean(System.getProperty(string)));
- }
-
- /**
* Answers an integer hash code for the receiver. Any two objects which
* answer true when passed to equals must
* answer the same value for this method.
@@ -127,20 +140,31 @@
public int hashCode() {
return value ? 1231 : 1237;
}
-
- /**
- * Answers true if the argument is equal to "true" using case insensitive
- * comparison, and false otherwise.
- *
- * @param string
- * The name of the desired boolean.
- * @return the boolean value.
- */
- static boolean toBoolean(String string) {
- return parseBoolean(string);
- }
/**
+ * Answers a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ * @return a printable representation for the receiver.
+ */
+ public String toString() {
+ return String.valueOf(value);
+ }
+
+ /**
+ * Answers true if the system property described by the argument equal to
+ * "true" using case insensitive comparison, and false otherwise.
+ *
+ * @param string The name of the desired boolean.
+ * @return The boolean value.
+ */
+ public static boolean getBoolean(String string) {
+ if (string == null || string.length() == 0)
+ return false;
+ return (parseBoolean(System.getProperty(string)));
+ }
+
+ /**
*
* Parses the string as a boolean. If the string is not
* null and is equal to "true", regardless
@@ -156,16 +180,6 @@
}
/**
- * Answers a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a printable representation for the receiver.
- */
- public String toString() {
- return String.valueOf(value);
- }
-
- /**
* Converts the specified boolean to its string representation. When the
* boolean is true answer "true", otherwise answer
* "false".
@@ -188,7 +202,7 @@
* @return the boolean value.
*/
public static Boolean valueOf(String string) {
- return toBoolean(string) ? Boolean.TRUE : Boolean.FALSE;
+ return parseBoolean(string) ? Boolean.TRUE : Boolean.FALSE;
}
/**
Index: /luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
===================================================================
--- /luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java (revision 392441)
+++ /luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java (working copy)
@@ -132,4 +132,20 @@
assertFalse(Boolean.parseBoolean(""));
assertFalse(Boolean.parseBoolean("invalid"));
}
+
+ /**
+ * @tests java.lang.Boolean#compareTo(Boolean)
+ */
+ public void test_compareToLjava_lang_Boolean() {
+ assertTrue(Boolean.TRUE.compareTo(Boolean.TRUE) == 0);
+ assertTrue(Boolean.FALSE.compareTo(Boolean.FALSE) == 0);
+ assertTrue(Boolean.TRUE.compareTo(Boolean.FALSE) > 0);
+ assertTrue(Boolean.FALSE.compareTo(Boolean.TRUE) < 0);
+
+ try {
+ Boolean.TRUE.compareTo(null);
+ fail("No NPE");
+ } catch (NullPointerException e) {
+ }
+ }
}