harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r395479 - in /incubator/harmony/enhanced/classlib/trunk/modules: jndi/src/main/java/javax/naming/ luni/src/main/java/java/lang/ luni/src/main/java/java/util/ luni/src/test/java/tests/api/java/lang/
Date Thu, 20 Apr 2006 04:48:41 GMT
Author: mloenko
Date: Wed Apr 19 21:48:39 2006
New Revision: 395479

URL: http://svn.apache.org/viewcvs?rev=395479&view=rev
Log:
fixes for HARMONY-376
[classlib][luni] Generics uplift for java.lang.String and java.util.Comparator

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Comparator.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/StringTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java?rev=395479&r1=395478&r2=395479&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/CompositeName.java
Wed Apr 19 21:48:39 2006
@@ -506,7 +506,7 @@
             CompositeName he = (CompositeName) o;
             int r;
             for (int i = 0; i < elems.size() && i < he.elems.size(); i++) {
-                r = ((String) elems.get(i)).compareTo(he.elems.get(i));
+                r = ((String) elems.get(i)).compareTo((String)he.elems.get(i));
                 if (r != 0) {
                     return r;
                 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java?rev=395479&r1=395478&r2=395479&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/String.java
Wed Apr 19 21:48:39 2006
@@ -40,7 +40,7 @@
  * 
  * @see StringBuffer
  */
-public final class String implements Serializable, Comparable, CharSequence {
+public final class String implements Serializable, Comparable<String>, CharSequence
{
 	private static final long serialVersionUID = -6849794470754667710L;
 
 	/**
@@ -94,7 +94,7 @@
 	 * CaseInsensitiveComparator compares Strings ignoring the case of the
 	 * characters.
 	 */
-	private static final class CaseInsensitiveComparator implements Comparator,
+	private static final class CaseInsensitiveComparator implements Comparator<String>,
 			Serializable {
 		private static final long serialVersionUID = 8575799808933029326L;
 
@@ -111,15 +111,15 @@
 		 * @exception ClassCastException
 		 *                when objects are not the correct type
 		 */
-		public int compare(Object o1, Object o2) {
-			return ((String) o1).compareToIgnoreCase((String) o2);
+		public int compare(String o1, String o2) {
+			return o1.compareToIgnoreCase(o2);
 		}
 	}
 
 	/*
 	 * A Comparator which compares Strings ignoring the case of the characters.
 	 */
-	public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
+	public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
 
 	private static final char[] ascii;
 
@@ -503,22 +503,6 @@
 		if (0 <= index && index < count)
 			return value[offset + index];
 		throw new StringIndexOutOfBoundsException();
-	}
-
-	/**
-	 * Compare the receiver to the specified Object to determine the relative
-	 * ordering.
-	 * 
-	 * @param object
-	 *            an Object
-	 * @return an int < 0 if this String is less than the specified String, 0 if
-	 *         they are equal, and > 0 if this String is greater
-	 * 
-	 * @throws ClassCastException
-	 *             when object is not a String
-	 */
-	public int compareTo(Object object) {
-		return compareTo((String) object);
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Comparator.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Comparator.java?rev=395479&r1=395478&r2=395479&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Comparator.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Comparator.java
Wed Apr 19 21:48:39 2006
@@ -15,12 +15,13 @@
 
 package java.util;
 
-
 /**
  * Comparator is used to compare two objects to determine their ordering in
  * respect to each other.
+ * 
+ * @since 1.2
  */
-public interface Comparator {
+public interface Comparator<T> {
 	/**
 	 * Compare the two objects to determine the relative ordering.
 	 * 
@@ -34,7 +35,7 @@
 	 * @exception ClassCastException
 	 *                when objects are not the correct type
 	 */
-	public int compare(Object object1, Object object2);
+	public int compare(T object1, T object2);
 
 	/**
 	 * Compares the argument to the receiver, and answers true if they represent

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/StringTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/StringTest.java?rev=395479&r1=395478&r2=395479&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/StringTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/StringTest.java
Wed Apr 19 21:48:39 2006
@@ -181,23 +181,6 @@
 	}
 
 	/**
-	 * @tests java.lang.String#compareTo(java.lang.Object)
-	 */
-	public void test_compareToLjava_lang_Object() {
-		// Test for method int java.lang.String.compareTo(java.lang.Object)
-		String s = "VV";
-		assertTrue("Comparison failed for same strings", s
-				.compareTo((Object) s) == 0);
-		try {
-			s.compareTo(new Object());
-		} catch (ClassCastException e) {
-			// Correct
-			return;
-		}
-		fail("Failed to throw exception when compared to non String");
-	}
-
-	/**
 	 * @tests java.lang.String#compareTo(java.lang.String)
 	 */
 	public void test_compareToLjava_lang_String() {
@@ -210,6 +193,12 @@
 				.compareTo("aaaaab") > 0);
 		assertTrue("Considered case to not be of importance", !("A"
 				.compareTo("a") == 0));
+        
+        try {
+            "fixture".compareTo(null);
+            fail("No NPE");
+        } catch (NullPointerException e) {
+        }
 	}
 
 	/**
@@ -244,6 +233,12 @@
 		} finally {
 			Locale.setDefault(defLocale);
 		}
+        
+        try {
+            "fixture".compareToIgnoreCase(null);
+            fail("No NPE");
+        } catch (NullPointerException e) {
+        }
 	}
 
 	/**



Mime
View raw message