float loadFactor;
int numItems;
int threshold;
+ Collection values;
+ Set keys;
public HashMap() {
init(16, 0.75f);
table[bin]=he;
return null;
}
+
+ public Collection values()
+ {
+ if (values == null)
+ // We don't bother overriding many of the optional methods, as doing so
+ // wouldn't provide any significant performance advantage.
+ values = new AbstractCollection()
+ {
+
+ public int size()
+ {
+ return size;
+ }
+
+ public Iterator iterator()
+ {
+ // Cannot create the iterator directly, because of LinkedHashMap.
+ return HashMapIterator(HashMap.this, 1);
+ }
+
+ public void clear()
+ {
+ HashMap.this.clear();
+ }
+ };
+ return values;
+ }
+
+ public Set keySet()
+ {
+ if (keys == null)
+ // Create an AbstractSet with custom implementations of those methods
+ // that can be overridden easily and efficiently.
+ keys = new AbstractSet()
+ {
+ public int size()
+ {
+ return size;
+ }
+
+ public Iterator iterator()
+ {
+ // Cannot create the iterator directly, because of LinkedHashMap.
+ //return HashMap.this.iterator(KEYS);
+ return HashMapIterator(HashMap.this, 0);
+ }
+
+ public void clear()
+ {
+ HashMap.this.clear();
+ }
+
+ public boolean contains(Object o)
+ {
+ return containsKey(o);
+ }
+
+ public boolean remove(Object o)
+ {
+ // Test against the size of the HashMap to determine if anything
+ // really got removed. This is necessary because the return value
+ // of HashMap.remove() is ambiguous in the null case.
+ int oldsize = size;
+ HashMap.this.remove(o);
+ return oldsize != size;
+ }
+ };
+ return keys;
+ }
}