public class TagCollection extends java.lang.Object implements java.lang.Iterable<Tag>
OsmPrimitives.
A TagCollection can be created:
OsmPrimitive with from(org.openstreetmap.josm.data.osm.Tagged)OsmPrimitives with unionOfAllPrimitives(java.util.Collection)DataSet with unionOfAllPrimitives(org.openstreetmap.josm.data.osm.DataSet)commonToAllPrimitives(java.util.Collection)size(), hasTagsFor(String), etc.
Basic set operations allow to create the union, the intersection and the difference
of tag collections, see union(org.openstreetmap.josm.data.osm.TagCollection), intersect(org.openstreetmap.josm.data.osm.TagCollection),
and minus(org.openstreetmap.josm.data.osm.TagCollection).| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
SPLIT_VALUES_PATTERN |
private java.util.Set<Tag> |
tags |
| Constructor and Description |
|---|
TagCollection()
Creates an empty tag collection
|
TagCollection(java.util.Collection<Tag> tags)
Creates a tag collection from
tags. |
TagCollection(TagCollection other)
Creates a clone of the tag collection
other. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.util.Collection<Tag> tags)
Adds a collection of tags to the tag collection.
|
void |
add(Tag tag)
Adds a tag to the tag collection.
|
void |
add(TagCollection tags)
Adds the tags of another tag collection to this collection.
|
void |
applyTo(java.util.Collection<? extends Tagged> primitives)
Applies this tag collection to a collection of
OsmPrimitives. |
void |
applyTo(Tagged primitive)
Applies this tag collection to an
OsmPrimitive. |
java.util.List<Tag> |
asList()
Replies the tags of this tag collection as list.
|
java.util.Set<Tag> |
asSet()
Replies the tags of this tag collection as set
|
static TagCollection |
commonToAllPrimitives(java.util.Collection<? extends Tagged> primitives)
Replies a tag collection with the tags which are common to all primitives in in
primitives. |
boolean |
contains(Tag tag)
Replies true if the this tag collection contains
tag. |
boolean |
containsAll(java.util.Collection<Tag> tags)
Replies true if this tag collection contains all tags in
tags. |
boolean |
containsAllKeys(java.util.Collection<java.lang.String> keys)
Replies true if this tag collection at least one tag for every key in
keys. |
boolean |
containsKey(java.lang.String key)
Replies true if this tag collection contains at least one tag with key
key. |
TagCollection |
emptyTagsForKeysMissingIn(TagCollection other) |
static TagCollection |
from(java.util.Map<java.lang.String,java.lang.String> tags)
Creates a tag collection from a map of key/value-pairs.
|
static TagCollection |
from(Tagged primitive)
Creates a tag collection from the tags managed by a specific
OsmPrimitive. |
java.lang.String |
getJoinedValues(java.lang.String key)
Replies the concatenation of all tag values (concatenated by a semicolon)
|
java.util.Set<java.lang.String> |
getKeys()
Replies the set of keys of this tag collection.
|
java.util.Set<java.lang.String> |
getKeysWithMultipleValues()
Replies the set of keys which have at least 2 matching tags.
|
int |
getNumTagsFor(java.lang.String key)
Replies the number of tags with key
key |
java.lang.String |
getSummedValues(java.lang.String key)
Replies the sum of all numeric tag values.
|
TagCollection |
getTagsFor(java.util.Collection<java.lang.String> keys)
Replies a tag collection with all tags whose key is equal to one of the keys in
keys. |
TagCollection |
getTagsFor(java.lang.String key)
Replies a tag collection with the tags for a given key.
|
java.util.Set<java.lang.String> |
getValues()
Replies the set of values in this tag collection
|
java.util.Set<java.lang.String> |
getValues(java.lang.String key)
Replies the set of values for a given key.
|
boolean |
hasEmptyValue(java.lang.String key)
Replies true if there is a tag with an empty value for
key. |
boolean |
hasTagsFor(java.lang.String key)
Replies true if there is at least one tag for the given key.
|
boolean |
hasUniqueEmptyValue(java.lang.String key)
Replies true if there is exactly one tag for
key and if
the value for this tag is empty. |
boolean |
hasUniqueNonEmptyValue(java.lang.String key)
Replies true if there is exactly one tag for
key and
if the value of this tag is not empty. |
boolean |
hasValuesFor(java.lang.String key)
Replies true it there is at least one tag with a non empty value for key.
|
TagCollection |
intersect(TagCollection other)
Builds the intersection of this tag collection and another tag collection
|
boolean |
isApplicableToPrimitive()
Replies true if for every key there is one tag only, i.e.
|
boolean |
isEmpty()
Replies true if this tag collection is empty
|
java.util.Iterator<Tag> |
iterator()
Replies an iterator to iterate over the tags in this collection
|
TagCollection |
minus(TagCollection other)
Replies the difference of this tag collection and another tag collection
|
void |
remove(java.util.Collection<Tag> tags)
Removes a collection of tags from the tag collection.
|
void |
remove(Tag tag)
Removes a specific tag from the tag collection.
|
void |
remove(TagCollection tags)
Removes all tags in the tag collection
tags from the current tag collection. |
void |
removeByKey(java.util.Collection<java.lang.String> keys)
Removes all tags whose key is in the collection
keys. |
void |
removeByKey(java.lang.String key)
Removes all tags whose keys are equal to
key. |
void |
replaceTagsOf(java.util.Collection<? extends Tagged> primitives)
Replaces the tags of a collection of
OsmPrimitives by the tags in this collection. |
void |
replaceTagsOf(Tagged primitive)
Replaces the tags of an
OsmPrimitive by the tags in this collection . |
void |
setUniqueForKey(java.lang.String key,
java.lang.String value)
Sets a unique tag for the key of this tag.
|
void |
setUniqueForKey(Tag tag)
Sets a unique tag for the key of this tag.
|
int |
size()
Replies the number of tags in this tag collection
|
java.lang.String |
toString() |
TagCollection |
union(TagCollection other)
Replies the union of this tag collection and another tag collection
|
static TagCollection |
unionOfAllPrimitives(java.util.Collection<? extends Tagged> primitives)
Creates a tag collection from the union of the tags managed by
a collection of primitives.
|
static TagCollection |
unionOfAllPrimitives(DataSet ds)
Replies a tag collection with the union of the tags which are common to all primitives in
the dataset
ds. |
private static final java.util.regex.Pattern SPLIT_VALUES_PATTERN
public TagCollection()
public TagCollection(TagCollection other)
other. Creats an empty
tag collection if other is null.other - the other collectionpublic TagCollection(java.util.Collection<Tag> tags)
tags.tags - the collection of tagspublic static TagCollection from(Tagged primitive)
OsmPrimitive. If primitive is null, replies
an empty tag collection.primitive - the primitiveOsmPrimitivepublic static TagCollection from(java.util.Map<java.lang.String,java.lang.String> tags)
tags is null.tags - the key/value-pairspublic static TagCollection unionOfAllPrimitives(java.util.Collection<? extends Tagged> primitives)
primitives is null.primitives - the primitivespublic static TagCollection commonToAllPrimitives(java.util.Collection<? extends Tagged> primitives)
primitives. Replies an empty tag collection of primitives
is null.primitives - the primitivespublic static TagCollection unionOfAllPrimitives(DataSet ds)
ds. Returns an empty tag collection of ds is null.ds - the datasetdspublic int size()
public boolean isEmpty()
public final void add(Tag tag)
tag is null, nothing is added.tag - the tag to addpublic final void add(java.util.Collection<Tag> tags)
tags is null, nothing
is added. null values in the collection are ignored.tags - the collection of tagspublic final void add(TagCollection tags)
tags is null.tags - the other tag collectionpublic void remove(Tag tag)
tag is
null.tag - the tag to be removedpublic void remove(java.util.Collection<Tag> tags)
tags is
null.tags - the tags to be removedpublic void remove(TagCollection tags)
tags from the current tag collection.
Does nothing if tags is null.tags - the tag collection to be removed.public void removeByKey(java.lang.String key)
key. Does nothing if key
is null.key - the key to be removedpublic void removeByKey(java.util.Collection<java.lang.String> keys)
keys. Does nothing if
keys is null.keys - the collection of keys to be removedpublic boolean contains(Tag tag)
tag.tag - the tag to look uptag; false, otherwisepublic boolean containsKey(java.lang.String key)
key.key - the key to look upkey; false, otherwisepublic boolean containsAll(java.util.Collection<Tag> tags)
tags. Replies
false, if tags is null.tags - the tags to look uptags. Replies
false, if tags is null.public boolean containsAllKeys(java.util.Collection<java.lang.String> keys)
keys.
Replies false, if keys is null. null values in keys are ignored.keys - the keys to lookupkeys.public int getNumTagsFor(java.lang.String key)
keykey - the key to look upkey. 0, if key is null.public boolean hasTagsFor(java.lang.String key)
key - the key to look uppublic boolean hasValuesFor(java.lang.String key)
key - the keypublic boolean hasUniqueNonEmptyValue(java.lang.String key)
key and
if the value of this tag is not empty. Replies false if key is
null.key - the keykey and
if the value of this tag is not emptypublic boolean hasEmptyValue(java.lang.String key)
key.
Replies false, if key is null.key - the keykeypublic boolean hasUniqueEmptyValue(java.lang.String key)
key and if
the value for this tag is empty. Replies false if key is null.key - the keykey and if
the value for this tag is emptypublic TagCollection getTagsFor(java.lang.String key)
key - the key to look uppublic TagCollection getTagsFor(java.util.Collection<java.lang.String> keys)
keys. Replies an empty collection if keys is null.keys - the keys to look upkeyspublic java.util.Set<Tag> asSet()
public java.util.List<Tag> asList()
public java.util.Iterator<Tag> iterator()
iterator in interface java.lang.Iterable<Tag>public java.util.Set<java.lang.String> getKeys()
public java.util.Set<java.lang.String> getKeysWithMultipleValues()
public void setUniqueForKey(Tag tag)
tag - the tag to setpublic void setUniqueForKey(java.lang.String key, java.lang.String value)
key - the keyvalue - the valuepublic java.util.Set<java.lang.String> getValues()
public java.util.Set<java.lang.String> getValues(java.lang.String key)
key - the key to look uppublic boolean isApplicableToPrimitive()
true if for every key there is one tag onlypublic void applyTo(Tagged primitive) throws java.lang.IllegalStateException
OsmPrimitive. Does nothing if
primitive is nullprimitive - the primitivejava.lang.IllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void applyTo(java.util.Collection<? extends Tagged> primitives) throws java.lang.IllegalStateException
OsmPrimitives. Does nothing if
primitives is nullprimitives - the collection of primitivesjava.lang.IllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void replaceTagsOf(Tagged primitive) throws java.lang.IllegalStateException
OsmPrimitive by the tags in this collection . Does nothing if
primitive is nullprimitive - the primitivejava.lang.IllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void replaceTagsOf(java.util.Collection<? extends Tagged> primitives) throws java.lang.IllegalStateException
OsmPrimitives by the tags in this collection.
Does nothing if primitives is nullprimitives - the collection of primitivesjava.lang.IllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic TagCollection intersect(TagCollection other)
other - the other tag collection. If null, replies an empty tag collection.public TagCollection minus(TagCollection other)
other - the other tag collection. May be null.public TagCollection union(TagCollection other)
other - the other tag collection. May be null.public TagCollection emptyTagsForKeysMissingIn(TagCollection other)
public java.lang.String getJoinedValues(java.lang.String key)
key - the key to look uppublic java.lang.String getSummedValues(java.lang.String key)
key - the key to look uppublic java.lang.String toString()
toString in class java.lang.Object