public abstract class AbstractPrimitive extends Object implements IPrimitive, IFilterablePrimitive
Modifier and Type | Field and Description |
---|---|
protected int |
changesetId
The id of the changeset this primitive was last uploaded to.
|
private static Collection<String> |
discardable |
protected static short |
FLAG_ANNOTATED
If the primitive is annotated with a tag such as note, fixme, etc.
|
protected static short |
FLAG_DELETED
An object that was deleted by the user.
|
protected static short |
FLAG_DIRECTION_REVERSED
This flag is only relevant if FLAG_HAS_DIRECTIONS is set.
|
protected static short |
FLAG_DISABLED
An object can be disabled by the filter mechanism.
|
protected static short |
FLAG_DISABLED_TYPE
Flag used internally by the filter mechanism.
|
protected static 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.
|
protected static short |
FLAG_HIDDEN_TYPE
Flag used internally by the filter mechanism.
|
protected static 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).
|
protected static short |
FLAG_HIGHLIGHTED
When hovering over ways and nodes in add mode, the
"target" objects are visually highlighted.
|
protected static short |
FLAG_INCOMPLETE
A primitive is incomplete if we know its id and type, but nothing more.
|
protected static 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.
|
protected static short |
FLAG_PRESERVED
Determines if the primitive is preserved from the filter mechanism.
|
protected static short |
FLAG_TAGGED
If the primitive is tagged.
|
protected static short |
FLAG_VISIBLE
This flag is false, if the object is marked
as deleted on the server.
|
protected short |
flags
Put several boolean flags to one short int field to save memory.
|
protected long |
id
Unique identifier in OSM.
|
protected String[] |
keys
The key/value list for this primitive.
|
protected short |
mappaintCacheIdx
The mappaint cache index for this primitive.
|
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
|
private static Collection<String> |
uninteresting |
protected User |
user
User that last modified this primitive, as specified by the server.
|
protected int |
version
Contains the version number as returned by the API.
|
private static Collection<String> |
workinprogress |
MAX_TAG_LENGTH
Constructor and Description |
---|
AbstractPrimitive() |
Modifier and Type | Method and Description |
---|---|
void |
clearOsmMetadata()
Clears the metadata, including id and version known to the OSM API.
|
void |
cloneFrom(AbstractPrimitive other)
Get and write all attributes from the parameter.
|
protected String |
doGet(String key,
BiPredicate<String,String> predicate) |
String |
get(String key)
Replies the value for key
key . |
int |
getChangesetId()
Replies the id of the changeset this primitive was last uploaded to.
|
boolean |
getDisabledType()
Get binary property used internally by the filter mechanism.
|
static Collection<String> |
getDiscardableKeys()
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.
|
protected String |
getFlagsAsString() |
boolean |
getHiddenType()
Get binary property used internally by the filter mechanism.
|
long |
getId()
Replies the id of this primitive.
|
abstract UniqueIdGenerator |
getIdGenerator()
Returns the unique identifier generator.
|
String |
getIgnoreCase(String key)
Gets a key ignoring the case of the key
|
Instant |
getInstant()
Time of last modification to this object.
|
Map<String,String> |
getInterestingTags()
Returns
Tagged.getKeys() for which key does not fulfill uninteresting criteria. |
TagMap |
getKeys()
Replies the map of key/value pairs.
|
int |
getNumKeys()
Gets the number of keys
|
int |
getRawTimestamp()
Time of last modification to this object.
|
Date |
getTimestamp()
Deprecated.
|
static Collection<String> |
getUninterestingKeys()
Returns a list of "uninteresting" keys that do not make an object
"tagged".
|
long |
getUniqueId()
Gets a unique id representing this object.
|
User |
getUser()
Replies the user who has last touched this object.
|
int |
getVersion()
Replies the version number as returned by the API.
|
static Collection<String> |
getWorkInProgressKeys()
Returns a list of "work in progress" keys that do not make an object
"tagged" but "annotated".
|
boolean |
hasKey(String... keys)
Replies true if this primitive has a tag any of the
keys . |
boolean |
hasKey(String key)
Replies true if this primitive has a tag with key
key . |
boolean |
hasKeys()
Replies true, if the map of key/value pairs of this primitive is not empty.
|
private static int |
indexOfKey(String[] keys,
String key)
Scans a key/value array for a given key.
|
boolean |
isDeleted()
Replies
true , if the object has been deleted. |
boolean |
isDrawable()
Determines if this object is drawable.
|
boolean |
isIncomplete()
Determines if this primitive is incomplete.
|
boolean |
isModified()
Replies
true if the object has been modified since it was loaded from
the server. |
boolean |
isNew()
Determines if this primitive is new.
|
boolean |
isNewOrUndeleted()
Determines if this primitive is new or undeleted.
|
boolean |
isTimestampEmpty()
Determines if this primitive has no timestamp information.
|
boolean |
isUndeleted()
Replies
true if the object has been deleted on the server and was undeleted by the user. |
static boolean |
isUninterestingKey(String key)
Determines if key is considered "uninteresting".
|
boolean |
isUsable()
Replies
true , if the object is usable
(i.e. |
boolean |
isVisible()
Checks if object is known to the server.
|
Stream<String> |
keys()
Replies the keys as stream
|
protected abstract void |
keysChangedImpl(Map<String,String> originalKeys)
What to do, when the tags have changed by one of the tag-changing methods.
|
Collection<String> |
keySet()
Replies the set of keys
|
void |
put(String key,
String value)
Set the given value to the given key.
|
void |
putAll(Map<String,String> tags)
Add all key/value pairs.
|
void |
remove(String key)
Remove the given key from the list
|
void |
removeAll()
Removes all keys from this primitive.
|
void |
setChangesetId(int changesetId)
Sets the changeset id of this primitive.
|
void |
setDeleted(boolean deleted)
Sets whether this primitive is deleted or not.
|
boolean |
setDisabledState(boolean hidden)
Make the primitive disabled (e.g. if a filter applies).
|
void |
setDisabledType(boolean isExplicit)
Set binary property used internally by the filter mechanism.
|
void |
setHiddenType(boolean isExplicit)
Set binary property used internally by the filter mechanism.
|
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)
|
void |
setInstant(Instant timestamp)
Sets time of last modification to this object
|
void |
setKeys(Map<String,String> keys)
Sets the keys of this primitives to the key/value pairs in
keys . |
void |
setKeys(TagMap keys)
Copy the keys from a TagMap.
|
void |
setModified(boolean modified)
Marks this primitive as being modified.
|
void |
setOsmId(long id,
int version)
Sets the id and the version of this primitive if it is known to the OSM API.
|
void |
setRawTimestamp(int timestamp)
Sets time of last modification to this object
|
void |
setTimestamp(Date timestamp)
Deprecated.
|
void |
setUser(User user)
Sets the user who has last touched this object.
|
void |
setVisible(boolean visible)
Sets whether this primitive is visible, i.e.
|
boolean |
unsetDisabledState()
Remove the disabled flag from the primitive.
|
protected void |
updateFlags(short flag,
boolean value) |
protected boolean |
updateFlagsChanged(short flag,
boolean value)
Update flags
|
void |
visitKeys(KeyValueVisitor visitor)
Calls the visitor for every key/value pair.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
accept, getBBox, getChildren, getDataSet, getDisplayName, getDisplayType, getLocalName, getName, getOsmId, getOsmPrimitiveId, getPrimitiveId, getReferrers, getReferrers, getStyleCacheSyncObject, hasDirectionKeys, hasSameInterestingTags, isAnnotated, isDisabled, isDisabledAndHidden, isHighlighted, isMemberOfSelected, isMultipolygon, isOuterMemberOfSelected, isPreserved, isSelectable, isSelected, isTagged, resetPrimitiveChildren, reversedDirection, setHighlighted, visitReferrers
hasTag, hasTag, hasTag, hasTag, hasTagDifferent, hasTagDifferent, hasTagDifferent, isKeyFalse, isKeyTrue, ofMap, ofTags, put
getType
clearCachedStyle, declareCachedStyleUpToDate, getCachedStyle, isCachedStyleUpToDate, setCachedStyle
compareTo
protected static final short FLAG_MODIFIED
protected static final short FLAG_VISIBLE
protected static final short FLAG_DELETED
protected static final short FLAG_INCOMPLETE
protected static final short FLAG_DISABLED
protected static final short FLAG_HIDE_IF_DISABLED
When the primitive is not disabled, this flag should be unset as well (for efficient access).
protected static final short FLAG_DISABLED_TYPE
protected static final short FLAG_HIDDEN_TYPE
protected static final short FLAG_HAS_DIRECTIONS
protected static final short FLAG_TAGGED
protected static final short FLAG_DIRECTION_REVERSED
protected static final short FLAG_HIGHLIGHTED
protected static final short FLAG_ANNOTATED
protected static final short FLAG_PRESERVED
protected volatile short flags
protected short mappaintCacheIdx
OsmPrimitive
, but due to Java's memory layout alignment, see #20830.protected long id
protected User user
protected int version
protected int changesetId
protected int timestamp
protected volatile String[] keys
Note that the keys field is synchronized using RCU. Writes to it are not synchronized by this object, the writers have to synchronize writes themselves.
In short this means that you should not rely on this variable being the same value when read again and your should always copy it on writes.
Further reading:
CopyOnWriteArrayList
rcu_assign_pointer
and rcu_dereference
are ensured by the volatile
keyword)private static volatile Collection<String> workinprogress
private static volatile Collection<String> uninteresting
private static volatile Collection<String> discardable
public AbstractPrimitive()
public void cloneFrom(AbstractPrimitive other)
other
- the primitive to clone data frompublic int getVersion()
IPrimitive
getVersion
in interface IPrimitive
PrimitiveData.setVersion(int)
public long getId()
IPrimitive
getId
in interface IPrimitive
public long getUniqueId()
getUniqueId
in interface PrimitiveId
public boolean isNew()
isNew
in interface PrimitiveId
true
if this primitive is new (not yet uploaded the server, id <= 0)public boolean isNewOrUndeleted()
IPrimitive
isNewOrUndeleted
in interface IPrimitive
PrimitiveId.isNew()
,
IPrimitive.isUndeleted()
public void setOsmId(long id, int version)
IPrimitive
Since we know the id and its version it can't be incomplete anymore. incomplete is set to false.
setOsmId
in interface IPrimitive
id
- the id. > 0 requiredversion
- the version > 0 requiredpublic void clearOsmMetadata()
public abstract UniqueIdGenerator getIdGenerator()
public User getUser()
IPrimitive
getUser
in interface IPrimitive
public void setUser(User user)
IPrimitive
setUser
in interface IPrimitive
user
- the userpublic int getChangesetId()
IPrimitive
getChangesetId
in interface IPrimitive
public void setChangesetId(int changesetId)
IPrimitive
setChangesetId
in interface IPrimitive
changesetId
- the id. >= 0 required.@Deprecated public void setTimestamp(Date timestamp)
IPrimitive
setTimestamp
in interface IPrimitive
timestamp
- date of last modificationIPrimitive.getTimestamp()
public void setInstant(Instant timestamp)
IPrimitive
setInstant
in interface IPrimitive
timestamp
- date of last modificationIPrimitive.getInstant()
public void setRawTimestamp(int timestamp)
IPrimitive
setRawTimestamp
in interface IPrimitive
timestamp
- date of last modificationIPrimitive.getRawTimestamp()
@Deprecated public Date getTimestamp()
IPrimitive
getTimestamp
in interface IPrimitive
IPrimitive.setTimestamp(java.util.Date)
public Instant getInstant()
IPrimitive
getInstant
in interface IPrimitive
IPrimitive.setInstant(java.time.Instant)
public int getRawTimestamp()
IPrimitive
getRawTimestamp
in interface IPrimitive
IPrimitive.setRawTimestamp(int)
public boolean isTimestampEmpty()
IPrimitive
isTimestampEmpty
in interface IPrimitive
true
if this primitive has no timestamp informationIPrimitive.getTimestamp()
,
IPrimitive.getRawTimestamp()
protected void updateFlags(short flag, boolean value)
protected boolean updateFlagsChanged(short flag, boolean value)
flag
- The flag to updatevalue
- The value to settrue
if the flags have changedpublic void setModified(boolean modified)
IPrimitive
setModified
in interface IPrimitive
modified
- true, if this primitive is to be modifiedpublic boolean isModified()
IPrimitive
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.
isModified
in interface IPrimitive
true
if the object has been modified since it was loaded from
the serverpublic boolean isDeleted()
IPrimitive
true
, if the object has been deleted.isDeleted
in interface IPrimitive
true
, if the object has been deleted.IPrimitive.setDeleted(boolean)
public boolean isUndeleted()
IPrimitive
true
if the object has been deleted on the server and was undeleted by the user.isUndeleted
in interface IPrimitive
true
if the object has been undeletedpublic boolean isUsable()
IPrimitive
true
, if the object is usable
(i.e. complete and not deleted).isUsable
in interface IPrimitive
true
, if the object is usable.IPrimitive.setDeleted(boolean)
public boolean isVisible()
IPrimitive
isVisible
in interface IPrimitive
true
, if the object is visible on server.IPrimitive.setVisible(boolean)
public void setVisible(boolean visible)
IPrimitive
setVisible
in interface IPrimitive
visible
- true
if this primitive is visibleIPrimitive.isVisible()
public void setDeleted(boolean deleted)
IPrimitive
Also marks this primitive as modified if deleted is true.
setDeleted
in interface IPrimitive
deleted
- true, if this primitive is deleted; false, otherwiseprotected void setIncomplete(boolean incomplete)
incomplete
- incomplete flag valuepublic boolean isIncomplete()
IPrimitive
isIncomplete
in interface IPrimitive
true
if this primitive is incomplete, false
otherwisepublic boolean getHiddenType()
IFilterablePrimitive
getHiddenType
in interface IFilterablePrimitive
true
if this object has the "hidden type" flag enabledpublic boolean getDisabledType()
IFilterablePrimitive
getDisabledType
in interface IFilterablePrimitive
true
if this object has the "disabled type" flag enabledpublic boolean setDisabledState(boolean hidden)
IFilterablePrimitive
setDisabledState
in interface IFilterablePrimitive
hidden
- if the primitive should be completely hidden from view or
just shown in gray color.public boolean unsetDisabledState()
IFilterablePrimitive
unsetDisabledState
in interface IFilterablePrimitive
true
if a change occurredpublic void setDisabledType(boolean isExplicit)
IFilterablePrimitive
setDisabledType
in interface IFilterablePrimitive
isExplicit
- new "disabled type" flag valuepublic void setHiddenType(boolean isExplicit)
IFilterablePrimitive
setHiddenType
in interface IFilterablePrimitive
isExplicit
- new "hidden type" flag valuepublic boolean isDrawable()
IPrimitive
A primitive is drawable if all conditions are met:
isDrawable
in interface IPrimitive
true
if this object is drawableprotected String getFlagsAsString()
public TagMap getKeys()
getKeys
in interface Tagged
visitKeys(KeyValueVisitor)
public void visitKeys(KeyValueVisitor visitor)
Tagged
visitKeys
in interface Tagged
visitor
- The visitor to call.Tagged.getKeys()
public void setKeys(Map<String,String> keys)
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.
public void setKeys(TagMap keys)
keys
- The new key map.public void put(String key, String value)
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.
put
in interface Tagged
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.remove(String)
public void putAll(Map<String,String> tags)
Tagged
Tagged.put(java.lang.String, java.lang.String)
, depending upon the implementation.
By default, this calls Tagged.put(java.lang.String, java.lang.String)
for each map entry.private static int indexOfKey(String[] keys, String key)
keys
- The key array. It is not modified. It may be null to indicate an empty array.key
- The key to search for.public void remove(String key)
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.
public void removeAll()
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.
public final String get(String key)
key
. Replies null, if key
is null.
Replies null, if there is no value for the given key.public final String getIgnoreCase(String key)
key
- The key to getpublic final int getNumKeys()
Tagged
getNumKeys
in interface Tagged
public final Collection<String> keySet()
Tagged
keySet
in interface Tagged
Tagged.keys()
public Stream<String> keys()
Tagged
keys
in interface Tagged
Tagged.keySet()
public final boolean hasKeys()
public boolean hasKey(String key)
key
.hasKey
in interface Tagged
key
- the keykey
Tagged.hasTag(String)
public boolean hasKey(String... keys)
keys
.keys
- the keyskeys
protected abstract void keysChangedImpl(Map<String,String> originalKeys)
originalKeys
- original tagspublic static Collection<String> getUninterestingKeys()
public static Collection<String> getDiscardableKeys()
public static Collection<String> getWorkInProgressKeys()
public static boolean isUninterestingKey(String key)
key
- The key to checkpublic Map<String,String> getInterestingTags()
IPrimitive
Tagged.getKeys()
for which key
does not fulfill uninteresting criteria.getInterestingTags
in interface IPrimitive