harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r680223 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Arrays.java test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
Date Mon, 28 Jul 2008 01:53:26 GMT
Author: qiuxx
Date: Sun Jul 27 18:53:26 2008
New Revision: 680223

URL: http://svn.apache.org/viewvc?rev=680223&view=rev
Log:
Fixing java.util.Arrays.sort(Object, Comparator) behavior difference from RI,  make the sort
result corrct when the comparator is special.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java?rev=680223&r1=680222&r2=680223&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Arrays.java Sun Jul
27 18:53:26 2008
@@ -2520,7 +2520,7 @@
             Object fromVal = in[start];
             Object rVal = in[r];
             if (c.compare(fromVal, rVal) <= 0) {
-                int l_1 = find(in, rVal, -1, start + 1, med - 1, c);
+                int l_1 = find(in, rVal, 0, start + 1, med - 1, c);
                 int toCopy = l_1 - start + 1;
                 System.arraycopy(in, start, out, i, toCopy);
                 i += toCopy;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java?rev=680223&r1=680222&r2=680223&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java
Sun Jul 27 18:53:26 2008
@@ -1296,7 +1296,8 @@
 	/**
 	 * @tests java.util.Arrays#sort(java.lang.Object[], java.util.Comparator)
 	 */
-	public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
+    @SuppressWarnings("unchecked")
+    public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
 		// Test for method void java.util.Arrays.sort(java.lang.Object [],
 		// java.util.Comparator)
 		ReversedIntegerComparator comp = new ReversedIntegerComparator();
@@ -1306,6 +1307,52 @@
 					comp
 							.compare(objectArray[counter],
 									objectArray[counter + 1]) <= 0);
+        
+        // Test the sort functionailty with an Integer array
+        int[] original = { 190, 180, 170, 160, 150, 140, 120, 320, 110, 310,
+                100, 300, 290, 280, 270, 260, 250, 240, 230, 210, 200 };
+        Integer[] sorted = { 100, 110, 120, 140, 150, 160, 170, 180, 190, 200,
+                210, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320 };
+
+        Integer[] elements = new Integer[original.length];
+        for (int i=0; i < original.length; i++){
+            elements[i] = new Integer(original[i]);
+        }
+        
+        Comparator normalComparator = new Comparator(){
+            public int compare(Object o1, Object o2) {
+                Integer e1 = (Integer)o1;
+                Integer e2 = (Integer)o2;
+                if (e1 > e2){
+                    return 1;
+                }else if(e1 < e2){
+                    return -1;
+                }else{
+                    return 0;
+                }
+            }
+        };
+        Arrays.sort(elements, normalComparator);
+        // After sorting, elements should be the same as sorted array.
+        for(int i = 0; i < original.length; i++){
+            assertEquals(sorted[i],elements[i]);
+        }
+
+        for (int i=0; i < original.length; i++){
+            elements[i] = new Integer(original[i]);
+        }
+        Comparator comparator = new Comparator(){
+            public int compare(Object o1, Object o2) {
+                Integer e1 = (Integer)o1;
+                Integer e2 = (Integer)o2;
+                return e1 > e2 ? 1 : 0;
+            }
+        };
+        Arrays.sort(elements, comparator);
+        // After sorting, elements should be the same as sorted array.
+        for(int i = 0; i < original.length; i++){
+            assertEquals(sorted[i],elements[i]);
+        }
 	}
 
 	/**



Mime
View raw message