Class UnmodifiableMapBase<K,​V>

  • Type Parameters:
    K - The map key type.
    V - The map value type.
    All Implemented Interfaces:
    Map<K,​V>
    Direct Known Subclasses:
    UnmodifiableMap, UnmodifiableSortedMap

    public abstract class UnmodifiableMapBase<K,​V>
    extends Object
    implements Map<K,​V>
    Base implementation class for immutable maps.
    • Field Detail

      • entries

        protected final transient Map.Entry<K,​V>[] entries
      • size

        protected final transient int size
    • Method Detail

      • orderedBy

        public UnmodifiableSortedMap<K,​V> orderedBy​(Comparator<? super K> comparator)
        Get the map as a sorted map ordered by the specific comparator.
        Parameters:
        comparator - The comparator to make the map sorted for.
        Returns:
        The sorted map.
      • withEntry

        public abstract Map<K,​V> withEntry​(K key,
                                                 V value)
        Get a map with entries from this with the additional entry. The entry will overwrite if the key conflicts.
        Parameters:
        key - The entry key.
        value - The entry value.
        Returns:
        The resulting map.
      • withEntries

        public abstract Map<K,​V> withEntries​(Map<? extends K,​? extends V> map)
        Get a map with entries from this with additional entries from provided map. Entries in the provided map will overwrite if key conflict.
        Parameters:
        map - Map with additional entries.
        Returns:
        The resulting map.
      • size

        public int size()
        Specified by:
        size in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface Map<K,​V>
      • keySet

        public Set<K> keySet()
        Specified by:
        keySet in interface Map<K,​V>
      • put

        public V put​(K k,
                     V v)
        Specified by:
        put in interface Map<K,​V>
      • putAll

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

        public void clear()
        Specified by:
        clear in interface Map<K,​V>
      • makeEntrySet

        protected abstract Set<Map.Entry<K,​V>> makeEntrySet()
      • makeKeySet

        protected abstract Set<K> makeKeySet()
      • entry

        protected static <K,​V> Map.Entry<K,​V> entry​(K key,
                                                                V value)