Package gw.util
Class SpaceEfficientHashMap<K,V>
java.lang.Object
gw.util.SpaceEfficientHashMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
private final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object
private Object
private static final Object
private static final int
(package private) int
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). -
Constructor Summary
ConstructorsConstructorDescriptionSpaceEfficientHashMap
(Map<? extends K, ? extends V> m) Constructs a new HashMap with the same mappings as the specified Map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
boolean
Compares the specified object with this map for equality.int
hashCode()
Returns the hash code value for this map.boolean
isEmpty()
private boolean
isList()
private boolean
isMap()
private boolean
isObject()
keySet()
void
int
size()
toString()
void
values()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
EMPTY_KEY
-
_keys
-
_values
-
MAX_LIST_SIZE
private static final int MAX_LIST_SIZE- See Also:
-
modCount
transient volatile int modCountThe 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 Details
-
SpaceEfficientHashMap
public SpaceEfficientHashMap() -
SpaceEfficientHashMap
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:
NullPointerException
- if the specified map is null
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
equals
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
-
isObject
private boolean isObject() -
isList
private boolean isList() -
isMap
private boolean isMap() -
trimToSize
public void trimToSize()
-