You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by lv...@apache.org on 2009/10/12 12:52:16 UTC

svn commit: r824293 - /harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java

Author: lvjing
Date: Mon Oct 12 10:52:16 2009
New Revision: 824293

URL: http://svn.apache.org/viewvc?rev=824293&view=rev
Log:
Commit several fixes for TreeMap: fix an endkey mis-checking problem in subMap.iterator; fix a mistyping in findCeilingEntry; the testcases will be committed as well 

Modified:
    harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java?rev=824293&r1=824292&r2=824293&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/TreeMap.java Mon Oct 12 10:52:16 2009
@@ -886,10 +886,12 @@
                         if (backingMap.cmp(object,  endKey, lastKeyNode.keys[lastKeyIndex]) != 0) {
                             return lastKeyNode.keys[lastKeyIndex];
                         } else {
+						        // according to subMap, it excludes the last element 
                             if (lastKeyIndex != lastKeyNode.left_idx) {
                                 object = backingMap.comparator == null ? toComparable((K) startKey)
                                         : null;
-                                if (backingMap.cmp(object,  startKey, lastKeyNode.keys[lastKeyIndex-1]) < 0){
+							    // check if the element is smaller than the startkey, there's no lastkey
+                                if (backingMap.cmp(object,  startKey, lastKeyNode.keys[lastKeyIndex-1]) <= 0){
                                     return lastKeyNode.keys[lastKeyIndex - 1];
                                 }
                             } else {
@@ -1244,9 +1246,12 @@
                 from = minimum(subMap.backingMap.root);
                 fromIndex = from != null ? from.left_idx : 0;
             }
+            if (from == null){
+                return new BoundedKeyIterator<K, V>(null, 0, subMap.backingMap, null, 0);
+            }
             if (!subMap.hasEnd) {
-                return new UnboundedKeyIterator<K, V>(subMap.backingMap, from,
-                        from == null ? 0 : from.right_idx - fromIndex);
+                return new UnboundedKeyIterator<K, V>(subMap.backingMap,
+                        from, from == null ? 0 : from.right_idx - fromIndex);
             }
             subMap.setLastKey();
             Node<K, V> to = subMap.lastKeyNode;
@@ -1256,11 +1261,14 @@
                     + (subMap.lastKeyNode != null
                             && (!subMap.lastKeyNode.keys[subMap.lastKeyIndex].equals(subMap.endKey)) ? 1
                             : 0);
-            if (to != null
-                    && toIndex > to.right_idx) {
+            if (subMap.lastKeyNode != null && toIndex > subMap.lastKeyNode.right_idx){
                 to = to.next;
                 toIndex = to != null ? to.left_idx : 0;
             }
+            // no intial nor end key, return a unbounded iterator
+            if (to == null) {
+                return new UnboundedKeyIterator(subMap.backingMap, from,fromIndex);
+            } else 
             return new BoundedKeyIterator<K, V>(from, from == null ? 0
                     : fromIndex, subMap.backingMap, to,
                     to == null ? 0 : toIndex);
@@ -1296,6 +1304,9 @@
                 from = minimum(subMap.backingMap.root);
                 fromIndex = from != null ? from.left_idx : 0;
             }
+            if (from == null){
+                return new BoundedEntryIterator<K, V>(null, 0, subMap.backingMap, null, 0);
+            }
             if (!subMap.hasEnd) {
                 return new UnboundedEntryIterator<K, V>(subMap.backingMap,
                         from, from == null ? 0 : from.right_idx - fromIndex);
@@ -4088,7 +4099,7 @@
             foundNode = null;
         }
         if (foundNode != null){
-            return null;// createEntry(foundNode, foundIndex);
+            return createEntry(foundNode, foundIndex);
         }
         return null;
     }