Package org.openstreetmap.josm.data.osm
Class TagMap
- java.lang.Object
-
- java.util.AbstractMap<String,String>
-
- org.openstreetmap.josm.data.osm.TagMap
-
- All Implemented Interfaces:
Serializable
,Map<String,String>
public class TagMap extends AbstractMap<String,String> implements 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.-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description private static String[]
EMPTY_TAGS
We use this array every time we want to represent an empty map.(package private) static long
serialVersionUID
private String[]
tags
The tags field.
-
Constructor Summary
Constructors Constructor Description TagMap()
Creates a new, empty tag map.TagMap(Iterable<Tag> tags)
Creates a new map using the given list of tags.TagMap(String... tags)
Creates a new read only tag map using a key/value/key/value/...TagMap(Map<String,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(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<String,String>>
entrySet()
String
get(Object key)
List<Tag>
getTags()
Gets a list of all tags contained in this map.(package private) String[]
getTagsArray()
Gets the backing tags array.private static int
indexOfKey(String[] tags, Object key)
Finds a key in an array that is structured like thetags
array and returns the position.String
put(String key, String value)
String
remove(Object key)
int
size()
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
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
EMPTY_TAGS
private static final 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.
-
-
Constructor Detail
-
TagMap
public TagMap()
Creates a new, empty tag map.
-
TagMap
public TagMap(Map<String,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(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
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<String,String>
- Overrides:
containsKey
in classAbstractMap<String,String>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<String,String>
- Overrides:
containsValue
in classAbstractMap<String,String>
-
clear
public void clear()
-
size
public int size()
-
getTags
public 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(String[] tags, 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.
-
getTagsArray
String[] getTagsArray()
Gets the backing tags array. Do not modify this array.- Returns:
- The tags array.
-
-