Class HashMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<K>, Collection<K>, Dictionary<K,​V>, Map<K,​V>
    Direct Known Subclasses:
    CategorySeries

    public class HashMap<K,​V>
    extends java.lang.Object
    implements Map<K,​V>, java.io.Serializable
    Implementation of the Map interface that is backed by a hash table.
    See Also:
    Serialized Form
    • Constructor Detail

      • HashMap

        public HashMap()
      • HashMap

        public HashMap​(int capacity)
      • HashMap

        public HashMap​(int capacity,
                       float loadFactor)
      • HashMap

        public HashMap​(Map<K,​V> map)
      • HashMap

        public HashMap​(java.util.Map<K,​V> map)
      • HashMap

        public HashMap​(java.util.Comparator<K> comparator)
    • Method Detail

      • get

        public V get​(K key)
        Retrieves the value for the given key.
        Specified by:
        get in interface Dictionary<K,​V>
        Parameters:
        key - The key whose value is to be returned.
        Returns:
        The value corresponding to key, or null if the key does not exist. Will also return null if the key refers to a null value. Use Dictionary.containsKey(K) to distinguish between these two cases.
        Throws:
        java.lang.IllegalArgumentException - If key is null.
      • put

        public V put​(K key,
                     V value)
        Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.
        Specified by:
        put in interface Dictionary<K,​V>
        Specified by:
        put in interface Map<K,​V>
        Parameters:
        key - The key whose value is to be set.
        value - The value to be associated with the given key.
        Returns:
        The value previously associated with the key.
        Throws:
        java.lang.IllegalArgumentException - If key is null.
        See Also:
        MapListener.valueAdded(Map, Object), MapListener.valueUpdated(Map, Object, Object)
      • remove

        public V remove​(K key)
        Removes a key/value pair from the map.
        Specified by:
        remove in interface Dictionary<K,​V>
        Specified by:
        remove in interface Map<K,​V>
        Parameters:
        key - The key whose mapping is to be removed.
        Returns:
        The value that was removed.
        Throws:
        java.lang.IllegalArgumentException - If key is null.
        See Also:
        MapListener.valueRemoved(Map, Object, Object)
      • containsKey

        public boolean containsKey​(K key)
        Tests the existence of a key in the dictionary.
        Specified by:
        containsKey in interface Dictionary<K,​V>
        Parameters:
        key - The key whose presence in the dictionary is to be tested.
        Returns:
        true if the key exists in the dictionary; false, otherwise.
        Throws:
        java.lang.IllegalArgumentException - If key is null.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Collection
        Tests the emptiness of the collection.
        Specified by:
        isEmpty in interface Collection<K>
        Returns:
        true if the collection contains no elements; false, otherwise.
      • getCount

        public int getCount()
        Description copied from interface: Map
        Returns the number of entries in the map.
        Specified by:
        getCount in interface Map<K,​V>
        Returns:
        Current number of map entries.
      • getCapacity

        public int getCapacity()
      • getComparator

        public java.util.Comparator<K> getComparator()
        Description copied from interface: Collection
        Returns the collection's sort order.
        Specified by:
        getComparator in interface Collection<K>
        Returns:
        The comparator used to order elements in the collection, or null if the sort order is undefined.
        See Also:
        Collection.setComparator(Comparator)
      • setComparator

        public void setComparator​(java.util.Comparator<K> comparator)
        Description copied from interface: Collection
        Sets the collection's sort order, re-ordering the collection's contents and ensuring that new entries preserve the sort order.

        Calling this method more than once with the same comparator will re-sort the collection.

        Specified by:
        setComparator in interface Collection<K>
        Specified by:
        setComparator in interface Map<K,​V>
        Parameters:
        comparator - The comparator used to order elements in the collection, or null if the collection is unsorted.
        See Also:
        MapListener.comparatorChanged(Map, Comparator)
      • iterator

        public java.util.Iterator<K> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<K>
      • getMapListeners

        public ListenerList<MapListener<K,​V>> getMapListeners()
        Description copied from interface: Map
        Returns the map listener collection.
        Specified by:
        getMapListeners in interface Map<K,​V>
        Returns:
        Current list of listeners on this map.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object