Package org.openstreetmap.josm.data.osm
Class TagMap
- java.lang.Object
-
- java.util.AbstractMap<java.lang.String,java.lang.String>
-
- org.openstreetmap.josm.data.osm.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 asAbstractPrimitive.keys. It offers good performance for few keys. It uses copy on write, so there cannot be aConcurrentModificationExceptionwhile iterating through it.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTagMap.TagEntryIteratorAn iterator that iterates over the tags in this map.private static classTagMap.TagEntrySetThis is the entry set of this map.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[]EMPTY_TAGSWe use this array every time we want to represent an empty map.(package private) static longserialVersionUIDprivate java.lang.String[]tagsThe 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 voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>>entrySet()java.lang.Stringget(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 intindexOfKey(java.lang.String[] tags, java.lang.Object key)Finds a key in an array that is structured like thetagsarray and returns the position.java.lang.Stringput(java.lang.String key, java.lang.String value)java.lang.Stringremove(java.lang.Object key)intsize()java.lang.StringtoString()-
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, isEmpty, keySet, putAll, values
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
- Specified by:
entrySetin interfacejava.util.Map<java.lang.String,java.lang.String>- Specified by:
entrySetin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
containsKeyin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
get
public java.lang.String get(java.lang.Object key)
- Specified by:
getin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
getin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
containsValuein classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
put
public java.lang.String put(java.lang.String key, java.lang.String value)
- Specified by:
putin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
putin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
remove
public java.lang.String remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
removein classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
clearin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
sizein classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
getTags
public java.util.List<Tag> getTags()
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 thetagsarray 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:
toStringin classjava.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.
-
-