public class TagCollection extends Object implements Iterable<Tag>
OsmPrimitives.
A TagCollection can be created:
OsmPrimitive with from(Tagged)OsmPrimitives with unionOfAllPrimitives(Collection)DataSet with unionOfAllPrimitives(DataSet)commonToAllPrimitives(Collection)size(), hasTagsFor(String), etc.
Basic set operations allow to create the union, the intersection and the difference
of tag collections, see union(TagCollection), intersect(TagCollection),
and minus(TagCollection).| Constructor and Description |
|---|
TagCollection()
Creates an empty tag collection
|
TagCollection(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(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(Collection<? extends Tagged> primitives)
Applies this tag collection to a collection of
OsmPrimitives. |
void |
applyTo(Tagged primitive)
Applies this tag collection to an
OsmPrimitive. |
List<Tag> |
asList()
Replies the tags of this tag collection as list.
|
Set<Tag> |
asSet()
Replies the tags of this tag collection as set
|
static TagCollection |
commonToAllPrimitives(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(Collection<Tag> tags)
Replies true if this tag collection contains all tags in
tags. |
boolean |
containsAllKeys(Collection<String> keys)
Replies true if this tag collection at least one tag for every key in
keys. |
boolean |
containsKey(String key)
Replies true if this tag collection contains at least one tag with key
key. |
TagCollection |
emptyTagsForKeysMissingIn(TagCollection other) |
static TagCollection |
from(Map<String,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. |
String |
getJoinedValues(String key)
Replies the concatenation of all tag values (concatenated by a semicolon)
|
Set<String> |
getKeys()
Replies the set of keys of this tag collection.
|
Set<String> |
getKeysWithMultipleValues()
Replies the set of keys which have at least 2 matching tags.
|
int |
getNumTagsFor(String key)
Replies the number of tags with key
key |
TagCollection |
getTagsFor(Collection<String> keys)
Replies a tag collection with all tags whose key is equal to one of the keys in
keys. |
TagCollection |
getTagsFor(String key)
Replies a tag collection with the tags for a given key.
|
Set<String> |
getValues()
Replies the set of values in this tag collection
|
Set<String> |
getValues(String key)
Replies the set of values for a given key.
|
boolean |
hasEmptyValue(String key)
Replies true if there is a tag with an empty value for
key. |
boolean |
hasTagsFor(String key)
Replies true if there is at least one tag for the given key.
|
boolean |
hasUniqueEmptyValue(String key)
Replies true if there is exactly one tag for
key and if
the value for this tag is empty. |
boolean |
hasUniqueNonEmptyValue(String key)
Replies true if there is exactly one tag for
key and
if the value of this tag is not empty. |
boolean |
hasValuesFor(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. exactly one value.
|
boolean |
isEmpty()
Replies true if this tag collection is empty
|
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(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(Collection<String> keys)
Removes all tags whose key is in the collection
keys. |
void |
removeByKey(String key)
Removes all tags whose keys are equal to
key. |
void |
replaceTagsOf(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(String key,
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
|
String |
toString() |
TagCollection |
union(TagCollection other)
Replies the union of this tag collection and another tag collection
|
static TagCollection |
unionOfAllPrimitives(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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic TagCollection()
public TagCollection(TagCollection other)
other. Creats an empty
tag collection if other is null.other - the other collectionpublic TagCollection(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(Map<String,String> tags)
tags is null.tags - the key/value-pairspublic static TagCollection unionOfAllPrimitives(Collection<? extends Tagged> primitives)
primitives is null.primitives - the primitivespublic static TagCollection commonToAllPrimitives(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 void add(Tag tag)
tag is null, nothing is added.tag - the tag to addpublic void add(Collection<Tag> tags)
tags is null, nothing
is added. null values in the collection are ignored.tags - the collection of tagspublic 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(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(String key)
key. Does nothing if key
is null.key - the key to be removedpublic void removeByKey(Collection<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(String key)
key.key - the key to look upkey; false, otherwisepublic boolean containsAll(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(Collection<String> keys)
keys.
Replies false, if keys is null. null values in keys are ignored.keys - the keys to lookupkeys.public int getNumTagsFor(String key)
keykey - the key to look upkey. 0, if key is null.public boolean hasTagsFor(String key)
key - the key to look uppublic boolean hasValuesFor(String key)
key - the keypublic boolean hasUniqueNonEmptyValue(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(String key)
key.
Replies false, if key is null.key - the keykeypublic boolean hasUniqueEmptyValue(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(String key)
key - the key to look uppublic TagCollection getTagsFor(Collection<String> keys)
keys. Replies an empty collection if keys is null.keys - the keys to look upkeyspublic Set<Tag> asSet()
public List<Tag> asList()
public Iterator<Tag> iterator()
public Set<String> getKeys()
public Set<String> getKeysWithMultipleValues()
public void setUniqueForKey(Tag tag)
tag - the tag to setpublic void setUniqueForKey(String key, String value)
key - the keyvalue - the valuepublic Set<String> getValues()
public Set<String> getValues(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 IllegalStateException
OsmPrimitive. Does nothing if
primitive is nullprimitive - the primitiveIllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void applyTo(Collection<? extends Tagged> primitives) throws IllegalStateException
OsmPrimitives. Does nothing if
primitives is nullprimitives - the collection of primitivesIllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void replaceTagsOf(Tagged primitive) throws IllegalStateException
OsmPrimitive by the tags in this collection . Does nothing if
primitive is nullprimitive - the primitiveIllegalStateException - thrown if this tag collection can't be applied
because there are keys with multiple valuespublic void replaceTagsOf(Collection<? extends Tagged> primitives) throws IllegalStateException
OsmPrimitives by the tags in this collection.
Does nothing if primitives is nullprimitives - the collection of primitivesIllegalStateException - 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 String getJoinedValues(String key)