Package gw.util

Class SpaceEfficientHashMap<K,​V>

  • All Implemented Interfaces:
    Map<K,​V>

    public class SpaceEfficientHashMap<K,​V>
    extends Object
    implements Map<K,​V>
    • 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

      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • containsKey

        public boolean containsKey​(Object key)
        Specified by:
        containsKey in interface Map<K,​V>
      • get

        public V get​(Object key)
        Specified by:
        get in interface Map<K,​V>
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface Map<K,​V>
      • remove

        public V remove​(Object key)
        Specified by:
        remove in interface Map<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface Map<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<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.

        Specified by:
        equals in interface Map<K,​V>
        Overrides:
        equals in class Object
        Parameters:
        o - object to be compared for equality with this map
        Returns:
        true if the specified object is equal to this map
      • 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 of Object.hashCode().

        This implementation iterates over entrySet(), calling hashCode() on each element (entry) in the set, and adding up the results.

        Specified by:
        hashCode in interface Map<K,​V>
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this map
        See Also:
        Map.Entry.hashCode(), Object.equals(Object), Set.equals(Object)
      • trimToSize

        public void trimToSize()