Class JdkMapAdapterStringMap

  • All Implemented Interfaces:
    java.io.Serializable, ReadOnlyStringMap, StringMap

    public class JdkMapAdapterStringMap
    extends java.lang.Object
    implements StringMap
    Provides a read-only StringMap view of a Map<String, String>.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String FROZEN  
      private boolean immutable  
      private java.util.Map<java.lang.String,​java.lang.String> map  
      private static java.util.Comparator<? super java.lang.String> NULL_FIRST_COMPARATOR  
      private static TriConsumer<java.lang.String,​java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> PUT_ALL  
      private static long serialVersionUID  
      private java.lang.String[] sortedKeys  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void assertNotFrozen()  
      void clear()
      Removes all key-value pairs from this collection.
      boolean containsKey​(java.lang.String key)
      Returns true if this data structure contains the specified key, false otherwise.
      boolean equals​(java.lang.Object object)
      Indicates whether some other object is "equal to" this one.
      <V> void forEach​(BiConsumer<java.lang.String,​? super V> action)
      Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.
      <V,​S>
      void
      forEach​(TriConsumer<java.lang.String,​? super V,​S> action, S state)
      Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.
      void freeze()
      Makes this collection immutable.
      private java.lang.String[] getSortedKeys()  
      <V> V getValue​(java.lang.String key)
      Returns the value for the specified key, or null if the specified key does not exist in this collection.
      int hashCode()
      Returns a hash code value for the object.
      boolean isEmpty()
      Returns true if this collection is empty (size is zero), false otherwise.
      boolean isFrozen()
      Returns true if this object has been frozen, false otherwise.
      void putAll​(ReadOnlyStringMap source)
      Copies all key-value pairs from the specified ReadOnlyStringMap into this StringMap.
      void putValue​(java.lang.String key, java.lang.Object value)
      Puts the specified key-value pair into the collection.
      void remove​(java.lang.String key)
      Removes the key-value pair for the specified key from this data structure.
      int size()
      Returns the number of key-value pairs in this collection.
      java.util.Map<java.lang.String,​java.lang.String> toMap()
      Returns a non-null mutable Map<String, String> containing a snapshot of this data structure.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NULL_FIRST_COMPARATOR

        private static final java.util.Comparator<? super java.lang.String> NULL_FIRST_COMPARATOR
      • map

        private final java.util.Map<java.lang.String,​java.lang.String> map
      • immutable

        private boolean immutable
      • sortedKeys

        private transient java.lang.String[] sortedKeys
      • PUT_ALL

        private static TriConsumer<java.lang.String,​java.lang.String,​java.util.Map<java.lang.String,​java.lang.String>> PUT_ALL
    • Constructor Detail

      • JdkMapAdapterStringMap

        public JdkMapAdapterStringMap()
      • JdkMapAdapterStringMap

        public JdkMapAdapterStringMap​(java.util.Map<java.lang.String,​java.lang.String> map)
    • Method Detail

      • toMap

        public java.util.Map<java.lang.String,​java.lang.String> toMap()
        Description copied from interface: ReadOnlyStringMap
        Returns a non-null mutable Map<String, String> containing a snapshot of this data structure.
        Specified by:
        toMap in interface ReadOnlyStringMap
        Returns:
        a mutable copy of this data structure in Map<String, String> form.
      • assertNotFrozen

        private void assertNotFrozen()
      • containsKey

        public boolean containsKey​(java.lang.String key)
        Description copied from interface: ReadOnlyStringMap
        Returns true if this data structure contains the specified key, false otherwise.
        Specified by:
        containsKey in interface ReadOnlyStringMap
        Parameters:
        key - the key whose presence to check. May be null.
        Returns:
        true if this data structure contains the specified key, false otherwise.
      • forEach

        public <V> void forEach​(BiConsumer<java.lang.String,​? super V> action)
        Description copied from interface: ReadOnlyStringMap
        Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.

        Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the BiConsumer's BiConsumer.accept(Object, Object) accept} method may cause a ConcurrentModificationException to be thrown.

        Specified by:
        forEach in interface ReadOnlyStringMap
        Type Parameters:
        V - type of the value.
        Parameters:
        action - The action to be performed for each key-value pair in this collection.
      • forEach

        public <V,​S> void forEach​(TriConsumer<java.lang.String,​? super V,​S> action,
                                        S state)
        Description copied from interface: ReadOnlyStringMap
        Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.

        The third parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.

        Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the TriConsumer's accept method may cause a ConcurrentModificationException to be thrown.

        Specified by:
        forEach in interface ReadOnlyStringMap
        Type Parameters:
        V - type of the value.
        S - type of the third parameter.
        Parameters:
        action - The action to be performed for each key-value pair in this collection.
        state - the object to be passed as the third parameter to each invocation on the specified triconsumer.
      • getSortedKeys

        private java.lang.String[] getSortedKeys()
      • getValue

        public <V> V getValue​(java.lang.String key)
        Description copied from interface: ReadOnlyStringMap
        Returns the value for the specified key, or null if the specified key does not exist in this collection.
        Specified by:
        getValue in interface ReadOnlyStringMap
        Parameters:
        key - the key whose value to return.
        Returns:
        the value for the specified key or null.
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: ReadOnlyStringMap
        Returns true if this collection is empty (size is zero), false otherwise.
        Specified by:
        isEmpty in interface ReadOnlyStringMap
        Returns:
        true if this collection is empty (size is zero).
      • size

        public int size()
        Description copied from interface: ReadOnlyStringMap
        Returns the number of key-value pairs in this collection.
        Specified by:
        size in interface ReadOnlyStringMap
        Returns:
        the number of key-value pairs in this collection.
      • clear

        public void clear()
        Description copied from interface: StringMap
        Removes all key-value pairs from this collection.
        Specified by:
        clear in interface StringMap
      • freeze

        public void freeze()
        Description copied from interface: StringMap
        Makes this collection immutable. Attempts to modify the collection after the freeze() method was called will result in an UnsupportedOperationException being thrown.
        Specified by:
        freeze in interface StringMap
      • isFrozen

        public boolean isFrozen()
        Description copied from interface: StringMap
        Returns true if this object has been frozen, false otherwise.
        Specified by:
        isFrozen in interface StringMap
        Returns:
        true if this object has been frozen, false otherwise
      • putAll

        public void putAll​(ReadOnlyStringMap source)
        Description copied from interface: StringMap
        Copies all key-value pairs from the specified ReadOnlyStringMap into this StringMap.
        Specified by:
        putAll in interface StringMap
        Parameters:
        source - the ReadOnlyStringMap to copy key-value pairs from
      • putValue

        public void putValue​(java.lang.String key,
                             java.lang.Object value)
        Description copied from interface: StringMap
        Puts the specified key-value pair into the collection.
        Specified by:
        putValue in interface StringMap
        Parameters:
        key - the key to add or remove. Keys may be null.
        value - the value to add. Values may be null.
      • remove

        public void remove​(java.lang.String key)
        Description copied from interface: StringMap
        Removes the key-value pair for the specified key from this data structure.
        Specified by:
        remove in interface StringMap
        Parameters:
        key - the key to remove. May be null.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)
        Description copied from interface: StringMap
        Indicates whether some other object is "equal to" this one.
        Specified by:
        equals in interface StringMap
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
        See Also:
        StringMap.hashCode()
      • hashCode

        public int hashCode()
        Description copied from interface: StringMap
        Returns a hash code value for the object.
        Specified by:
        hashCode in interface StringMap
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code value for this object.