Class LimitedHashMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​V>
    Direct Known Subclasses:
    LimitedHashMapAbstractState

    public class LimitedHashMap<K,​V>
    extends java.util.HashMap<K,​V>
    This LimitedHashMap is a HashMap which limits its content based on the function removeElement. removeElement determines whether the map limit is reached. If it returns an empty value, the map behaves as usual. Otherwise, the returned key is removed from the map.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      V compute​(K key, java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)  
      V computeIfAbsent​(K key, java.util.function.Function<? super K,​? extends V> mappingFunction)  
      V merge​(K key, V value, java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction)  
      V put​(K key, V value)  
      void putAll​(java.util.Map<? extends K,​? extends V> m)  
      V putIfAbsent​(K key, V value)  
      • Methods inherited from class java.util.HashMap

        clear, clone, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, remove, remove, replace, replace, replaceAll, size, values
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        equals, hashCode
    • Constructor Detail

      • LimitedHashMap

        public LimitedHashMap​(TriFunction<LimitedHashMap<K,​V>,​K,​V,​java.util.Optional<K>> removeElement)
        Create an empty limited hash map.
        Parameters:
        removeElement - determines whether the map limit is reached if it returns an empty value, the map behaves as usual otherwise, the returned key is removed from the map
      • LimitedHashMap

        public LimitedHashMap​(int initialCapacity,
                              TriFunction<LimitedHashMap<K,​V>,​K,​V,​java.util.Optional<K>> removeElement)
        Create an empty limited map with reserved initial capacity.
        Parameters:
        initialCapacity - the initial capacity of the hash table
        removeElement - determines whether the map limit is reached if it returns an empty value, the map behaves as usual otherwise, the returned key is removed from the map
      • LimitedHashMap

        public LimitedHashMap​(java.util.Map<? extends K,​? extends V> m,
                              TriFunction<LimitedHashMap<K,​V>,​K,​V,​java.util.Optional<K>> removeElement)
        Create a limited map from another map and a tripredicate.
        Parameters:
        m - map which elements are used for initialization
        removeElement - determines whether the map limit is reached if it returns an empty value, the map behaves as usual otherwise, the returned key is removed from the map
    • Method Detail

      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.HashMap<K,​V>
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface java.util.Map<K,​V>
        Overrides:
        putAll in class java.util.HashMap<K,​V>
      • putIfAbsent

        public V putIfAbsent​(K key,
                             V value)
        Specified by:
        putIfAbsent in interface java.util.Map<K,​V>
        Overrides:
        putIfAbsent in class java.util.HashMap<K,​V>
      • computeIfAbsent

        public V computeIfAbsent​(K key,
                                 java.util.function.Function<? super K,​? extends V> mappingFunction)
        Specified by:
        computeIfAbsent in interface java.util.Map<K,​V>
        Overrides:
        computeIfAbsent in class java.util.HashMap<K,​V>
      • compute

        public V compute​(K key,
                         java.util.function.BiFunction<? super K,​? super V,​? extends V> remappingFunction)
        Specified by:
        compute in interface java.util.Map<K,​V>
        Overrides:
        compute in class java.util.HashMap<K,​V>
      • merge

        public V merge​(K key,
                       V value,
                       java.util.function.BiFunction<? super V,​? super V,​? extends V> remappingFunction)
        Specified by:
        merge in interface java.util.Map<K,​V>
        Overrides:
        merge in class java.util.HashMap<K,​V>