--- jsr166/src/main/java/util/TreeMap.java 2005/03/22 01:30:10 1.4
+++ jsr166/src/main/java/util/TreeMap.java 2005/03/31 15:23:10 1.7
@@ -11,7 +11,7 @@ package java.util;
/**
* Red-Black tree based implementation of the NavigableMap interface.
* This class guarantees that the map will be in ascending key order, sorted
- * according to the natural order for the key's class (see
+ * according to the natural order for the keys' class (see
* Comparable), or by the comparator provided at creation time,
* depending on which constructor is used.
*
@@ -61,7 +61,7 @@ package java.util;
* throw ConcurrentModificationException on a best-effort basis.
* Therefore, it would be wrong to write a program that depended on this
* exception for its correctness: the fail-fast behavior of iterators
- * should be used only to detect bugs.
+ * should be used only to detect bugs.
*
*
All Map.Entry pairs returned by methods in this class
* and its views represent snapshots of mappings at the time they were
@@ -542,7 +542,7 @@ public class TreeMap
* @param key key with which the specified value is to be associated.
* @param value value to be associated with the specified key.
*
- * @return previous value associated with specified key, or null
+ * @return the previous value associated with specified key, or null
* if there was no mapping for key. A null return can
* also indicate that the map previously associated null
* with the specified key.
@@ -591,7 +591,7 @@ public class TreeMap
* Removes the mapping for this key from this TreeMap if present.
*
* @param key key for which mapping should be removed
- * @return previous value associated with specified key, or null
+ * @return the previous value associated with specified key, or null
* if there was no mapping for key. A null return can
* also indicate that the map previously associated
* null with the specified key.
@@ -670,8 +670,6 @@ public class TreeMap
/**
* Returns a key-value mapping associated with the greatest
* key in this map, or null if the map is empty.
- * The returned entry does not support
- * the Entry.setValue method.
*
* @return an Entry with greatest key, or null
* if the map is empty.
@@ -1145,7 +1143,7 @@ public class TreeMap
* the key-value mappings in m whose keys are less than or equal
* to high:
*
- * NavigableMap head = m.headMap(high+"\0");
+ * NavigableMap head = m.navigableHeadMap(high+"\0");
*
*
* @param toKey high endpoint (exclusive) of the headMap.
@@ -1185,7 +1183,7 @@ public class TreeMap
* are strings. The following idiom obtains a view containing
* all of the key-value mappings in m whose keys are strictly
* greater than low:
- * NavigableMap tail = m.tailMap(low+"\0");
+ * NavigableMap tail = m.navigableTailMap(low+"\0");
*
*
* @param fromKey low endpoint (inclusive) of the tailMap.
@@ -1310,7 +1308,7 @@ public class TreeMap
}
public boolean isEmpty() {
- return entrySet.isEmpty();
+ return entrySet().isEmpty();
}
public boolean containsKey(Object key) {
@@ -1374,7 +1372,7 @@ public class TreeMap
public Map.Entry pollFirstEntry() {
TreeMap.Entry e = fromStart ?
getFirstEntry() : getCeilingEntry(fromKey);
- if (e == null || (!fromStart && compare(e.key, fromKey) < 0))
+ if (e == null || (!toEnd && compare(e.key, toKey) >= 0))
return null;
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e);
deleteEntry(e);
@@ -1384,7 +1382,7 @@ public class TreeMap
public Map.Entry pollLastEntry() {
TreeMap.Entry e = toEnd ?
getLastEntry() : getLowerEntry(toKey);
- if (e == null || (!toEnd && compare(e.key, toKey) >= 0))
+ if (e == null || (!fromStart && compare(e.key, fromKey) < 0))
return null;
Map.Entry result = new AbstractMap.SimpleImmutableEntry(e);
deleteEntry(e);
@@ -1464,10 +1462,11 @@ public class TreeMap
return e == null? null : e.key;
}
- private transient Set> entrySet = new EntrySetView();
+ private transient Set> entrySet = null;
public Set> entrySet() {
- return entrySet;
+ Set> es = entrySet;
+ return (es != null)? es : (entrySet = new EntrySetView());
}
private class EntrySetView extends AbstractSet> {
@@ -2164,8 +2163,9 @@ public class TreeMap
// Write out size (number of Mappings)
s.writeInt(size);
+ Set> es = entrySet();
// Write out keys and values (alternating)
- for (Iterator> i = entrySet().iterator(); i.hasNext(); ) {
+ for (Iterator> i = es.iterator(); i.hasNext(); ) {
Map.Entry e = i.next();
s.writeObject(e.getKey());
s.writeObject(e.getValue());