harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r394868 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/Boolean.java test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
Date Tue, 18 Apr 2006 07:00:09 GMT
Author: mloenko
Date: Tue Apr 18 00:00:06 2006
New Revision: 394868

URL: http://svn.apache.org/viewcvs?rev=394868&view=rev
Log:
Fixes for HARMONY-355
 [classlib][luni] Generics uplift and clean up for java.lang.Boolean

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java?rev=394868&r1=394867&r2=394868&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/Boolean.java
Tue Apr 18 00:00:06 2006
@@ -15,12 +15,13 @@
 
 package java.lang;
 
+import java.io.Serializable;
+
 /**
  * <p>Boolean is the wrapper for the primitive type <code>boolean</code>.</p>
  * @since 1.0
  */
-public final class Boolean implements java.io.Serializable {
-    //TODO Add Comparable<Boolean> to implements when generics are supported.
+public final class Boolean implements Serializable, Comparable<Boolean> {
 
 	private static final long serialVersionUID = -3665804199014368530L;
 
@@ -30,10 +31,10 @@
 	private final boolean value;
 
 	/**
-	 * The java.lang.Class that represents this class.
-	 */
-	public static final Class TYPE = new boolean[0].getClass()
-			.getComponentType();
+     * The java.lang.Class that represents this class.
+     */
+    public static final Class<Boolean> TYPE = new boolean[0].getClass()
+            .getComponentType();
 
 	// Note: This can't be set to "boolean.class", since *that* is
 	// defined to be "java.lang.Boolean.TYPE";
@@ -58,7 +59,7 @@
 	 *            The name of the desired boolean.
 	 */
 	public Boolean(String string) {
-		this(toBoolean(string));
+		this(parseBoolean(string));
 	}
 
 	/**
@@ -100,20 +101,32 @@
 		return (o == this)
 				|| ((o instanceof Boolean) && (value == ((Boolean) o).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 (toBoolean(System.getProperty(string)));
-	}
+    
+    /**
+     * <p>
+     * Compares this <code>Boolean</code> to another <code>Boolean</code>.
+     * If this instance has the same value as the instance passed, then
+     * <code>0</code> is returned. If this instance is <code>true</code>
and
+     * the instance passed is <code>false</code>, then a positive value is
+     * returned. If this instance is <code>false</code> and the instance
+     * passed is <code>true</code>, then a negative value is returned.
+     * </p>
+     * 
+     * @param that The instance to compare to.
+     * @throws java.lang.NullPointerException if <code>that</code> is
+     *         <code>null</code>.
+     * @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 an integer hash code for the receiver. Any two objects which
@@ -127,18 +140,29 @@
 	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)));
+    }
     
     /**
      * <p>
@@ -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 <code>"true"</code>, otherwise answer
 	 * <code>"false"</code>.
@@ -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;
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java?rev=394868&r1=394867&r2=394868&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/BooleanTest.java
Tue Apr 18 00:00:06 2006
@@ -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) {
+		}
+	}
 }



Mime
View raw message