Class TagMap

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Map<java.lang.String,​java.lang.String>

    public class TagMap
    extends java.util.AbstractMap<java.lang.String,​java.lang.String>
    implements java.io.Serializable
    This class provides a read/write map that uses the same format as AbstractPrimitive.keys. It offers good performance for few keys. It uses copy on write, so there cannot be a ConcurrentModificationException while iterating through it.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  TagMap.TagEntryIterator
      An iterator that iterates over the tags in this map.
      private static class  TagMap.TagEntrySet
      This is the entry set of this map.
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String[] EMPTY_TAGS
      We use this array every time we want to represent an empty map.
      (package private) static long serialVersionUID  
      private java.lang.String[] tags
      The tags field.
    • Constructor Summary

      Constructors 
      Constructor Description
      TagMap()
      Creates a new, empty tag map.
      TagMap​(java.lang.Iterable<Tag> tags)
      Creates a new map using the given list of tags.
      TagMap​(java.lang.String... tags)
      Creates a new read only tag map using a key/value/key/value/...
      TagMap​(java.util.Map<java.lang.String,​java.lang.String> tags)
      Create a new tag map and load it from the other map.
      TagMap​(TagMap tagMap)
      Copy constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.String>> entrySet()  
      java.lang.String get​(java.lang.Object key)  
      java.util.List<Tag> getTags()
      Gets a list of all tags contained in this map.
      (package private) java.lang.String[] getTagsArray()
      Gets the backing tags array.
      private static int indexOfKey​(java.lang.String[] tags, java.lang.Object key)
      Finds a key in an array that is structured like the tags array and returns the position.
      java.lang.String put​(java.lang.String key, java.lang.String value)  
      java.lang.String remove​(java.lang.Object key)  
      int size()  
      java.lang.String toString()  
      • Methods inherited from class java.util.AbstractMap

        clone, equals, hashCode, isEmpty, keySet, putAll, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • EMPTY_TAGS

        private static final java.lang.String[] EMPTY_TAGS
        We use this array every time we want to represent an empty map. This saves us the burden of checking for null every time but saves some object allocations.
      • tags

        private volatile java.lang.String[] tags
        The tags field. This field is guarded using RCU.
    • Constructor Detail

      • TagMap

        public TagMap()
        Creates a new, empty tag map.
      • TagMap

        public TagMap​(java.util.Map<java.lang.String,​java.lang.String> tags)
        Create a new tag map and load it from the other map.
        Parameters:
        tags - The map to load from.
        Since:
        10604
      • TagMap

        public TagMap​(TagMap tagMap)
        Copy constructor.
        Parameters:
        tagMap - The map to copy from.
        Since:
        10604
      • TagMap

        public TagMap​(java.lang.String... tags)
        Creates a new read only tag map using a key/value/key/value/... array.

        The array that is passed as parameter may not be modified after passing it to this map.

        Parameters:
        tags - The tags array. It is not modified by this map.
      • TagMap

        public TagMap​(java.lang.Iterable<Tag> tags)
        Creates a new map using the given list of tags. For duplicate keys the last value found is used.
        Parameters:
        tags - The tags
        Since:
        10736
    • Method Detail

      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,​java.lang.String>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,​java.lang.String>
        Specified by:
        entrySet in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        containsKey in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • get

        public java.lang.String get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        get in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        containsValue in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • put

        public java.lang.String put​(java.lang.String key,
                                    java.lang.String value)
        Specified by:
        put in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        put in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • remove

        public java.lang.String remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        remove in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        clear in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,​java.lang.String>
        Overrides:
        size in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • getTags

        public java.util.List<TaggetTags()
        Gets a list of all tags contained in this map.
        Returns:
        The list of tags in the order they were added.
        Since:
        10604
      • indexOfKey

        private static int indexOfKey​(java.lang.String[] tags,
                                      java.lang.Object key)
        Finds a key in an array that is structured like the tags array and returns the position.

        We allow the parameter to be passed to allow for better synchronization.

        Parameters:
        tags - The tags array to search through.
        key - The key to search.
        Returns:
        The index of the key (a multiple of two) or -1 if it was not found.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.util.AbstractMap<java.lang.String,​java.lang.String>
      • getTagsArray

        java.lang.String[] getTagsArray()
        Gets the backing tags array. Do not modify this array.
        Returns:
        The tags array.