Class OsmPrimitive

    • Constructor Detail

      • OsmPrimitive

        protected OsmPrimitive​(long id,
                               boolean allowNegativeId)
        Creates a new primitive for the given id.

        If allowNegativeId is set, provided id can be < 0 and will be set to primitive without any processing. If allowNegativeId is not set, then id will have to be 0 (in that case new unique id will be generated) or positive number.

        Parameters:
        id - the id
        allowNegativeId - true to allow negative id
        Throws:
        java.lang.IllegalArgumentException - if id < 0 and allowNegativeId is false
      • OsmPrimitive

        protected OsmPrimitive​(long id,
                               int version,
                               boolean allowNegativeId)
        Creates a new primitive for the given id and version.

        If allowNegativeId is set, provided id can be < 0 and will be set to primitive without any processing. If allowNegativeId is not set, then id will have to be 0 (in that case new unique id will be generated) or positive number.

        If id is not > 0 version is ignored and set to 0.

        Parameters:
        id - the id
        version - the version (positive integer)
        allowNegativeId - true to allow negative id
        Throws:
        java.lang.IllegalArgumentException - if id < 0 and allowNegativeId is false
    • Method Detail

      • getReferrer

        public static java.util.Set<OsmPrimitivegetReferrer​(java.util.Collection<? extends OsmPrimitive> primitives)
        Replies the collection of referring primitives for the primitives in primitives.
        Parameters:
        primitives - the collection of primitives.
        Returns:
        the collection of referring primitives for the primitives in primitives; empty set if primitives is null or if there are no referring primitives
      • isCachedStyleUpToDate

        public final boolean isCachedStyleUpToDate()
        Description copied from interface: Stylable
        Check if the cached style for this primitive is up to date.
        Specified by:
        isCachedStyleUpToDate in interface Stylable
        Returns:
        true if the cached style for this primitive is up to date
      • setDataset

        void setDataset​(DataSet dataSet)
        This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods
        Parameters:
        dataSet - the parent dataset
      • checkDataset

        public void checkDataset()
        Throws exception if primitive is not part of the dataset
      • checkDatasetNotReadOnly

        protected final void checkDatasetNotReadOnly()
        Throws exception if primitive is in a read-only dataset
      • writeUnlock

        protected void writeUnlock​(boolean locked)
      • setOsmId

        public void setOsmId​(long id,
                             int version)
        Sets the id and the version of this primitive if it is known to the OSM API.

        Since we know the id and its version it can't be incomplete anymore. incomplete is set to false.

        Specified by:
        setOsmId in interface IPrimitive
        Overrides:
        setOsmId in class AbstractPrimitive
        Parameters:
        id - the id. > 0 required
        version - the version > 0 required
        Throws:
        java.lang.IllegalArgumentException - if id <= 0
        java.lang.IllegalArgumentException - if version <= 0
        DataIntegrityProblemException - if id is changed and primitive was already added to the dataset
      • clearOsmMetadata

        public void clearOsmMetadata()
        Clears the metadata, including id and version known to the OSM API. The id is a new unique id. The version, changeset and timestamp are set to 0. incomplete and deleted are set to false. It's preferred to use copy constructor with clearMetadata set to true instead

        Caution: Do not use this method on primitives which are already added to a DataSet.

        Overrides:
        clearOsmMetadata in class AbstractPrimitive
        Throws:
        DataIntegrityProblemException - If primitive was already added to the dataset
        Since:
        6140
      • setDisabledState

        public boolean setDisabledState​(boolean hidden)
        Description copied from interface: IFilterablePrimitive
        Make the primitive disabled (e.g. if a filter applies). To enable the primitive again, use unsetDisabledState.
        Specified by:
        setDisabledState in interface IFilterablePrimitive
        Overrides:
        setDisabledState in class AbstractPrimitive
        Parameters:
        hidden - if the primitive should be completely hidden from view or just shown in gray color.
        Returns:
        true, any flag has changed; false if you try to set the disabled state to the value that is already preset
      • setPreserved

        public void setPreserved​(boolean isPreserved)
        Set binary property used internally by the filter mechanism.
        Parameters:
        isPreserved - new "preserved" flag value
        Since:
        13309
      • isSelectable

        public boolean isSelectable()
        Description copied from interface: IPrimitive
        Determines if this object is selectable.

        A primitive can be selected if all conditions are met:

        • it is drawable
        • it is not disabled (greyed out) by a filter.
        Specified by:
        isSelectable in interface IPrimitive
        Returns:
        true if this object is selectable
      • setDeleted

        public void setDeleted​(boolean deleted)
        Description copied from interface: IPrimitive
        Sets whether this primitive is deleted or not.

        Also marks this primitive as modified if deleted is true.

        Specified by:
        setDeleted in interface IPrimitive
        Overrides:
        setDeleted in class AbstractPrimitive
        Parameters:
        deleted - true, if this primitive is deleted; false, otherwise
      • setIncomplete

        protected final void setIncomplete​(boolean incomplete)
        Description copied from class: AbstractPrimitive
        If set to true, this object is incomplete, which means only the id and type is known (type is the objects instance class)
        Overrides:
        setIncomplete in class AbstractPrimitive
        Parameters:
        incomplete - incomplete flag value
      • isSelected

        public boolean isSelected()
        Description copied from interface: IPrimitive
        Determines whether the primitive is selected
        Specified by:
        isSelected in interface IPrimitive
        Returns:
        whether the primitive is selected
      • isMemberOfSelected

        public boolean isMemberOfSelected()
        Description copied from interface: IPrimitive
        Determines if this primitive is a member of a selected relation.
        Specified by:
        isMemberOfSelected in interface IPrimitive
        Returns:
        true if this primitive is a member of a selected relation, false otherwise
      • isOuterMemberOfSelected

        public boolean isOuterMemberOfSelected()
        Description copied from interface: IPrimitive
        Determines if this primitive is an outer member of a selected multipolygon relation.
        Specified by:
        isOuterMemberOfSelected in interface IPrimitive
        Returns:
        true if this primitive is an outer member of a selected multipolygon relation, false otherwise
      • setHighlighted

        public void setHighlighted​(boolean highlighted)
        Description copied from interface: IPrimitive
        Updates the highlight flag for this primitive.
        Specified by:
        setHighlighted in interface IPrimitive
        Parameters:
        highlighted - The new highlight flag.
      • compileDirectionKeys

        private static SearchCompiler.Match compileDirectionKeys​(java.lang.String prefName,
                                                                 java.lang.String defaultValue)
                                                          throws java.lang.AssertionError
        Throws:
        java.lang.AssertionError
      • setKeys

        public final void setKeys​(java.util.Map<java.lang.String,​java.lang.String> keys)
        Description copied from class: AbstractPrimitive
        Sets the keys of this primitives to the key/value pairs in keys. Old key/value pairs are removed. If keys is null, clears existing key/value pairs.

        Note that this method, like all methods that modify keys, is not synchronized and may lead to data corruption when being used from multiple threads.

        Specified by:
        setKeys in interface Tagged
        Overrides:
        setKeys in class AbstractPrimitive
        Parameters:
        keys - the key/value pairs to set. If null, removes all existing key/value pairs.
      • put

        public final void put​(java.lang.String key,
                              java.lang.String value)
        Description copied from class: AbstractPrimitive
        Set the given value to the given key. If key is null, does nothing. If value is null, removes the key and behaves like AbstractPrimitive.remove(String).

        Note that this method, like all methods that modify keys, is not synchronized and may lead to data corruption when being used from multiple threads.

        Specified by:
        put in interface Tagged
        Overrides:
        put in class AbstractPrimitive
        Parameters:
        key - The key, for which the value is to be set. Can be null or empty, does nothing in this case.
        value - The value for the key. If null, removes the respective key/value pair.
        See Also:
        AbstractPrimitive.remove(String)
      • remove

        public final void remove​(java.lang.String key)
        Description copied from class: AbstractPrimitive
        Remove the given key from the list

        Note that this method, like all methods that modify keys, is not synchronized and may lead to data corruption when being used from multiple threads.

        Specified by:
        remove in interface Tagged
        Overrides:
        remove in class AbstractPrimitive
        Parameters:
        key - the key to be removed. Ignored, if key is null.
      • removeAll

        public final void removeAll()
        Description copied from class: AbstractPrimitive
        Removes all keys from this primitive.

        Note that this method, like all methods that modify keys, is not synchronized and may lead to data corruption when being used from multiple threads.

        Specified by:
        removeAll in interface Tagged
        Overrides:
        removeAll in class AbstractPrimitive
      • keysChangedImpl

        protected void keysChangedImpl​(java.util.Map<java.lang.String,​java.lang.String> originalKeys)
        Description copied from class: AbstractPrimitive
        What to do, when the tags have changed by one of the tag-changing methods.
        Specified by:
        keysChangedImpl in class AbstractPrimitive
        Parameters:
        originalKeys - original tags
      • addReferrer

        protected void addReferrer​(OsmPrimitive referrer)
        Add new referrer. If referrer is already included then no action is taken
        Parameters:
        referrer - The referrer to add
      • removeReferrer

        protected void removeReferrer​(OsmPrimitive referrer)
        Remove referrer. No action is taken if referrer is not registered
        Parameters:
        referrer - The referrer to remove
      • referrers

        private <T extends OsmPrimitive> java.util.stream.Stream<T> referrers​(boolean allowWithoutDataset,
                                                                              java.lang.Class<T> filter)
      • referrers

        public final <T extends OsmPrimitive> java.util.stream.Stream<T> referrers​(java.lang.Class<T> filter)
        Gets all primitives in the current dataset that reference this primitive.
        Type Parameters:
        T - type of primitives
        Parameters:
        filter - restrict primitives to subclasses
        Returns:
        the referrers as Stream
        Since:
        14654
      • getReferrers

        public final java.util.List<OsmPrimitivegetReferrers​(boolean allowWithoutDataset)
        Description copied from interface: IPrimitive
        Find primitives that reference this primitive. Returns only primitives that are included in the same dataset as this primitive.
        For example following code will add wnew as referer to all nodes of existingWay, but this method will not return wnew because it's not part of the dataset
        Way wnew = new Way(existingWay)
        Specified by:
        getReferrers in interface IPrimitive
        Parameters:
        allowWithoutDataset - If true, method will return empty list if primitive is not part of the dataset. If false, exception will be thrown in this case
        Returns:
        a collection of all primitives that reference this primitive.
      • getReferrers

        public final java.util.List<OsmPrimitivegetReferrers()
        Description copied from interface: IPrimitive
        Gets a list of all primitives in the current dataset that reference this primitive.
        Specified by:
        getReferrers in interface IPrimitive
        Returns:
        The referrers
      • visitReferrers

        public void visitReferrers​(OsmPrimitiveVisitor visitor)

        Visits visitor for all referrers.

        Parameters:
        visitor - the visitor. Ignored, if null.
        Since:
        12809
      • isNodeReferredByWays

        protected final boolean isNodeReferredByWays​(int n)
        Return true, if this primitive is a node referred by at least n ways
        Parameters:
        n - Minimal number of ways to return true. Must be positive
        Returns:
        true if this primitive is referred by at least n ways
      • accept

        public abstract void accept​(OsmPrimitiveVisitor visitor)
        Implementation of the visitor scheme. Subclasses have to call the correct visitor function.
        Parameters:
        visitor - The visitor from which the visit() function must be called.
        Since:
        12809
      • cloneFrom

        public final void cloneFrom​(OsmPrimitive other)
        Get and write all attributes from the parameter. Does not fire any listener, so use this only in the data initializing phase
        Parameters:
        other - other primitive
      • cloneFrom

        protected void cloneFrom​(OsmPrimitive other,
                                 boolean copyChildren)
        Get and write all attributes from the parameter. Does not fire any listener, so use this only in the data initializing phase
        Parameters:
        other - other primitive
        copyChildren - whether to copy child primitives too
        Since:
        16212
      • mergeFrom

        public void mergeFrom​(OsmPrimitive other)
        Merges the technical and semantic attributes from other onto this.

        Both this and other must be new, or both must be assigned an OSM ID. If both this and other have an assigned OSM id, the IDs have to be the same.

        Parameters:
        other - the other primitive. Must not be null.
        Throws:
        java.lang.IllegalArgumentException - if other is null.
        DataIntegrityProblemException - if either this is new and other is not, or other is new and this is not
        DataIntegrityProblemException - if other isn't new and other.getId() != this.getId()
      • hasEqualSemanticAttributes

        public final boolean hasEqualSemanticAttributes​(OsmPrimitive other)
        Replies true if this primitive and other are equal with respect to their semantic attributes.
        1. equal id
        2. both are complete or both are incomplete
        3. both have the same tags
        Parameters:
        other - other primitive to compare
        Returns:
        true if this primitive and other are equal with respect to their semantic attributes.
      • hasEqualTechnicalAttributes

        public boolean hasEqualTechnicalAttributes​(OsmPrimitive other)
        Replies true if this primitive and other are equal with respect to their technical attributes. The attributes:
        1. deleted
        2. modified
        3. timestamp
        4. version
        5. visible
        6. user
        have to be equal
        Parameters:
        other - the other primitive
        Returns:
        true if this primitive and other are equal with respect to their technical attributes
      • load

        public void load​(PrimitiveData data)
        Loads (clone) this primitive from provided PrimitiveData
        Parameters:
        data - The object which should be cloned
      • save

        public abstract PrimitiveData save()
        Save parameters of this primitive to the transport object
        Returns:
        The saved object data
      • saveCommonAttributes

        protected void saveCommonAttributes​(PrimitiveData data)
        Save common parameters of primitives to the transport object
        Parameters:
        data - The object to save the data into
      • updatePosition

        public abstract void updatePosition()
        Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
      • equals

        public boolean equals​(java.lang.Object obj)
        Equal if the id (and class) are equal.

        A primitive is equal to its incomplete counterpart.

        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Return the id plus the class type encoded as hashcode or super's hashcode if id is 0.

        A primitive has the same hashcode as its incomplete counterpart.

        Overrides:
        hashCode in class java.lang.Object
      • getTemplateValue

        public java.lang.Object getTemplateValue​(java.lang.String name,
                                                 boolean special)
        Description copied from interface: TemplateEngineDataProvider
        Map a key to a value given the properties of the object.
        Specified by:
        getTemplateValue in interface TemplateEngineDataProvider
        Parameters:
        name - the key to map
        special - if the key is a "special:*" keyword that is used to get certain information or automated behavior
        Returns:
        a value that the key is mapped to or "special" information in case special is true
      • getParentRelations

        public static java.util.Set<RelationgetParentRelations​(java.util.Collection<? extends OsmPrimitive> primitives)
        Replies the set of referring relations
        Parameters:
        primitives - primitives to fetch relations from
        Returns:
        the set of referring relations
      • hasAreaTags

        public final boolean hasAreaTags()
        Determines if this primitive has tags denoting an area.
        Returns:
        true if this primitive has tags denoting an area, false otherwise.
        Since:
        6491
      • concernsArea

        public abstract boolean concernsArea()
        Determines if this primitive semantically concerns an area.
        Returns:
        true if this primitive semantically concerns an area, according to its type, geometry and tags, false otherwise.
        Since:
        6491
      • isOutsideDownloadArea

        public abstract boolean isOutsideDownloadArea()
        Tests if this primitive lies outside of the downloaded area of its DataSet.
        Returns:
        true if this primitive lies outside of the downloaded area
      • addToBBox

        protected abstract void addToBBox​(BBox box,
                                          java.util.Set<PrimitiveId> visited)
        If necessary, extend the bbox to contain this primitive
        Parameters:
        box - a bbox instance
        visited - a set of visited members or null
        Since:
        11269