Package gw.util
Class SpaceEfficientHashMap<K,V>
- java.lang.Object
-
- gw.util.SpaceEfficientHashMap<K,V>
-
-
Constructor Summary
Constructors Constructor Description SpaceEfficientHashMap()
SpaceEfficientHashMap(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 void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object o)
Compares the specified object with this map for equality.V
get(Object key)
int
hashCode()
Returns the hash code value for this map.boolean
isEmpty()
Set<K>
keySet()
V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
V
remove(Object key)
int
size()
String
toString()
void
trimToSize()
Collection<V>
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
-
-
-
-
Constructor Detail
-
SpaceEfficientHashMap
public SpaceEfficientHashMap()
-
SpaceEfficientHashMap
public SpaceEfficientHashMap(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:
NullPointerException
- if the specified map is null
-
-
Method Detail
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
equals
public boolean equals(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.- Specified by:
hashCode
in interfaceMap<K,V>
- Overrides:
hashCode
in classObject
- Returns:
- the hash code value for this map
- See Also:
Map.Entry.hashCode()
,Object.equals(Object)
,Set.equals(Object)
-
trimToSize
public void trimToSize()
-
-