Class AionMap<K,​V>

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

    public class AionMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​V>
    Hash table based implementation of the Map interface.

    This implementation provides all of the optional map operations, and permits null values. null key will be rejected for this map.

    An instance of AionMap has two parameters that affect its performance: initial capacity and load factor. capacity is the number of buckets in the hash table, and load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. Threshold for initiating a rehashing operation is calculated as the product of the load factor and the current capacity. When the number of hash table entries exceed this threshold, the capacity is doubled and the internal structure is rebuilt by rehashing all the keys.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Constructor Summary

      Constructors 
      Constructor Description
      AionMap()
      Constructs an empty AionMap with the default capacity (16) and load factor (0.75).
      AionMap​(int initialCapacity, float loadFactor)
      Constructs an empty AionMap.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all of the mappings from this map.
      boolean containsKey​(java.lang.Object key)
      Returns true if this map contains a mapping for the specified key.
      boolean containsValue​(java.lang.Object value)
      Returns true if this map maps one or more keys to the specified value.
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      Returns a Set view of the mappings contained in this map.
      V get​(java.lang.Object key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      V getOrDefault​(java.lang.Object key, V defaultValue)
      Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
      boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      java.util.Set<K> keySet()
      Returns a Set view of the keys contained in this map.
      V put​(K key, V value)
      Associates the specified value with the specified key in this map.
      void putAll​(java.util.Map<? extends K,​? extends V> m)
      Copies all of the mappings from the specified map to this map.
      V remove​(java.lang.Object key)
      Removes the mapping for the specified key from this map if present.
      int size()
      Returns the number of key-value mappings in this map.
      java.util.Collection<V> values()
      Returns a Collection view of the values contained in this map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Constructor Detail

      • AionMap

        public AionMap​(int initialCapacity,
                       float loadFactor)
        Constructs an empty AionMap.
        Parameters:
        initialCapacity - The initial initialCapacity of the AionMap
        loadFactor - The load factor for the hash table.
      • AionMap

        public AionMap()
        Constructs an empty AionMap with the default capacity (16) and load factor (0.75).
    • Method Detail

      • size

        public int size()
        Returns the number of key-value mappings in this map.
        Specified by:
        size in interface java.util.Map<K,​V>
        Returns:
        the number of key-value mappings in this map
      • isEmpty

        public boolean isEmpty()
        Returns true if this map contains no key-value mappings.
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
        Returns:
        true if this map contains no key-value mappings
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Parameters:
        key - The key whose presence in this map is to be tested
        Returns:
        true if this map contains a mapping for the specified key.
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Returns true if this map maps one or more keys to the specified value.
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Parameters:
        value - value whose presence in this map is to be tested
        Returns:
        true if this map maps one or more keys to the specified value
      • get

        public V get​(java.lang.Object key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

        A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

        Specified by:
        get in interface java.util.Map<K,​V>
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • put

        public V put​(K key,
                     V value)
        Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
        Specified by:
        put in interface java.util.Map<K,​V>
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • remove

        public V remove​(java.lang.Object key)
        Removes the mapping for the specified key from this map if present.
        Specified by:
        remove in interface java.util.Map<K,​V>
        Parameters:
        key - key whose mapping is to be removed from the map
        Returns:
        the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
        Throws:
        java.lang.NullPointerException - if the specified key is null
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Parameters:
        m - mappings to be stored in this map
        Throws:
        java.lang.NullPointerException - if the specified map is null
      • clear

        public void clear()
        Removes all of the mappings from this map. The map will be empty after this call returns. The capacity of this map will remain the same.
        Specified by:
        clear in interface java.util.Map<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Returns a Set view of the keys contained in this map. The key set is based on a snapshot of the map. Modifications of the map after key set generation will not be reflected back to existing key set, and vice-versa.
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Returns:
        a set view of the keys contained in this map
      • values

        public java.util.Collection<V> values()
        Returns a Collection view of the values contained in this map. Values is based on a snapshot of the map. Modifications of the map after values generation will not be reflected back to existing values, and vice-versa.
        Specified by:
        values in interface java.util.Map<K,​V>
        Returns:
        a view of the values contained in this map
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Returns a Set view of the mappings contained in this map. The entry set is based on a snapshot of the map. Modifications of the map after entry set generation will not be reflected back to existing entry set, and vice-versa.
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Returns:
        a set view of the mappings contained in this map
      • getOrDefault

        public V getOrDefault​(java.lang.Object key,
                              V defaultValue)
        Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key.
        Specified by:
        getOrDefault in interface java.util.Map<K,​V>
        Parameters:
        key - the key whose associated value is to be returned
        defaultValue - the default mapping of the key
        Returns:
        the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key