Class AbstractPrimitive

    • Field Detail

      • FLAG_MODIFIED

        protected static final short FLAG_MODIFIED
        This flag shows, that the properties have been changed by the user and on upload the object will be send to the server.
        See Also:
        Constant Field Values
      • FLAG_DELETED

        protected static final short FLAG_DELETED
        An object that was deleted by the user. Deleted objects are usually hidden on the map and a request for deletion will be send to the server on upload. An object usually cannot be deleted if it has non-deleted objects still referring to it.
        See Also:
        Constant Field Values
      • FLAG_INCOMPLETE

        protected static final short FLAG_INCOMPLETE
        A primitive is incomplete if we know its id and type, but nothing more. Typically some members of a relation are incomplete until they are fetched from the server.
        See Also:
        Constant Field Values
      • FLAG_DISABLED

        protected static final short FLAG_DISABLED
        An object can be disabled by the filter mechanism. Then it will show in a shade of gray on the map or it is completely hidden from the view. Disabled objects usually cannot be selected or modified while the filter is active.
        See Also:
        Constant Field Values
      • FLAG_HIDE_IF_DISABLED

        protected static final short FLAG_HIDE_IF_DISABLED
        This flag is only relevant if an object is disabled by the filter mechanism (i.e. FLAG_DISABLED is set). Then it indicates, whether it is completely hidden or just shown in gray color. When the primitive is not disabled, this flag should be unset as well (for efficient access).
        See Also:
        Constant Field Values
      • FLAG_HAS_DIRECTIONS

        protected static final short FLAG_HAS_DIRECTIONS
        This flag is set if the primitive is a way and according to the tags, the direction of the way is important. (e.g. one way street.)
        See Also:
        Constant Field Values
      • FLAG_TAGGED

        protected static final short FLAG_TAGGED
        If the primitive is tagged. Some trivial tags like source=* are ignored here.
        See Also:
        Constant Field Values
      • FLAG_DIRECTION_REVERSED

        protected static final short FLAG_DIRECTION_REVERSED
        This flag is only relevant if FLAG_HAS_DIRECTIONS is set. It shows, that direction of the arrows should be reversed. (E.g. oneway=-1.)
        See Also:
        Constant Field Values
      • FLAG_HIGHLIGHTED

        protected static final short FLAG_HIGHLIGHTED
        When hovering over ways and nodes in add mode, the "target" objects are visually highlighted. This flag indicates that the primitive is currently highlighted.
        See Also:
        Constant Field Values
      • FLAG_ANNOTATED

        protected static final short FLAG_ANNOTATED
        If the primitive is annotated with a tag such as note, fixme, etc. Match the "work in progress" tags in default map style.
        See Also:
        Constant Field Values
      • flags

        protected volatile short flags
        Put several boolean flags to one short int field to save memory. Other bits of this field are used in subclasses.
      • mappaintCacheIdx

        protected short mappaintCacheIdx
        The mappaint cache index for this primitive. This field belongs to OsmPrimitive, but due to Java's memory layout alignment, see #20830.
      • id

        protected long id
        Unique identifier in OSM. This is used to identify objects on the server. An id of 0 means an unknown id. The object has not been uploaded yet to know what id it will get.
      • user

        protected User user
        User that last modified this primitive, as specified by the server. Never changed by JOSM.
      • version

        protected int version
        Contains the version number as returned by the API. Needed to ensure update consistency
      • changesetId

        protected int changesetId
        The id of the changeset this primitive was last uploaded to. 0 if it wasn't uploaded to a changeset yet of if the changeset id isn't known.
      • timestamp

        protected int timestamp
        A time value, measured in seconds from the epoch, or in other words, a number of seconds that have passed since 1970-01-01T00:00:00Z
    • Method Detail

      • cloneFrom

        public void cloneFrom​(AbstractPrimitive 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 - the primitive to clone data from
      • getVersion

        public int getVersion()
        Description copied from interface: IPrimitive
        Replies the version number as returned by the API. The version is 0 if the id is 0 or if this primitive is incomplete.
        Specified by:
        getVersion in interface IPrimitive
        Returns:
        the version number as returned by the API
        See Also:
        PrimitiveData.setVersion(int)
      • getId

        public long getId()
        Description copied from interface: IPrimitive
        Replies the id of this primitive.
        Specified by:
        getId in interface IPrimitive
        Returns:
        the id of this primitive.
      • getUniqueId

        public long getUniqueId()
        Gets a unique id representing this object.
        Specified by:
        getUniqueId in interface PrimitiveId
        Returns:
        Osm id if primitive already exists on the server. Unique negative value if primitive is new
      • isNew

        public boolean isNew()
        Determines if this primitive is new.
        Specified by:
        isNew in interface PrimitiveId
        Returns:
        true if this primitive is new (not yet uploaded the server, id <= 0)
      • setOsmId

        public void setOsmId​(long id,
                             int version)
        Description copied from interface: IPrimitive
        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
        Parameters:
        id - the id. > 0 required
        version - the version > 0 required
      • 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 of calling this method.
        Since:
        6140
      • getIdGenerator

        public abstract UniqueIdGenerator getIdGenerator()
        Returns the unique identifier generator.
        Returns:
        the unique identifier generator
        Since:
        15820
      • getUser

        public User getUser()
        Description copied from interface: IPrimitive
        Replies the user who has last touched this object. May be null.
        Specified by:
        getUser in interface IPrimitive
        Returns:
        the user who has last touched this object. May be null.
      • setUser

        public void setUser​(User user)
        Description copied from interface: IPrimitive
        Sets the user who has last touched this object.
        Specified by:
        setUser in interface IPrimitive
        Parameters:
        user - the user
      • getChangesetId

        public int getChangesetId()
        Description copied from interface: IPrimitive
        Replies the id of the changeset this primitive was last uploaded to. 0 if this primitive wasn't uploaded to a changeset yet or if the changeset isn't known.
        Specified by:
        getChangesetId in interface IPrimitive
        Returns:
        the id of the changeset this primitive was last uploaded to.
      • setChangesetId

        public void setChangesetId​(int changesetId)
        Description copied from interface: IPrimitive
        Sets the changeset id of this primitive. Can't be set on a new primitive.
        Specified by:
        setChangesetId in interface IPrimitive
        Parameters:
        changesetId - the id. >= 0 required.
      • getInstant

        public Instant getInstant()
        Description copied from interface: IPrimitive
        Time of last modification to this object. This is not set by JOSM but read from the server and delivered back to the server unmodified. It is used to check against edit conflicts.
        Specified by:
        getInstant in interface IPrimitive
        Returns:
        date of last modification
        See Also:
        IPrimitive.getInstant()
      • getRawTimestamp

        public int getRawTimestamp()
        Description copied from interface: IPrimitive
        Time of last modification to this object. This is not set by JOSM but read from the server and delivered back to the server unmodified. It is used to check against edit conflicts.
        Specified by:
        getRawTimestamp in interface IPrimitive
        Returns:
        last modification as timestamp
        See Also:
        IPrimitive.setRawTimestamp(int)
      • updateFlags

        protected void updateFlags​(short flag,
                                   boolean value)
      • updateFlagsChanged

        protected boolean updateFlagsChanged​(short flag,
                                             boolean value)
        Update flags
        Parameters:
        flag - The flag to update
        value - The value to set
        Returns:
        true if the flags have changed
      • setModified

        public void setModified​(boolean modified)
        Description copied from interface: IPrimitive
        Marks this primitive as being modified.
        Specified by:
        setModified in interface IPrimitive
        Parameters:
        modified - true, if this primitive is to be modified
      • isModified

        public boolean isModified()
        Description copied from interface: IPrimitive
        Replies true if the object has been modified since it was loaded from the server. In this case, on next upload, this object will be updated. Deleted objects are deleted from the server. If the objects are added (id=0), the modified is ignored and the object is added to the server.
        Specified by:
        isModified in interface IPrimitive
        Returns:
        true if the object has been modified since it was loaded from the server
      • isUndeleted

        public boolean isUndeleted()
        Description copied from interface: IPrimitive
        Replies true if the object has been deleted on the server and was undeleted by the user.
        Specified by:
        isUndeleted in interface IPrimitive
        Returns:
        true if the object has been undeleted
      • isVisible

        public boolean isVisible()
        Description copied from interface: IPrimitive
        Checks if object is known to the server. Replies true if this primitive is either unknown to the server (i.e. its id is 0) or it is known to the server and it hasn't be deleted on the server. Replies false, if this primitive is known on the server and has been deleted on the server.
        Specified by:
        isVisible in interface IPrimitive
        Returns:
        true, if the object is visible on server.
        See Also:
        IPrimitive.setVisible(boolean)
      • setVisible

        public void setVisible​(boolean visible)
        Description copied from interface: IPrimitive
        Sets whether this primitive is visible, i.e. whether it is known on the server and not deleted on the server.
        Specified by:
        setVisible in interface IPrimitive
        Parameters:
        visible - true if this primitive is visible
        See Also:
        IPrimitive.isVisible()
      • 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
        Parameters:
        deleted - true, if this primitive is deleted; false, otherwise
      • setIncomplete

        protected void setIncomplete​(boolean incomplete)
        If set to true, this object is incomplete, which means only the id and type is known (type is the objects instance class)
        Parameters:
        incomplete - incomplete flag value
      • isIncomplete

        public boolean isIncomplete()
        Description copied from interface: IPrimitive
        Determines if this primitive is incomplete.
        Specified by:
        isIncomplete in interface IPrimitive
        Returns:
        true if this primitive is incomplete, false otherwise
      • 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
        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
      • getKeys

        public TagMap getKeys()
        Replies the map of key/value pairs. Never replies null. The map can be empty, though.
        Specified by:
        getKeys in interface Tagged
        Returns:
        tags of this primitive. Changes made in returned map are not mapped back to the primitive, use setKeys() to modify the keys
        See Also:
        visitKeys(KeyValueVisitor)
      • setKeys

        public void setKeys​(Map<String,​String> keys)
        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
        Parameters:
        keys - the key/value pairs to set. If null, removes all existing key/value pairs.
      • setKeys

        public void setKeys​(TagMap keys)
        Copy the keys from a TagMap.
        Parameters:
        keys - The new key map.
      • put

        public void put​(String key,
                        String value)
        Set the given value to the given key. If key is null, does nothing. If value is null, removes the key and behaves like 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
        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:
        remove(String)
      • indexOfKey

        private static int indexOfKey​(String[] keys,
                                      String key)
        Scans a key/value array for a given key.
        Parameters:
        keys - The key array. It is not modified. It may be null to indicate an empty array.
        key - The key to search for.
        Returns:
        The position of that key in the keys array - which is always a multiple of 2 - or -1 if it was not found.
      • remove

        public void remove​(String key)
        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
        Parameters:
        key - the key to be removed. Ignored, if key is null.
      • removeAll

        public void removeAll()
        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
      • get

        public final String get​(String key)
        Replies the value for key key. Replies null, if key is null. Replies null, if there is no value for the given key.
        Specified by:
        get in interface Tagged
        Parameters:
        key - the key. Can be null, replies null in this case.
        Returns:
        the value for key key.
      • getIgnoreCase

        public final String getIgnoreCase​(String key)
        Gets a key ignoring the case of the key
        Parameters:
        key - The key to get
        Returns:
        The value for a key that matches the given key ignoring case.
      • getNumKeys

        public final int getNumKeys()
        Description copied from interface: Tagged
        Gets the number of keys
        Specified by:
        getNumKeys in interface Tagged
        Returns:
        The number of keys set for this tagged object.
      • hasKeys

        public final boolean hasKeys()
        Replies true, if the map of key/value pairs of this primitive is not empty.
        Specified by:
        hasKeys in interface Tagged
        Returns:
        true, if the map of key/value pairs of this primitive is not empty; false otherwise
      • hasKey

        public boolean hasKey​(String key)
        Replies true if this primitive has a tag with key key.
        Specified by:
        hasKey in interface Tagged
        Parameters:
        key - the key
        Returns:
        true, if this primitive has a tag with key key
        See Also:
        Tagged.hasTag(String)
      • hasKey

        public boolean hasKey​(String... keys)
        Replies true if this primitive has a tag any of the keys.
        Parameters:
        keys - the keys
        Returns:
        true, if this primitive has a tag with any of the keys
        Since:
        11587
      • keysChangedImpl

        protected abstract void keysChangedImpl​(Map<String,​String> originalKeys)
        What to do, when the tags have changed by one of the tag-changing methods.
        Parameters:
        originalKeys - original tags
      • getUninterestingKeys

        public static Collection<StringgetUninterestingKeys()
        Returns a list of "uninteresting" keys that do not make an object "tagged". Entries that end with ':' are causing a whole namespace to be considered "uninteresting". Only the first level namespace is considered. Initialized by isUninterestingKey()
        Returns:
        The list of uninteresting keys.
      • getDiscardableKeys

        public static Collection<StringgetDiscardableKeys()
        Returns a list of keys which have been deemed uninteresting to the point that they can be silently removed from data which is being edited.
        Returns:
        The list of discardable keys.
      • getWorkInProgressKeys

        public static Collection<StringgetWorkInProgressKeys()
        Returns a list of "work in progress" keys that do not make an object "tagged" but "annotated".
        Returns:
        The list of work in progress keys.
        Since:
        5754
      • isUninterestingKey

        public static boolean isUninterestingKey​(String key)
        Determines if key is considered "uninteresting".
        Parameters:
        key - The key to check
        Returns:
        true if key is considered "uninteresting".