Class TagCollection

    • Constructor Detail

      • TagCollection

        public TagCollection()
        Creates an empty tag collection.
      • TagCollection

        public TagCollection​(TagCollection other)
        Creates a clone of the tag collection other. Creates an empty tag collection if other is null.
        Parameters:
        other - the other collection
      • TagCollection

        public TagCollection​(Collection<Tag> tags)
        Creates a tag collection from tags.
        Parameters:
        tags - the collection of tags
        Since:
        5724
    • Method Detail

      • from

        public static TagCollection from​(Tagged primitive)
        Creates a tag collection from the tags managed by a specific OsmPrimitive. If primitive is null, replies an empty tag collection.
        Parameters:
        primitive - the primitive
        Returns:
        a tag collection with the tags managed by a specific OsmPrimitive
      • from

        public static TagCollection from​(Map<String,​String> tags)
        Creates a tag collection from a map of key/value-pairs. Replies an empty tag collection if tags is null.
        Parameters:
        tags - the key/value-pairs
        Returns:
        the tag collection
      • unionOfAllPrimitives

        public static TagCollection unionOfAllPrimitives​(Collection<? extends Tagged> primitives)
        Creates a tag collection from the union of the tags managed by a collection of primitives. Replies an empty tag collection, if primitives is null.
        Parameters:
        primitives - the primitives
        Returns:
        a tag collection with the union of the tags managed by a collection of primitives
      • commonToAllPrimitives

        public static TagCollection commonToAllPrimitives​(Collection<? extends Tagged> primitives)
        Replies a tag collection with the tags which are common to all primitives in in primitives. Replies an empty tag collection of primitives is null.
        Parameters:
        primitives - the primitives
        Returns:
        a tag collection with the tags which are common to all primitives
      • unionOfAllPrimitives

        public 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. Returns an empty tag collection of ds is null.
        Parameters:
        ds - the dataset
        Returns:
        a tag collection with the union of the tags which are common to all primitives in the dataset ds
      • size

        public int size()
        Replies the number of tags in this tag collection
        Returns:
        the number of tags in this tag collection
      • isEmpty

        public boolean isEmpty()
        Replies true if this tag collection is empty
        Returns:
        true if this tag collection is empty; false, otherwise
      • add

        public final void add​(Tag tag)
        Adds a tag to the tag collection. If tag is null, nothing is added.
        Parameters:
        tag - the tag to add
      • getTagOccurrence

        public int getTagOccurrence​(Tag tag)
        Gets the number of times this tag was added to the collection.
        Parameters:
        tag - The tag
        Returns:
        The number of times this tag is used in this collection.
        Since:
        14302
      • add

        public final void add​(Collection<Tag> tags)
        Adds a collection of tags to the tag collection. If tags is null, nothing is added. null values in the collection are ignored.
        Parameters:
        tags - the collection of tags
      • add

        public final void add​(TagCollection tags)
        Adds the tags of another tag collection to this collection. Adds nothing, if tags is null.
        Parameters:
        tags - the other tag collection
      • remove

        public void remove​(Tag tag)
        Removes a specific tag from the tag collection. Does nothing if tag is null.
        Parameters:
        tag - the tag to be removed
      • remove

        public void remove​(Collection<Tag> tags)
        Removes a collection of tags from the tag collection. Does nothing if tags is null.
        Parameters:
        tags - the tags to be removed
      • remove

        public void remove​(TagCollection tags)
        Removes all tags in the tag collection tags from the current tag collection. Does nothing if tags is null.
        Parameters:
        tags - the tag collection to be removed.
      • removeByKey

        public void removeByKey​(String key)
        Removes all tags whose keys are equal to key. Does nothing if key is null.
        Parameters:
        key - the key to be removed
      • removeByKey

        public void removeByKey​(Collection<String> keys)
        Removes all tags whose key is in the collection keys. Does nothing if keys is null.
        Parameters:
        keys - the collection of keys to be removed
      • contains

        public boolean contains​(Tag tag)
        Replies true if the this tag collection contains tag.
        Parameters:
        tag - the tag to look up
        Returns:
        true if the this tag collection contains tag; false, otherwise
      • containsAll

        public boolean containsAll​(Collection<Tag> tags)
        Replies true if this tag collection contains all tags in tags. Replies false, if tags is null.
        Parameters:
        tags - the tags to look up
        Returns:
        true if this tag collection contains all tags in tags. Replies false, if tags is null.
      • containsAllKeys

        public boolean containsAllKeys​(Collection<String> keys)
        Replies true if this tag collection at least one tag for every key in keys. Replies false, if keys is null. null values in keys are ignored.
        Parameters:
        keys - the keys to lookup
        Returns:
        true if this tag collection at least one tag for every key in keys.
      • getNumTagsFor

        public int getNumTagsFor​(String key)
        Replies the number of tags with key key
        Parameters:
        key - the key to look up
        Returns:
        the number of tags with key key, including the empty "" value. 0, if key is null.
      • hasTagsFor

        public boolean hasTagsFor​(String key)
        Replies true if there is at least one tag for the given key.
        Parameters:
        key - the key to look up
        Returns:
        true if there is at least one tag for the given key. false, if key is null.
      • hasValuesFor

        public boolean hasValuesFor​(String key)
        Replies true it there is at least one tag with a non empty value for key. Replies false if key is null.
        Parameters:
        key - the key
        Returns:
        true it there is at least one tag with a non empty value for key.
      • hasUniqueNonEmptyValue

        public boolean hasUniqueNonEmptyValue​(String key)
        Replies true if there is exactly one tag for key and if the value of this tag is not empty. Replies false if key is null.
        Parameters:
        key - the key
        Returns:
        true if there is exactly one tag for key and if the value of this tag is not empty
      • hasEmptyValue

        public boolean hasEmptyValue​(String key)
        Replies true if there is a tag with an empty value for key. Replies false, if key is null.
        Parameters:
        key - the key
        Returns:
        true if there is a tag with an empty value for key
      • hasUniqueEmptyValue

        public boolean hasUniqueEmptyValue​(String key)
        Replies true if there is exactly one tag for key and if the value for this tag is empty. Replies false if key is null.
        Parameters:
        key - the key
        Returns:
        true if there is exactly one tag for key and if the value for this tag is empty
      • getTagsFor

        public TagCollection getTagsFor​(String key)
        Replies a tag collection with the tags for a given key. Replies an empty collection if key is null.
        Parameters:
        key - the key to look up
        Returns:
        a tag collection with the tags for a given key. Replies an empty collection if key is null.
      • getTagsFor

        public TagCollection getTagsFor​(Collection<String> keys)
        Replies a tag collection with all tags whose key is equal to one of the keys in keys. Replies an empty collection if keys is null.
        Parameters:
        keys - the keys to look up
        Returns:
        a tag collection with all tags whose key is equal to one of the keys in keys
      • asSet

        public Set<TagasSet()
        Replies the tags of this tag collection as set
        Returns:
        the tags of this tag collection as set
      • asList

        public List<TagasList()
        Replies the tags of this tag collection as list. Note that the order of the list is not preserved between method invocations.
        Returns:
        the tags of this tag collection as list. There are no duplicate values.
      • getKeys

        public Set<StringgetKeys()
        Replies the set of keys of this tag collection.
        Returns:
        the set of keys of this tag collection
      • getKeysWithMultipleValues

        public Set<StringgetKeysWithMultipleValues()
        Replies the set of keys which have at least 2 matching tags.
        Returns:
        the set of keys which have at least 2 matching tags.
      • setUniqueForKey

        public void setUniqueForKey​(Tag tag)
        Sets a unique tag for the key of this tag. All other tags with the same key are removed from the collection. Does nothing if tag is null.
        Parameters:
        tag - the tag to set
      • setUniqueForKey

        public void setUniqueForKey​(String key,
                                    String value)
        Sets a unique tag for the key of this tag. All other tags with the same key are removed from the collection. Assume the empty string for key and value if either key or value is null.
        Parameters:
        key - the key
        value - the value
      • getValues

        public Set<StringgetValues()
        Replies the set of values in this tag collection
        Returns:
        the set of values
      • getValues

        public Set<StringgetValues​(String key)
        Replies the set of values for a given key. Replies an empty collection if there are no values for the given key.
        Parameters:
        key - the key to look up
        Returns:
        the set of values for a given key. Replies an empty collection if there are no values for the given key
      • isApplicableToPrimitive

        public boolean isApplicableToPrimitive()
        Replies true if for every key there is one tag only, i.e. exactly one value.
        Returns:
        true if for every key there is one tag only
      • applyTo

        public void applyTo​(Tagged primitive)
        Applies this tag collection to an OsmPrimitive. Does nothing if primitive is null
        Parameters:
        primitive - the primitive
        Throws:
        IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • applyTo

        public void applyTo​(Collection<? extends Tagged> primitives)
        Applies this tag collection to a collection of OsmPrimitives. Does nothing if primitives is null
        Parameters:
        primitives - the collection of primitives
        Throws:
        IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • replaceTagsOf

        public void replaceTagsOf​(Tagged primitive)
        Replaces the tags of an OsmPrimitive by the tags in this collection . Does nothing if primitive is null
        Parameters:
        primitive - the primitive
        Throws:
        IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • replaceTagsOf

        public void replaceTagsOf​(Collection<? extends Tagged> primitives)
        Replaces the tags of a collection ofOsmPrimitives by the tags in this collection. Does nothing if primitives is null
        Parameters:
        primitives - the collection of primitives
        Throws:
        IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • intersect

        public TagCollection intersect​(TagCollection other)
        Builds the intersection of this tag collection and another tag collection
        Parameters:
        other - the other tag collection. If null, replies an empty tag collection.
        Returns:
        the intersection of this tag collection and another tag collection. All counts are set to 1.
      • minus

        public TagCollection minus​(TagCollection other)
        Replies the difference of this tag collection and another tag collection
        Parameters:
        other - the other tag collection. May be null.
        Returns:
        the difference of this tag collection and another tag collection
      • union

        public TagCollection union​(TagCollection other)
        Replies the union of this tag collection and another tag collection
        Parameters:
        other - the other tag collection. May be null.
        Returns:
        the union of this tag collection and another tag collection. The tag count is summed.
      • getJoinedValues

        public String getJoinedValues​(String key)
        Replies the concatenation of all tag values (concatenated by a semicolon)
        Parameters:
        key - the key to look up
        Returns:
        the concatenation of all tag values
      • getSummedValues

        public String getSummedValues​(String key)
        Replies the sum of all numeric tag values. Ignores duplicates.
        Parameters:
        key - the key to look up
        Returns:
        the sum of all numeric tag values, as string.
        Since:
        7743
      • generateStreamForKey

        private Stream<TaggenerateStreamForKey​(String key)
        Get a stream for the given key.
        Parameters:
        key - The key
        Returns:
        The stream. An empty stream if key is null