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 aConcurrentModificationException
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.
-
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 thetags
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
-
-
-
-
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:
entrySet
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Specified by:
entrySet
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
containsKey
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
get
public java.lang.String get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
get
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsValue
public boolean containsValue(java.lang.Object value)
- Specified by:
containsValue
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
containsValue
in 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:
put
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
put
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
remove
public java.lang.String remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
remove
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
clear
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
size
in 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 thetags
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 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.
-
-