You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2006/08/04 06:49:28 UTC

svn commit: r428619 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/TreeMap.java test/java/tests/api/java/util/TreeMapTest.java

Author: pyang
Date: Thu Aug  3 21:49:27 2006
New Revision: 428619

URL: http://svn.apache.org/viewvc?rev=428619&view=rev
Log:
Fix for HARMONY-1026 ([classlib][luni] java.util.TreeMap.headMap(Object) method does not return empty SortedMap)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java?rev=428619&r1=428618&r2=428619&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java Thu Aug  3 21:49:27 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -168,8 +168,8 @@
         }
 
         private static class ComparatorBoundedIterator <K, V> extends AbstractMapIterator<K, V>  {
-            private K endKey;
-            private Comparator<? super K> cmp;
+            final private K endKey;
+            final private Comparator<? super K> cmp;
      
             ComparatorBoundedIterator(TreeMap<K, V> map,
                                            Entry<K, V> startNode, K end) {
@@ -183,6 +183,11 @@
                     node = null;
                 }
             }
+            
+            @Override
+            public boolean hasNext() {
+                return (node != null) && (cmp.compare(endKey, node.key) > 0);
+            }
         }
 
         private static class ComparatorBoundedEntryIterator <K, V> extends ComparatorBoundedIterator<K, V> implements Iterator<Map.Entry<K, V>> {
@@ -240,6 +245,11 @@
                 if ((node != null) && (endKey.compareTo(node.key) <= 0)) {
                     node = null;
                 }
+            }
+            
+            @Override
+            public boolean hasNext() {
+                return (node != null) && (endKey.compareTo(node.key) > 0);
             }
         }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java?rev=428619&r1=428618&r2=428619&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java Thu Aug  3 21:49:27 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,6 +39,18 @@
 			return (((Comparable) o1).compareTo((Comparable) o2)) == 0;
 		}
 	}
+    
+    // Regression for Harmony-1026
+    public static class MockComparator<T extends Comparable<T>> implements Comparator<T>{
+        
+        public int compare(T o1, T o2) {
+            if( o1 == o2 ) return 0;
+            if( null == o1 ) return -1;
+            T c1 = (T)o1;
+            T c2 = (T)o2;
+            return c1.compareTo(c2);
+        }
+    }
 
 	TreeMap tm;
 
@@ -238,6 +250,27 @@
 		assertTrue("Returned incorrect elements", head.containsKey("0")
 				&& head.containsValue(new Integer("1"))
 				&& head.containsKey("10"));
+        
+	    // Regression for Harmony-1026
+        TreeMap<Integer, Double> map = new TreeMap<Integer, Double>(
+                new MockComparator());
+        map.put(1, 2.1);
+        map.put(2, 3.1);
+        map.put(3, 4.5);
+        map.put(7, 21.3);
+        map.put(null, null);
+
+        SortedMap<Integer, Double> smap = map.headMap(null);
+        assertEquals(0, smap.size());
+        
+        Set<Integer> keySet = smap.keySet();
+        assertEquals(0, keySet.size());
+        
+        Set<Map.Entry<Integer, Double>> entrySet = smap.entrySet();
+        assertEquals(0, entrySet.size());
+        
+        Collection<Double> valueCollection = smap.values();
+        assertEquals(0, valueCollection.size());
 	}
 
 	/**