public abstract class AbstractPrimitive extends java.lang.Object implements IPrimitive
Modifier and Type | Class and Description |
---|---|
static interface |
AbstractPrimitive.KeyValueVisitor
This is a visitor that can be used to loop over the keys/values of this primitive.
|
Modifier and Type | Field and Description |
---|---|
protected int |
changesetId
The id of the changeset this primitive was last uploaded to.
|
protected static int |
FLAG_DELETED
An object that was deleted by the user.
|
protected static int |
FLAG_INCOMPLETE
A primitive is incomplete if we know its id and type, but nothing more.
|
protected static int |
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 int |
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.
|
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.
|
(package private) static long |
generateUniqueId() |
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.
|
OsmPrimitiveType |
getDisplayType() |
protected java.lang.String |
getFlagsAsString() |
long |
getId()
Replies the id of this primitive.
|
java.lang.String |
getIgnoreCase(java.lang.String key) |
java.util.Map<java.lang.String,java.lang.String> |
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() |
PrimitiveId |
getPrimitiveId()
Replies the unique primitive id for this primitive
|
int |
getRawTimestamp() |
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 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 values . |
boolean |
isDeleted()
Replies
true , if the object has been deleted. |
boolean |
isIncomplete() |
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()
Replies true if this id represents a new primitive.
|
boolean |
isNewOrUndeleted() |
boolean |
isTimestampEmpty() |
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 |
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) |
void |
setTimestamp(java.util.Date timestamp) |
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(int flag,
boolean value) |
void |
visitKeys(AbstractPrimitive.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
getType
private static final java.util.concurrent.atomic.AtomicLong idCounter
protected static final int FLAG_MODIFIED
protected static final int FLAG_VISIBLE
protected static final int FLAG_DELETED
protected static final int FLAG_INCOMPLETE
protected volatile short flags
protected long id
protected User user
protected int version
protected int changesetId
protected int timestamp
protected java.lang.String[] keys
public AbstractPrimitive()
static long generateUniqueId()
public void cloneFrom(AbstractPrimitive other)
other
- the primitive to clone data frompublic int getVersion()
getVersion
in interface IPrimitive
PrimitiveData.setVersion(int)
public long getId()
getId
in interface IPrimitive
public long getUniqueId()
getUniqueId
in interface PrimitiveId
public boolean isNew()
PrimitiveId
isNew
in interface PrimitiveId
public boolean isNewOrUndeleted()
isNewOrUndeleted
in interface IPrimitive
isNew()
,
isUndeleted()
public void setOsmId(long id, int version)
setOsmId
in interface IPrimitive
id
- the id. > 0 requiredversion
- the version > 0 requiredjava.lang.IllegalArgumentException
- if id <= 0java.lang.IllegalArgumentException
- if version <= 0DataIntegrityProblemException
- if id is changed and primitive was already added to the datasetpublic void clearOsmMetadata()
public User getUser()
getUser
in interface IPrimitive
public void setUser(User user)
setUser
in interface IPrimitive
user
- the userpublic int getChangesetId()
getChangesetId
in interface IPrimitive
public void setChangesetId(int changesetId)
setChangesetId
in interface IPrimitive
changesetId
- the id. >= 0 required.java.lang.IllegalStateException
- if this primitive is new.java.lang.IllegalArgumentException
- if id < 0public PrimitiveId getPrimitiveId()
getPrimitiveId
in interface IPrimitive
public OsmPrimitiveType getDisplayType()
public void setTimestamp(java.util.Date timestamp)
setTimestamp
in interface IPrimitive
public void setRawTimestamp(int timestamp)
setRawTimestamp
in interface IPrimitive
public java.util.Date getTimestamp()
getTimestamp
in interface IPrimitive
public int getRawTimestamp()
getRawTimestamp
in interface IPrimitive
public boolean isTimestampEmpty()
isTimestampEmpty
in interface IPrimitive
protected void updateFlags(int flag, boolean value)
public void setModified(boolean modified)
setModified
in interface IPrimitive
modified
- true, if this primitive is to be modifiedpublic boolean isModified()
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()
true
, if the object has been deleted.isDeleted
in interface IPrimitive
true
, if the object has been deleted.setDeleted(boolean)
public boolean isUndeleted()
true
if the object has been deleted on the server and was undeleted by the user.true
if the object has been undeletedpublic boolean isUsable()
true
, if the object is usable
(i.e. complete and not deleted).true
, if the object is usable.setDeleted(boolean)
public boolean isVisible()
isVisible
in interface IPrimitive
true
, if the object is visible on server.setVisible(boolean)
public void setVisible(boolean visible)
setVisible
in interface IPrimitive
java.lang.IllegalStateException
- if visible is set to false on an primitive with id==0isVisible()
public void setDeleted(boolean deleted)
setDeleted
in interface IPrimitive
deleted
- true, if this primitive is deleted; false, otherwiseprotected void setIncomplete(boolean incomplete)
public boolean isIncomplete()
isIncomplete
in interface IPrimitive
protected java.lang.String getFlagsAsString()
public java.util.Map<java.lang.String,java.lang.String> getKeys()
getKeys
in interface Tagged
visitKeys(KeyValueVisitor)
public void visitKeys(AbstractPrimitive.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.public void put(java.lang.String key, java.lang.String value)
remove(String)
.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 remove(java.lang.String key)
public void removeAll()
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.OsmUtils.isTrue(String)
public final boolean isKeyFalse(java.lang.String key)
key
corresponds to an OSM false value.OsmUtils.isFalse(String)
public final java.lang.String getIgnoreCase(java.lang.String key)
public 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
.key
- the keykey
protected abstract void keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
public java.lang.String getName()
getName
in interface IPrimitive
public java.lang.String getLocalName()
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 values
.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
.