Class HistoryOsmPrimitive
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive
-
- All Implemented Interfaces:
java.lang.Comparable<HistoryOsmPrimitive>
,PrimitiveId
,Tagged
- Direct Known Subclasses:
HistoryNode
,HistoryRelation
,HistoryWay
public abstract class HistoryOsmPrimitive extends java.lang.Object implements Tagged, java.lang.Comparable<HistoryOsmPrimitive>, PrimitiveId
Represents an immutable OSM primitive in the context of a historical view on OSM data.- Since:
- 1670
-
-
Field Summary
Fields Modifier and Type Field Description private Changeset
changeset
private long
changesetId
private long
id
private java.util.Map<java.lang.String,java.lang.String>
tags
private java.time.Instant
timestamp
private User
user
private long
version
private boolean
visible
-
Fields inherited from interface org.openstreetmap.josm.data.osm.Tagged
MAX_TAG_LENGTH
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp)
Constructs a newHistoryOsmPrimitive
.protected
HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp, boolean checkHistoricParams)
Constructs a newHistoryOsmPrimitive
with a configurable checking of historic parameters.protected
HistoryOsmPrimitive(OsmPrimitive p)
Constructs a newHistoryOsmPrimitive
from an existingOsmPrimitive
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareTo(HistoryOsmPrimitive o)
protected void
ensurePositiveLong(long value, java.lang.String name)
Checks that value is positive.boolean
equals(java.lang.Object obj)
protected void
fillPrimitiveCommonData(PrimitiveData data)
Fills the attributes common to all primitives with values from this history.static HistoryOsmPrimitive
forOsmPrimitive(OsmPrimitive p)
java.lang.String
get(java.lang.String key)
Replies the value of the given key; null, if there is no value for this keyChangeset
getChangeset()
Returns the changeset for this history primitive.long
getChangesetId()
Returns the changeset id.abstract java.lang.String
getDisplayName(HistoryNameFormatter formatter)
Replies the display name of a primitive formatted byformatter
long
getId()
Returns the id.java.time.Instant
getInstant()
Returns the timestamp.java.util.Map<java.lang.String,java.lang.String>
getKeys()
Replies the map of key/value pairs.java.lang.String
getLocalName()
Replies the a localized name for this primitive given by the value of the tags (in this order) name:lang_COUNTRY_Variant of the current locale name:lang_COUNTRY of the current locale name:lang of the current locale name of the current locale null, if no such tag existsjava.lang.String
getName()
Replies the name of this primitive.int
getNumKeys()
Gets the number of keysPrimitiveId
getPrimitiveId()
Returns the primitive id.java.util.Map<java.lang.String,java.lang.String>
getTags()
Replies the key/value map.long
getUniqueId()
Gets a unique id representing this object (the OSM server id for OSM objects)User
getUser()
Returns the user.long
getVersion()
Returns the version.int
hashCode()
boolean
hasKey(java.lang.String key)
Replies true if there is a tag with keykey
.boolean
hasKeys()
Replies true, if there is at least one key/value pair; false, otherwiseboolean
isNew()
Replies true if this id represents a new primitive.boolean
isVisible()
Determines if the primitive is still visible.java.util.Collection<java.lang.String>
keySet()
Replies the set of keysboolean
matches(long id)
Determines if this history matches given id.boolean
matches(long id, long version)
Determines if this history matches given id and version.void
put(java.lang.String key, java.lang.String value)
Sets a key/value pairsvoid
remove(java.lang.String key)
Removes a given key/value pairvoid
removeAll()
Removes all tagsvoid
setChangeset(Changeset changeset)
Sets the changeset for this history primitive.void
setKeys(java.util.Map<java.lang.String,java.lang.String> keys)
Sets the map of key/value pairsvoid
setTags(java.util.Map<java.lang.String,java.lang.String> tags)
Sets the tags for this history primitive.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.osm.PrimitiveId
getType
-
Methods inherited from interface org.openstreetmap.josm.data.osm.Tagged
hasTag, hasTag, hasTag, hasTag, hasTagDifferent, hasTagDifferent, hasTagDifferent, isKeyFalse, isKeyTrue, keys, put, putAll, visitKeys
-
-
-
-
Constructor Detail
-
HistoryOsmPrimitive
protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp)
Constructs a newHistoryOsmPrimitive
.- Parameters:
id
- the id (> 0 required)version
- the version (> 0 required)visible
- whether the primitive is still visibleuser
- the user (!= null required)changesetId
- the changeset id (> 0 required)timestamp
- the timestamp (!= null required)- Throws:
java.lang.IllegalArgumentException
- if preconditions are violated
-
HistoryOsmPrimitive
protected HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp, boolean checkHistoricParams)
Constructs a newHistoryOsmPrimitive
with a configurable checking of historic parameters. This is needed to build virtual HistoryOsmPrimitives for modified primitives, which do not have a timestamp and a changeset id.- Parameters:
id
- the id (> 0 required)version
- the version (> 0 required)visible
- whether the primitive is still visibleuser
- the user (!= null required)changesetId
- the changeset id (> 0 required ifcheckHistoricParams
is true)timestamp
- the timestamp (!= null required ifcheckHistoricParams
is true)checkHistoricParams
- if true, checks values ofchangesetId
andtimestamp
- Throws:
java.lang.IllegalArgumentException
- if preconditions are violated- Since:
- 5440
-
HistoryOsmPrimitive
protected HistoryOsmPrimitive(OsmPrimitive p)
Constructs a newHistoryOsmPrimitive
from an existingOsmPrimitive
.- Parameters:
p
- the primitive
-
-
Method Detail
-
forOsmPrimitive
public static HistoryOsmPrimitive forOsmPrimitive(OsmPrimitive p)
- Parameters:
p
- the primitive- Returns:
- a new
HistoryNode
,HistoryWay
orHistoryRelation
fromp
.
-
getId
public long getId()
Returns the id.- Returns:
- the id
-
getPrimitiveId
public PrimitiveId getPrimitiveId()
Returns the primitive id.- Returns:
- the primitive id
-
isVisible
public boolean isVisible()
Determines if the primitive is still visible.- Returns:
true
if the primitive is still visible
-
getChangesetId
public long getChangesetId()
Returns the changeset id.- Returns:
- the changeset id
-
getInstant
public java.time.Instant getInstant()
Returns the timestamp.- Returns:
- the timestamp
-
getVersion
public long getVersion()
Returns the version.- Returns:
- the version
-
ensurePositiveLong
protected final void ensurePositiveLong(long value, java.lang.String name)
Checks that value is positive.- Parameters:
value
- value to checkname
- parameter name for error message- Throws:
java.lang.IllegalArgumentException
- ifvalue <= 0
-
matches
public boolean matches(long id, long version)
Determines if this history matches given id and version.- Parameters:
id
- Primitive identifierversion
- Primitive version- Returns:
true
if this history matches given id and version
-
matches
public boolean matches(long id)
Determines if this history matches given id.- Parameters:
id
- Primitive identifier- Returns:
true
if this history matches given id
-
getUniqueId
public final long getUniqueId()
Description copied from interface:PrimitiveId
Gets a unique id representing this object (the OSM server id for OSM objects)- Specified by:
getUniqueId
in interfacePrimitiveId
- Returns:
- the id number
-
isNew
public final boolean isNew()
Description copied from interface:PrimitiveId
Replies true if this id represents a new primitive.- Specified by:
isNew
in interfacePrimitiveId
- Returns:
- true if this id represents a new primitive.
-
compareTo
public int compareTo(HistoryOsmPrimitive o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<HistoryOsmPrimitive>
-
put
public final void put(java.lang.String key, java.lang.String value)
Description copied from interface:Tagged
Sets a key/value pairs
-
get
public final java.lang.String get(java.lang.String key)
Description copied from interface:Tagged
Replies the value of the given key; null, if there is no value for this key
-
hasKey
public final boolean hasKey(java.lang.String key)
Description copied from interface:Tagged
Replies true if there is a tag with keykey
. The value could however be empty. SeeTagged.hasTag(String)
to check for non-empty tags.- Specified by:
hasKey
in interfaceTagged
- Parameters:
key
- the key- Returns:
- true, if there is a tag with key
key
- See Also:
Tagged.hasTag(String)
-
getKeys
public final java.util.Map<java.lang.String,java.lang.String> getKeys()
Description copied from interface:Tagged
Replies the map of key/value pairs. Never null, but may be the empty map.
-
setKeys
public final void setKeys(java.util.Map<java.lang.String,java.lang.String> keys)
Description copied from interface:Tagged
Sets the map of key/value pairs
-
remove
public final void remove(java.lang.String key)
Description copied from interface:Tagged
Removes a given key/value pair
-
hasKeys
public final boolean hasKeys()
Description copied from interface:Tagged
Replies true, if there is at least one key/value pair; false, otherwise
-
keySet
public final java.util.Collection<java.lang.String> keySet()
Description copied from interface:Tagged
Replies the set of keys- Specified by:
keySet
in interfaceTagged
- Returns:
- the set of keys
- See Also:
Tagged.keys()
-
getNumKeys
public int getNumKeys()
Description copied from interface:Tagged
Gets the number of keys- Specified by:
getNumKeys
in interfaceTagged
- Returns:
- The number of keys set for this tagged object.
-
getTags
public java.util.Map<java.lang.String,java.lang.String> getTags()
Replies the key/value map.- Returns:
- the key/value map
-
getChangeset
public Changeset getChangeset()
Returns the changeset for this history primitive.- Returns:
- the changeset for this history primitive
-
setChangeset
public void setChangeset(Changeset changeset)
Sets the changeset for this history primitive.- Parameters:
changeset
- the changeset for this history primitive
-
setTags
public void setTags(java.util.Map<java.lang.String,java.lang.String> tags)
Sets the tags for this history primitive. Removes all tags iftags
is null.- Parameters:
tags
- the tags. May be null.
-
getName
public java.lang.String getName()
Replies the name of this primitive. The default implementation replies the value of the tagname
or null, if this tag is not present.- Returns:
- the name of this primitive
-
getDisplayName
public abstract java.lang.String getDisplayName(HistoryNameFormatter formatter)
Replies the display name of a primitive formatted byformatter
- Parameters:
formatter
- The formatter used to generate a display name- Returns:
- the display name
-
getLocalName
public java.lang.String getLocalName()
Replies the a localized name for this primitive given by the value of the tags (in this order)- name:lang_COUNTRY_Variant of the current locale
- name:lang_COUNTRY of the current locale
- name:lang of the current locale
- name of the current locale
- Returns:
- the name of this primitive
-
fillPrimitiveCommonData
protected void fillPrimitiveCommonData(PrimitiveData data)
Fills the attributes common to all primitives with values from this history.- Parameters:
data
- primitive data to fill
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-