Package gw.util
Class SpaceEfficientHashMap<K,V>
- java.lang.Object
-
- gw.util.SpaceEfficientHashMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class SpaceEfficientHashMap<K,V> extends java.lang.Object implements java.util.Map<K,V>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classSpaceEfficientHashMap.MyEntrySet<S,T>private classSpaceEfficientHashMap.MyListSet<T>
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object_keysprivate java.lang.Object_valuesprivate static java.lang.ObjectEMPTY_KEYprivate static intMAX_LIST_SIZE(package private) intmodCountThe number of times this HashMap has been structurally modified Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash).
-
Constructor Summary
Constructors Constructor Description SpaceEfficientHashMap()SpaceEfficientHashMap(java.util.Map<? extends K,? extends V> m)Constructs a new HashMap with the same mappings as the specified Map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()booleanequals(java.lang.Object o)Compares the specified object with this map for equality.Vget(java.lang.Object key)inthashCode()Returns the hash code value for this map.booleanisEmpty()private booleanisList()private booleanisMap()private booleanisObject()java.util.Set<K>keySet()Vput(K key, V value)voidputAll(java.util.Map<? extends K,? extends V> m)Vremove(java.lang.Object key)intsize()java.lang.StringtoString()voidtrimToSize()java.util.Collection<V>values()
-
-
-
Field Detail
-
EMPTY_KEY
private static final java.lang.Object EMPTY_KEY
-
_keys
private java.lang.Object _keys
-
_values
private java.lang.Object _values
-
MAX_LIST_SIZE
private static final int MAX_LIST_SIZE
- See Also:
- Constant Field Values
-
modCount
transient volatile int modCount
The number of times this HashMap has been structurally modified Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash). This field is used to make iterators on Collection-views of the HashMap fail-fast. (See ConcurrentModificationException).
-
-
Constructor Detail
-
SpaceEfficientHashMap
public SpaceEfficientHashMap()
-
SpaceEfficientHashMap
public SpaceEfficientHashMap(java.util.Map<? extends K,? extends V> m)
Constructs a new HashMap with the same mappings as the specified Map. The HashMap is created with default load factor (0.75) and an initial capacity sufficient to hold the mappings in the specified Map.- Parameters:
m- the map whose mappings are to be placed in this map- Throws:
java.lang.NullPointerException- if the specified map is null
-
-
Method Detail
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
values
public java.util.Collection<V> values()
-
equals
public boolean equals(java.lang.Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.This implementation first checks if the specified object is this map; if so it returns true. Then, it checks if the specified object is a map whose size is identical to the size of this map; if not, it returns false. If so, it iterates over this map's entrySet collection, and checks that the specified map contains each mapping that this map contains. If the specified map fails to contain such a mapping, false is returned. If the iteration completes, true is returned.
-
hashCode
public int hashCode()
Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract ofObject.hashCode().This implementation iterates over entrySet(), calling
hashCode()on each element (entry) in the set, and adding up the results.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isObject
private boolean isObject()
-
isList
private boolean isList()
-
isMap
private boolean isMap()
-
trimToSize
public void trimToSize()
-
-