Class AbstractMemoryEfficientMutableMap<K,​V>

    • Constructor Detail

      • AbstractMemoryEfficientMutableMap

        AbstractMemoryEfficientMutableMap()
    • Method Detail

      • put

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

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

        public void putAll​(java.util.Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface FixedSizeMap<K,​V>
        Specified by:
        putAll in interface java.util.Map<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface FixedSizeMap<K,​V>
        Specified by:
        clear in interface java.util.Map<K,​V>
      • removeKey

        public V removeKey​(K key)
        Description copied from interface: MutableMapIterable
        Remove an entry from the map at the specified key.
        Specified by:
        removeKey in interface FixedSizeMap<K,​V>
        Specified by:
        removeKey in interface MutableMapIterable<K,​V>
        Returns:
        The value removed from entry at key, or null if not found.
        See Also:
        Map.remove(Object)
      • collectKeysAndValues

        public <E> MutableMap<K,​V> collectKeysAndValues​(java.lang.Iterable<E> iterable,
                                                              Function<? super E,​? extends K> keyFunction,
                                                              Function<? super E,​? extends V> valueFunction)
        Description copied from interface: MutableMap
        Adds all the entries derived from iterable to this. The key and value for each entry is determined by applying the keyFunction and valueFunction to each item in collection. Any entry in map that has the same key as an entry in this will have its value replaced by that in map.
        Specified by:
        collectKeysAndValues in interface MutableMap<K,​V>
      • withAllKeyValues

        public MutableMap<K,​V> withAllKeyValues​(java.lang.Iterable<? extends Pair<? extends K,​? extends V>> keyValues)
        Description copied from interface: MutableMapIterable
        This method allows mutable, fixed size, and immutable maps the ability to add elements to their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original plus all the additional keys and values. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
         map = map.withAllKeyValues(FastList.newListWith(PairImpl.of("new key", "new value")));
         
        In the case of FixedSizeMap, a new instance will be returned by withAllKeyValues, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling put on themselves.
        Specified by:
        withAllKeyValues in interface MutableMap<K,​V>
        Specified by:
        withAllKeyValues in interface MutableMapIterable<K,​V>
        Overrides:
        withAllKeyValues in class AbstractMutableMap<K,​V>
        See Also:
        Map.put(Object, Object)
      • withoutAllKeys

        public MutableMap<K,​V> withoutAllKeys​(java.lang.Iterable<? extends K> keys)
        Description copied from interface: MutableMapIterable
        This method allows mutable, fixed size, and immutable maps the ability to remove elements from their existing elements. In order to support fixed size maps, a new instance of a map would have to be returned including the keys and values of the original minus all the keys and values to be removed. In the case of mutable maps, the original map is modified and then returned. In order to use this method properly with mutable and fixed size maps the following approach must be taken:
         map = map.withoutAllKeys(FastList.newListWith("key1", "key2"));
         
        In the case of FixedSizeMap, a new instance will be returned by withoutAllKeys, and any variables that previously referenced the original map will need to be redirected to reference the new instance. In the case of a FastMap or UnifiedMap, you will be replacing the reference to map with map, since FastMap and UnifiedMap will both return "this" after calling remove on themselves.
        Specified by:
        withoutAllKeys in interface MutableMap<K,​V>
        Specified by:
        withoutAllKeys in interface MutableMapIterable<K,​V>
        Overrides:
        withoutAllKeys in class AbstractMutableMap<K,​V>
        See Also:
        Map.remove(Object)
      • collect

        public abstract <K2,​V2> FixedSizeMap<K2,​V2> collect​(Function2<? super K,​? super V,​Pair<K2,​V2>> function)
        Description copied from interface: MapIterable
        For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.
         MapIterable<String, String> collected =
             peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));
         
        Specified by:
        collect in interface MapIterable<K,​V>
        Specified by:
        collect in interface MutableMap<K,​V>
        Specified by:
        collect in interface MutableMapIterable<K,​V>
        Specified by:
        collect in interface UnsortedMapIterable<K,​V>
        Overrides:
        collect in class AbstractMutableMapIterable<K,​V>