Class MinimalMap

java.lang.Object
com.aoapps.collections.MinimalMap

public final class MinimalMap extends Object
MinimalMap provides a set of static methods to dynamically choose the most efficient Map implementation. The implementation of Map is changed as needed. MinimalMap is most suited for building map-based data structures that use less heap space than a pure HashMap-based solution.

Insertion order is maintained.

size=0: Collections.emptyMap()
size=1: Collections.singletonMap(java.lang.Object, java.lang.Object)
size=2: LinkedHashMap

Author:
AO Industries, Inc.
  • Method Details

    • emptyMap

      public static <K, V> Map<K,V> emptyMap()
      Gets the empty map representation.
    • put

      public static <K, V> Map<K,V> put(Map<K,V> map, K key, V value)
      Puts a new element in a map, returning the (possibly new) map.
    • remove

      public static <K, V> Map<K,V> remove(Map<K,V> map, K key)
      Removes an element from a map, returning the (possibly new) map.
    • get

      @Deprecated public static <K, V> V get(Map<K,V> map, K key)
      Deprecated.
      Since empty maps are no longer represented by null, invoke Map.get(java.lang.Object) directly now.
      Gets an element from a map.
    • containsKey

      @Deprecated public static <K, V> boolean containsKey(Map<K,V> map, K key)
      Deprecated.
      Since empty maps are no longer represented by null, invoke Map.containsKey(java.lang.Object) directly now.
      Checks if a key is contained in the map.
    • values

      @Deprecated public static <K, V> Collection<V> values(Map<K,V> map)
      Deprecated.
      Since empty maps are no longer represented by null, invoke Map.values() directly now.
      Gets the value collection.
    • valuesCopy

      public static <K, V> Collection<V> valuesCopy(Map<K,V> map)
      Performs a shallow copy of the value collection.
    • copy

      public static <K, V> Map<K,V> copy(Map<K,V> map)
      Performs a shallow copy of a map. The map is assumed to have been created by MinimalMap and to be used through MinimalMap.
    • unmodifiable

      public static <K, V> Map<K,V> unmodifiable(Map<K,V> map)
      Gets an unmodifiable wrapper around this map. May or may not wrap this map itself.