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 Changesetchangesetprivate longchangesetIdprivate longidprivate java.util.Map<java.lang.String,java.lang.String>tagsprivate java.time.Instanttimestampprivate Useruserprivate longversionprivate booleanvisible-
Fields inherited from interface org.openstreetmap.josm.data.osm.Tagged
MAX_TAG_LENGTH
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp)Constructs a newHistoryOsmPrimitive.protectedHistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, java.time.Instant timestamp, boolean checkHistoricParams)Constructs a newHistoryOsmPrimitivewith a configurable checking of historic parameters.protectedHistoryOsmPrimitive(OsmPrimitive p)Constructs a newHistoryOsmPrimitivefrom an existingOsmPrimitive.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intcompareTo(HistoryOsmPrimitive o)protected voidensurePositiveLong(long value, java.lang.String name)Checks that value is positive.booleanequals(java.lang.Object obj)protected voidfillPrimitiveCommonData(PrimitiveData data)Fills the attributes common to all primitives with values from this history.static HistoryOsmPrimitiveforOsmPrimitive(OsmPrimitive p)java.lang.Stringget(java.lang.String key)Replies the value of the given key; null, if there is no value for this keyChangesetgetChangeset()Returns the changeset for this history primitive.longgetChangesetId()Returns the changeset id.abstract java.lang.StringgetDisplayName(HistoryNameFormatter formatter)Replies the display name of a primitive formatted byformatterlonggetId()Returns the id.java.time.InstantgetInstant()Returns the timestamp.java.util.Map<java.lang.String,java.lang.String>getKeys()Replies the map of key/value pairs.java.lang.StringgetLocalName()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.StringgetName()Replies the name of this primitive.intgetNumKeys()Gets the number of keysPrimitiveIdgetPrimitiveId()Returns the primitive id.java.util.Map<java.lang.String,java.lang.String>getTags()Replies the key/value map.longgetUniqueId()Gets a unique id representing this object (the OSM server id for OSM objects)UsergetUser()Returns the user.longgetVersion()Returns the version.inthashCode()booleanhasKey(java.lang.String key)Replies true if there is a tag with keykey.booleanhasKeys()Replies true, if there is at least one key/value pair; false, otherwisebooleanisNew()Replies true if this id represents a new primitive.booleanisVisible()Determines if the primitive is still visible.java.util.Collection<java.lang.String>keySet()Replies the set of keysbooleanmatches(long id)Determines if this history matches given id.booleanmatches(long id, long version)Determines if this history matches given id and version.voidput(java.lang.String key, java.lang.String value)Sets a key/value pairsvoidremove(java.lang.String key)Removes a given key/value pairvoidremoveAll()Removes all tagsvoidsetChangeset(Changeset changeset)Sets the changeset for this history primitive.voidsetKeys(java.util.Map<java.lang.String,java.lang.String> keys)Sets the map of key/value pairsvoidsetTags(java.util.Map<java.lang.String,java.lang.String> tags)Sets the tags for this history primitive.java.lang.StringtoString()-
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 newHistoryOsmPrimitivewith 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 ifcheckHistoricParamsis true)timestamp- the timestamp (!= null required ifcheckHistoricParamsis true)checkHistoricParams- if true, checks values ofchangesetIdandtimestamp- Throws:
java.lang.IllegalArgumentException- if preconditions are violated- Since:
- 5440
-
HistoryOsmPrimitive
protected HistoryOsmPrimitive(OsmPrimitive p)
Constructs a newHistoryOsmPrimitivefrom an existingOsmPrimitive.- Parameters:
p- the primitive
-
-
Method Detail
-
forOsmPrimitive
public static HistoryOsmPrimitive forOsmPrimitive(OsmPrimitive p)
- Parameters:
p- the primitive- Returns:
- a new
HistoryNode,HistoryWayorHistoryRelationfromp.
-
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:
trueif 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:
trueif 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:
trueif this history matches given id
-
getUniqueId
public final long getUniqueId()
Description copied from interface:PrimitiveIdGets a unique id representing this object (the OSM server id for OSM objects)- Specified by:
getUniqueIdin interfacePrimitiveId- Returns:
- the id number
-
isNew
public final boolean isNew()
Description copied from interface:PrimitiveIdReplies true if this id represents a new primitive.- Specified by:
isNewin interfacePrimitiveId- Returns:
- true if this id represents a new primitive.
-
compareTo
public int compareTo(HistoryOsmPrimitive o)
- Specified by:
compareToin interfacejava.lang.Comparable<HistoryOsmPrimitive>
-
put
public final void put(java.lang.String key, java.lang.String value)
Description copied from interface:TaggedSets a key/value pairs
-
get
public final java.lang.String get(java.lang.String key)
Description copied from interface:TaggedReplies 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:TaggedReplies 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:
hasKeyin 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:TaggedReplies 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:TaggedSets the map of key/value pairs
-
remove
public final void remove(java.lang.String key)
Description copied from interface:TaggedRemoves a given key/value pair
-
hasKeys
public final boolean hasKeys()
Description copied from interface:TaggedReplies 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:TaggedReplies the set of keys- Specified by:
keySetin interfaceTagged- Returns:
- the set of keys
- See Also:
Tagged.keys()
-
getNumKeys
public int getNumKeys()
Description copied from interface:TaggedGets the number of keys- Specified by:
getNumKeysin 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 iftagsis 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 tagnameor 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-