public abstract class AbstractPrimitive extends java.lang.Object implements IPrimitive
Modifier and Type | Field and Description |
---|---|
protected int |
changesetId
The id of the changeset this primitive was last uploaded to.
|
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.
|
private static java.util.concurrent.atomic.AtomicLong |
idCounter |
protected java.lang.String[] |
keys
The key/value list for this primitive.
|
protected int |
timestamp |
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.
|
MAX_TAG_LENGTH
Constructor and Description |
---|
AbstractPrimitive() |
Modifier and Type | Method and Description |
---|---|
static void |
advanceUniqueId(long newId)
Advances the current primitive unique id to skip a range of values.
|
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.
|
static long |
currentUniqueId()
Returns the current primitive unique id.
|
(package private) static long |
generateUniqueId()
Generates a new primitive unique id.
|
java.lang.String |
get(java.lang.String key)
Replies the value for key
key . |
int |
getChangesetId()
Replies the id of the changeset this primitive was last uploaded to.
|
protected java.lang.String |
getFlagsAsString() |
long |
getId()
Replies the id of this primitive.
|
java.lang.String |
getIgnoreCase(java.lang.String key)
Gets a key ignoring the case of the key
|
TagMap |
getKeys()
Replies the map of key/value pairs.
|
java.lang.String |
getLocalName()
Replies a localized name for this primitive given by the value of the name tags
accessed from very specific (language variant) to more generic (default name).
|
java.lang.String |
getName()
Replies the name of this primitive.
|
int |
getNumKeys()
Gets the number of keys
|
PrimitiveId |
getPrimitiveId()
Replies the unique primitive id for this primitive
|
int |
getRawTimestamp()
Time of last modification to this object.
|
java.util.Date |
getTimestamp()
Time of last modification to this object.
|
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.
|
boolean |
hasKey(java.lang.String... keys)
Replies true if this primitive has a tag any of the
keys . |
boolean |
hasKey(java.lang.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.
|
boolean |
hasTag(java.lang.String key,
java.util.Collection<java.lang.String> values)
Tests whether this primitive contains a tag consisting of
key and any of values . |
boolean |
hasTag(java.lang.String key,
java.lang.String... values)
Tests whether this primitive contains a tag consisting of
key and any of values . |
boolean |
hasTag(java.lang.String key,
java.lang.String value)
Tests whether this primitive contains a tag consisting of
key and value . |
boolean |
hasTagDifferent(java.lang.String key,
java.util.Collection<java.lang.String> values)
Tests whether this primitive contains a tag consisting of
key and none of values . |
boolean |
hasTagDifferent(java.lang.String key,
java.lang.String... values)
Tests whether this primitive contains a tag consisting of
key and none of values . |
boolean |
hasTagDifferent(java.lang.String key,
java.lang.String value)
Tests whether this primitive contains a tag consisting of
key and a value different from value . |
private static int |
indexOfKey(java.lang.String[] keys,
java.lang.String key)
Scans a key/value array for a given key.
|
boolean |
isDeleted()
Replies
true , if the object has been deleted. |
boolean |
isIncomplete()
Determines if this primitive is incomplete.
|
boolean |
isKeyFalse(java.lang.String key)
Returns true if the
key corresponds to an OSM false value. |
boolean |
isKeyTrue(java.lang.String key)
Returns true if the
key corresponds to an OSM true value. |
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. |
boolean |
isUsable()
Replies
true , if the object is usable
(i.e. |
boolean |
isVisible()
Checks if object is known to the server.
|
protected abstract void |
keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
What to do, when the tags have changed by one of the tag-changing methods.
|
java.util.Collection<java.lang.String> |
keySet()
Replies the set of keys
|
void |
put(java.lang.String key,
java.lang.String value)
Set the given value to the given key.
|
void |
remove(java.lang.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.
|
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 |
setKeys(java.util.Map<java.lang.String,java.lang.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(java.util.Date timestamp)
Sets time of last modification to this object
|
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.
|
protected void |
updateFlags(short flag,
boolean value) |
void |
visitKeys(KeyValueVisitor visitor)
Calls the visitor for every key/value pair of this primitive.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
accept, getDisplayName, getDisplayType
getType
private static final java.util.concurrent.atomic.AtomicLong idCounter
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
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 long id
protected User user
protected int version
protected int changesetId
protected int timestamp
protected volatile java.lang.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)public AbstractPrimitive()
static long generateUniqueId()
public static long currentUniqueId()
public static void advanceUniqueId(long newId)
newId
- new unique idjava.lang.IllegalArgumentException
- if newId is greater than current unique idpublic 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
setOsmId
in interface IPrimitive
id
- the id. > 0 requiredversion
- the version > 0 requiredpublic void clearOsmMetadata()
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.public PrimitiveId getPrimitiveId()
IPrimitive
getPrimitiveId
in interface IPrimitive
public void setTimestamp(java.util.Date timestamp)
IPrimitive
setTimestamp
in interface IPrimitive
timestamp
- date of last modificationIPrimitive.getTimestamp()
public void setRawTimestamp(int timestamp)
IPrimitive
setRawTimestamp
in interface IPrimitive
timestamp
- date of last modificationIPrimitive.getRawTimestamp()
public java.util.Date getTimestamp()
IPrimitive
getTimestamp
in interface IPrimitive
IPrimitive.setTimestamp(java.util.Date)
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)
public 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
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
otherwiseprotected java.lang.String getFlagsAsString()
public TagMap getKeys()
getKeys
in interface Tagged
visitKeys(KeyValueVisitor)
public void visitKeys(KeyValueVisitor visitor)
visitor
- The visitor to call.getKeys()
public void setKeys(java.util.Map<java.lang.String,java.lang.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(java.lang.String key, java.lang.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)
private static int indexOfKey(java.lang.String[] keys, java.lang.String key)
keys
- The key array. It is not modified. It may be null to indicate an emtpy array.key
- The key to search for.public void remove(java.lang.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 java.lang.String get(java.lang.String key)
key
. Replies null, if key
is null.
Replies null, if there is no value for the given key.public final boolean isKeyTrue(java.lang.String key)
key
corresponds to an OSM true value.key
- OSM keytrue
if the key
corresponds to an OSM true valueOsmUtils.isTrue(String)
public final boolean isKeyFalse(java.lang.String key)
key
corresponds to an OSM false value.key
- OSM keytrue
if the key
corresponds to an OSM false valueOsmUtils.isFalse(String)
public final java.lang.String getIgnoreCase(java.lang.String key)
key
- The key to getpublic final int getNumKeys()
public final java.util.Collection<java.lang.String> keySet()
Tagged
public final boolean hasKeys()
public boolean hasKey(java.lang.String key)
key
.hasKey
in interface Tagged
key
- the keykey
Tagged.hasTag(String)
public boolean hasKey(java.lang.String... keys)
keys
.keys
- the keyskeys
protected abstract void keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
originalKeys
- original tagspublic java.lang.String getName()
IPrimitive
name
or null, if this tag is not present.getName
in interface IPrimitive
public java.lang.String getLocalName()
IPrimitive
getLocalName
in interface IPrimitive
null
if no name existsLanguageInfo.getLanguageCodes(java.util.Locale)
public boolean hasTag(java.lang.String key, java.lang.String value)
key
and value
.key
- the key forming the tag.value
- value forming the tag.key
and value
.public boolean hasTag(java.lang.String key, java.lang.String... values)
key
and any of values
.key
- the key forming the tag.values
- one or many values forming the tag.key
and any of values
.public boolean hasTag(java.lang.String key, java.util.Collection<java.lang.String> values)
key
and any of values
.key
- the key forming the tag.values
- one or many values forming the tag.key
and any of values
.public boolean hasTagDifferent(java.lang.String key, java.lang.String value)
key
and a value different from value
.key
- the key forming the tag.value
- value not forming the tag.key
and a value different from value
.public boolean hasTagDifferent(java.lang.String key, java.lang.String... values)
key
and none of values
.key
- the key forming the tag.values
- one or many values forming the tag.key
and none of values
.public boolean hasTagDifferent(java.lang.String key, java.util.Collection<java.lang.String> values)
key
and none of values
.key
- the key forming the tag.values
- one or many values forming the tag.key
and none of values
.