Class UnmodifiableArrayMap<K,V>

java.lang.Object
org.olap4j.impl.ArrayMap<K,V>
org.olap4j.impl.UnmodifiableArrayMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class UnmodifiableArrayMap<K,V> extends ArrayMap<K,V>
Unmodifiable map backed by an array.

Has the same benefits and limitations as ArrayMap. It is extremely space-efficient but has poor performance for insert and lookup.

This structure is ideal if you are creating many maps with few elements. The of(java.util.Map) method will use Collections.emptyMap() and Collections.singletonMap(Object, Object) if possible, and these are even more space-efficient for maps of size 0 and 1.

Since:
Jan 16, 2010
Author:
jhyde
  • Constructor Details

    • UnmodifiableArrayMap

      public UnmodifiableArrayMap(Map<K,V> map)
      Creates an UnmodifiableArrayMap.
      Parameters:
      map - Contents of map, copied on creation
  • Method Details

    • put

      public V put(K key, V value)
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class ArrayMap<K,V>
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class ArrayMap<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
      Overrides:
      putAll in class ArrayMap<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class ArrayMap<K,V>
    • of

      public static <K, V> Map<K,V> of(K key, V value, Object... keyValues)
      Returns an unmodifiable array map with given contents.
      Type Parameters:
      K - Key type
      V - Value type
      Parameters:
      key - First key
      value - First value
      keyValues - Second and sequent key/value pairs
      Returns:
      Map with given contents
    • of

      public static <K, V> Map<K,V> of(Map<K,V> map)
      Creates an unmodifable map as a shallow copy of a map.

      Future changes to the map will not be reflected in the contents of the map.

      Type Parameters:
      K - Key type
      V - Value type
      Returns:
      Unmodifiable map with same contents that the map had at call time