--- jsr166/src/main/java/util/TreeMap.java 2006/05/10 02:31:44 1.38 +++ jsr166/src/main/java/util/TreeMap.java 2007/01/30 03:54:29 1.42 @@ -1,7 +1,7 @@ /* * %W% %E% * - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ @@ -1209,6 +1209,12 @@ public class TreeMap // SubMaps /** + * Dummy value serving as unmatchable fence key for unbounded + * SubMapIterators + */ + private static final Object UNBOUNDED = new Object(); + + /** * @serial include */ static abstract class NavigableSubMap extends AbstractMap @@ -1547,7 +1553,7 @@ public class TreeMap abstract class SubMapIterator implements Iterator { TreeMap.Entry lastReturned; TreeMap.Entry next; - final K fenceKey; + final Object fenceKey; int expectedModCount; SubMapIterator(TreeMap.Entry first, @@ -1555,7 +1561,7 @@ public class TreeMap expectedModCount = m.modCount; lastReturned = null; next = first; - fenceKey = fence == null ? null : fence.key; + fenceKey = fence == null ? UNBOUNDED : fence.key; } public final boolean hasNext() { @@ -1689,7 +1695,7 @@ public class TreeMap } public NavigableMap headMap(K toKey, boolean inclusive) { - if (!inClosedRange(toKey)) + if (!inRange(toKey, inclusive)) throw new IllegalArgumentException("toKey out of range"); return new AscendingSubMap(m, fromStart, lo, loInclusive, @@ -2353,7 +2359,7 @@ public class TreeMap if (hi < lo) return null; - int mid = (lo + hi) / 2; + int mid = (lo + hi) >>> 1; Entry left = null; if (lo < mid)