Class ImmutableAbstractMap<K,​V>

    • Field Detail

      • copyOrWrap

        protected final Immutable copyOrWrap
        COPY stores a safe, internal copy of the collection; WRAP stores a pointer to the original collection.
    • Constructor Detail

      • ImmutableAbstractMap

        protected ImmutableAbstractMap​(Map<K,​V> map,
                                       Immutable copyOrWrap)
        Construct an abstract immutable map. Make sure that the argument is a safe copy of the map of the right type! Copying does not take place in the Abstract class!
        Parameters:
        map - Map<K,V>; a safe copy of the map to use for the immutable map
        copyOrWrap - Immutable; indicate whether the immutable is a copy or a wrap
    • Method Detail

      • getUnderlyingMap

        protected Map<K,​V> getUnderlyingMap()
        Return the raw underlying map.
        Returns:
        Map<K, V>; the raw underlying map
      • size

        public final int size()
        Returns the number of elements in this immutable collection. If this immutable collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        size in interface ImmutableMap<K,​V>
        Returns:
        the number of elements in this immutable collection
      • isEmpty

        public final boolean isEmpty()
        Returns true if this immutable collection contains no elements.
        Specified by:
        isEmpty in interface ImmutableMap<K,​V>
        Returns:
        true if this immutable collection contains no elements
      • containsKey

        public final boolean containsKey​(Object key)
        Returns true if this map contains a mapping for the specified key. More formally, returns true if and only if this map contains a mapping for a key k such that (key==null ? k==null : key.equals(k)). (There can be at most one such mapping.)
        Specified by:
        containsKey in interface ImmutableMap<K,​V>
        Parameters:
        key - Object; key whose presence in this map is to be tested
        Returns:
        true if this map contains a mapping for the specified key
      • containsValue

        public final boolean containsValue​(Object value)
        Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations of the Map interface.
        Specified by:
        containsValue in interface ImmutableMap<K,​V>
        Parameters:
        value - Object; value whose presence in this map is to be tested
        Returns:
        true if this map maps one or more keys to the specified value
      • get

        public final V get​(Object key)
        Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

        More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

        If this map permits null values, then a return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

        Specified by:
        get in interface ImmutableMap<K,​V>
        Parameters:
        key - Object; the key whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this map contains no mapping for the key
      • isWrap

        public final boolean isWrap()
        Return whether the internal storage is a wrapped pointer to the original map. If true, this means that anyone holding a pointer to this data structure can still change it. The users of the ImmutableMap itself can, however, not make any changes.
        Specified by:
        isWrap in interface ImmutableMap<K,​V>
        Returns:
        boolean; whether the internal storage is a wrapped pointer to the original map
      • hashCode

        public int hashCode()
        Force to redefine hashCode for the implementations of immutable collection classes.
        Specified by:
        hashCode in interface ImmutableMap<K,​V>
        Overrides:
        hashCode in class Object
        Returns:
        the calculated hashCode
      • equals

        public boolean equals​(Object obj)
        Force to redefine equals for the implementations of immutable collection classes.
        Specified by:
        equals in interface ImmutableMap<K,​V>
        Overrides:
        equals in class Object
        Parameters:
        obj - Object; the object to compare this collection with
        Returns:
        whether the objects are equal