Class TagCollection

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      TagCollection emptyTagsForKeysMissingIn​(TagCollection other)  
      private void ensureApplicableToPrimitive()  
      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.
      private java.util.stream.Stream<java.lang.String> generateKeyStream()  
      private java.util.stream.Stream<Tag> generateStreamForKey​(java.lang.String key)
      Get a stream for the given key.
      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.
      int getTagOccurrence​(Tag tag)
      Gets the number of times this tag was added to the collection.
      TagCollection getTagsFor​(java.lang.String key)
      Replies a tag collection with the tags for a given key.
      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.
      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.lang.String key)
      Removes all tags whose keys are equal to key.
      void removeByKey​(java.util.Collection<java.lang.String> keys)
      Removes all tags whose key is in the collection keys.
      void replaceTagsOf​(java.util.Collection<? extends Tagged> primitives)
      Replaces the tags of a collection ofOsmPrimitives 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • 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​(java.util.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​(java.util.Map<java.lang.String,​java.lang.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​(java.util.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​(java.util.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​(java.util.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​(java.util.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​(java.lang.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​(java.util.Collection<java.lang.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​(java.util.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​(java.util.Collection<java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(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. 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 java.util.Set<TagasSet()
        Replies the tags of this tag collection as set
        Returns:
        the tags of this tag collection as set
      • asList

        public java.util.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.
      • iterator

        public java.util.Iterator<Tagiterator()
        Replies an iterator to iterate over the tags in this collection
        Specified by:
        iterator in interface java.lang.Iterable<Tag>
        Returns:
        the iterator
      • getKeys

        public java.util.Set<java.lang.String> getKeys()
        Replies the set of keys of this tag collection.
        Returns:
        the set of keys of this tag collection
      • getKeysWithMultipleValues

        public java.util.Set<java.lang.String> getKeysWithMultipleValues()
        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​(java.lang.String key,
                                    java.lang.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 java.util.Set<java.lang.String> getValues()
        Replies the set of values in this tag collection
        Returns:
        the set of values
      • getValues

        public java.util.Set<java.lang.String> getValues​(java.lang.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:
        java.lang.IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • applyTo

        public void applyTo​(java.util.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:
        java.lang.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:
        java.lang.IllegalStateException - if this tag collection can't be applied because there are keys with multiple values
      • replaceTagsOf

        public void replaceTagsOf​(java.util.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:
        java.lang.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 java.lang.String getJoinedValues​(java.lang.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 java.lang.String getSummedValues​(java.lang.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
      • generateKeyStream

        private java.util.stream.Stream<java.lang.String> generateKeyStream()
      • generateStreamForKey

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object