public abstract class OsmPrimitive extends AbstractPrimitive implements TemplateEngineDataProvider
Node
, Way
, Relation
).
It can be created, deleted and uploaded to the OSM-Server.
Although OsmPrimitive is designed as a base class, it is not to be meant to subclass
it by any other than from the package org.openstreetmap.josm.data.osm
. The available primitives are a fixed set that are given
by the server environment and not an extendible data stuff.Modifier and Type | Field and Description |
---|---|
private DataSet |
dataSet
the parent dataset
|
(package private) static SearchCompiler.Match |
directionKeys
A tagged way that matches this pattern has a direction.
|
private short |
mappaintCacheIdx |
private StyleCache |
mappaintStyle |
private java.lang.Object |
referrers |
private static SearchCompiler.Match |
reversedDirectionKeys
A tagged way that matches this pattern has a direction that is reversed.
|
private static java.lang.String |
SPECIAL_VALUE_ID |
private static java.lang.String |
SPECIAL_VALUE_LOCAL_NAME |
changesetId, FLAG_ANNOTATED, FLAG_DELETED, FLAG_DIRECTION_REVERSED, FLAG_DISABLED, FLAG_DISABLED_TYPE, FLAG_HAS_DIRECTIONS, FLAG_HIDDEN_TYPE, FLAG_HIDE_IF_DISABLED, FLAG_HIGHLIGHTED, FLAG_INCOMPLETE, FLAG_MODIFIED, FLAG_PRESERVED, FLAG_TAGGED, FLAG_VISIBLE, flags, id, keys, timestamp, user, version
MAX_TAG_LENGTH
Modifier | Constructor and Description |
---|---|
protected |
OsmPrimitive(long id,
boolean allowNegativeId)
Creates a new primitive for the given id.
|
protected |
OsmPrimitive(long id,
int version,
boolean allowNegativeId)
Creates a new primitive for the given id and version.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
accept(OsmPrimitiveVisitor visitor)
Implementation of the visitor scheme.
|
protected void |
addReferrer(OsmPrimitive referrer)
Add new referrer.
|
protected abstract void |
addToBBox(BBox box,
java.util.Set<PrimitiveId> visited)
If necessary, extend the bbox to contain this primitive
|
void |
checkDataset()
Throws exception if primitive is not part of the dataset
|
protected void |
checkDatasetNotReadOnly()
Throws exception if primitive is in a read-only dataset
|
void |
clearOsmMetadata()
Clears the metadata, including id and version known to the OSM API.
|
void |
cloneFrom(OsmPrimitive other)
Get and write all attributes from the parameter.
|
private static SearchCompiler.Match |
compileDirectionKeys(java.lang.String prefName,
java.lang.String defaultValue) |
abstract boolean |
concernsArea()
Determines if this primitive semantically concerns an area.
|
void |
declareCachedStyleUpToDate()
Declare that the cached style for this primitive is up to date.
|
private void |
doVisitReferrers(java.util.function.Consumer<OsmPrimitive> visitor) |
boolean |
equals(java.lang.Object obj)
Equal, if the id (and class) is equal.
|
boolean |
evaluateCondition(SearchCompiler.Match condition)
Check if a condition holds for the object represented by this
TemplateEngineDataProvider . |
StyleCache |
getCachedStyle()
Returns the cached style.
|
DataSet |
getDataSet()
Returns the parent data set of this primitive.
|
boolean |
getDisabledType()
Get binary property used internally by the filter mechanism.
|
protected java.lang.String |
getFlagsAsString() |
boolean |
getHiddenType()
Get binary property used internally by the filter mechanism.
|
static java.util.Set<Relation> |
getParentRelations(java.util.Collection<? extends OsmPrimitive> primitives)
Replies the set of referring relations
|
static java.util.Set<OsmPrimitive> |
getReferrer(java.util.Collection<? extends OsmPrimitive> primitives)
Replies the collection of referring primitives for the primitives in
primitives . |
java.util.List<OsmPrimitive> |
getReferrers()
Gets a list of all primitives in the current dataset that reference this primitive.
|
java.util.List<OsmPrimitive> |
getReferrers(boolean allowWithoutDataset)
Find primitives that reference this primitive.
|
java.util.Collection<java.lang.String> |
getTemplateKeys()
Get the collection of all keys that can be mapped to values.
|
java.lang.Object |
getTemplateValue(java.lang.String name,
boolean special)
Map a key to a value given the properties of the object.
|
boolean |
hasAreaTags()
Determines if this primitive has tags denoting an area.
|
boolean |
hasDirectionKeys()
true if this object has direction dependent tags (e.g.
|
boolean |
hasEqualSemanticAttributes(OsmPrimitive other)
Replies true if this primitive and other are equal with respect to their semantic attributes.
|
(package private) boolean |
hasEqualSemanticAttributes(OsmPrimitive other,
boolean testInterestingTagsOnly) |
(package private) boolean |
hasEqualSemanticFlags(OsmPrimitive other) |
boolean |
hasEqualTechnicalAttributes(OsmPrimitive other)
Replies true if this primitive and other are equal with respect to their technical attributes.
|
int |
hashCode()
Return the id plus the class type encoded as hashcode or super's hashcode if id is 0.
|
boolean |
isAnnotated()
Determines if this object is considered "annotated".
|
boolean |
isCachedStyleUpToDate()
Check if the cached style for this primitive is up to date.
|
boolean |
isDisabled()
Replies true, if this primitive is disabled.
|
boolean |
isDisabledAndHidden()
Replies true, if this primitive is disabled and marked as completely hidden on the map.
|
boolean |
isDrawable()
Determines if this object is drawable.
|
boolean |
isHighlighted()
Checks if the highlight flag for this primitive was set
|
boolean |
isMemberOfSelected()
Determines if this primitive is a member of a selected relation.
|
protected boolean |
isNodeReferredByWays(int n)
Return true, if this primitive is a node referred by at least n ways
|
private boolean |
isOuterMemberOfMultipolygon(OsmPrimitive ref) |
boolean |
isOuterMemberOfSelected()
Determines if this primitive is an outer member of a selected multipolygon relation.
|
abstract boolean |
isOutsideDownloadArea()
Tests if this primitive lies outside of the downloaded area of its
DataSet . |
boolean |
isPreserved()
Replies true, if this primitive is preserved from filtering.
|
boolean |
isSelectable()
Determines if this object is selectable.
|
boolean |
isSelected()
Determines whether the primitive is selected
|
boolean |
isTagged()
Determines if this object is considered "tagged".
|
protected 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.
|
void |
load(PrimitiveData data)
Loads (clone) this primitive from provided PrimitiveData
|
void |
mergeFrom(OsmPrimitive other)
Merges the technical and semantical attributes from
other onto this. |
void |
put(java.lang.String key,
java.lang.String value)
Set the given value to the given key.
|
private <T extends OsmPrimitive> |
referrers(boolean allowWithoutDataset,
java.lang.Class<T> filter) |
<T extends OsmPrimitive> |
referrers(java.lang.Class<T> filter)
Gets all primitives in the current dataset that reference this primitive.
|
void |
remove(java.lang.String key)
Remove the given key from the list
|
void |
removeAll()
Removes all keys from this primitive.
|
protected void |
removeReferrer(OsmPrimitive referrer)
Remove referrer.
|
boolean |
reversedDirection()
true if this object has the "reversed direction" flag enabled
|
abstract PrimitiveData |
save()
Save parameters of this primitive to the transport object
|
protected void |
saveCommonAttributes(PrimitiveData data)
Save common parameters of primitives to the transport object
|
void |
setCachedStyle(StyleCache mappaintStyle)
Sets the cached style.
|
void |
setChangesetId(int changesetId)
Sets the changeset id of this primitive.
|
(package private) void |
setDataset(DataSet dataSet)
This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods
|
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.
|
void |
setHighlighted(boolean highlighted)
Updates the highlight flag for this primitive.
|
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 |
setPreserved(boolean isPreserved)
Set binary property used internally by the filter mechanism.
|
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.
|
boolean |
unsetDisabledState()
Remove the disabled flag from the primitive.
|
private void |
updateAnnotated() |
private void |
updateDirectionFlags() |
protected void |
updateFlags(short flag,
boolean value) |
private void |
updateFlagsNoLock(short flag,
boolean value) |
abstract void |
updatePosition()
Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
|
private void |
updateTagged() |
void |
visitReferrers(OsmPrimitiveVisitor visitor)
Visits
visitor for all referrers. |
void |
visitReferrers(PrimitiveVisitor visitor)
Visits
visitor for all referrers. |
protected boolean |
writeLock() |
protected void |
writeUnlock(boolean locked) |
advanceUniqueId, cloneFrom, currentUniqueId, doGet, generateUniqueId, get, getChangesetId, getDiscardableKeys, getId, getIgnoreCase, getInterestingTags, getKeys, getNumKeys, getRawTimestamp, getTimestamp, getUninterestingKeys, getUniqueId, getUser, getVersion, getWorkInProgressKeys, hasKey, hasKey, hasKeys, isDeleted, isIncomplete, isModified, isNew, isNewOrUndeleted, isTimestampEmpty, isUndeleted, isUninterestingKey, isUsable, isVisible, keySet, setRawTimestamp, visitKeys
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
accept, getBBox, getDisplayName, getDisplayType, getLocalName, getName, getOsmId, getOsmPrimitiveId, getPrimitiveId, hasSameInterestingTags, isMultipolygon
hasTag, hasTag, hasTag, hasTag, hasTagDifferent, hasTagDifferent, hasTagDifferent, isKeyFalse, isKeyTrue, put
getType
clearCachedStyle
private static final java.lang.String SPECIAL_VALUE_ID
private static final java.lang.String SPECIAL_VALUE_LOCAL_NAME
static volatile SearchCompiler.Match directionKeys
AbstractPrimitive.FLAG_HAS_DIRECTIONS
private static volatile SearchCompiler.Match reversedDirectionKeys
This pattern should be a subset of directionKeys
private StyleCache mappaintStyle
private short mappaintCacheIdx
private java.lang.Object referrers
protected OsmPrimitive(long id, boolean allowNegativeId)
id
- the idallowNegativeId
- true
to allow negative idjava.lang.IllegalArgumentException
- if id < 0 and allowNegativeId is falseprotected OsmPrimitive(long id, int version, boolean allowNegativeId)
id
- the idversion
- the version (positive integer)allowNegativeId
- true
to allow negative idjava.lang.IllegalArgumentException
- if id < 0 and allowNegativeId is falsepublic static java.util.Set<OsmPrimitive> getReferrer(java.util.Collection<? extends OsmPrimitive> primitives)
primitives
.primitives
- the collection of primitives.primitives
;
empty set if primitives is null or if there are no referring primitivespublic final StyleCache getCachedStyle()
Stylable
getCachedStyle
in interface Stylable
public final void setCachedStyle(StyleCache mappaintStyle)
Stylable
setCachedStyle
in interface Stylable
mappaintStyle
- the cached stylepublic final boolean isCachedStyleUpToDate()
Stylable
isCachedStyleUpToDate
in interface Stylable
public final void declareCachedStyleUpToDate()
Stylable
declareCachedStyleUpToDate
in interface Stylable
void setDataset(DataSet dataSet)
dataSet
- the parent datasetpublic DataSet getDataSet()
IPrimitive
getDataSet
in interface IPrimitive
public void checkDataset()
protected final void checkDatasetNotReadOnly()
protected boolean writeLock()
protected void writeUnlock(boolean locked)
public void setOsmId(long id, int version)
setOsmId
in interface IPrimitive
setOsmId
in class AbstractPrimitive
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()
DataSet
.clearOsmMetadata
in class AbstractPrimitive
DataIntegrityProblemException
- If primitive was already added to the datasetpublic void setUser(User user)
IPrimitive
setUser
in interface IPrimitive
setUser
in class AbstractPrimitive
user
- the userpublic void setChangesetId(int changesetId)
IPrimitive
setChangesetId
in interface IPrimitive
setChangesetId
in class AbstractPrimitive
changesetId
- the id. >= 0 required.public void setTimestamp(java.util.Date timestamp)
IPrimitive
setTimestamp
in interface IPrimitive
setTimestamp
in class AbstractPrimitive
timestamp
- date of last modificationIPrimitive.getTimestamp()
private void updateFlagsNoLock(short flag, boolean value)
protected final void updateFlags(short flag, boolean value)
updateFlags
in class AbstractPrimitive
public boolean setDisabledState(boolean hidden)
hidden
- if the primitive should be completely hidden from view or
just shown in gray color.public boolean unsetDisabledState()
true
if a change occurredpublic void setDisabledType(boolean isExplicit)
isExplicit
- new "disabled type" flag valuepublic void setHiddenType(boolean isExplicit)
isExplicit
- new "hidden type" flag valuepublic void setPreserved(boolean isPreserved)
isPreserved
- new "preserved" flag valuepublic boolean isDisabled()
IPrimitive
isDisabled
in interface IPrimitive
true
if this object has the "disabled" flag enabledpublic boolean isDisabledAndHidden()
IPrimitive
isDisabledAndHidden
in interface IPrimitive
true
if this object has both the "disabled" and "hide if disabled" flags enabledpublic boolean getHiddenType()
true
if this object has the "hidden type" flag enabledpublic boolean getDisabledType()
true
if this object has the "disabled type" flag enabledpublic boolean isPreserved()
IPrimitive
isPreserved
in interface IPrimitive
true
if this object has the "preserved" flag enabledpublic boolean isSelectable()
IPrimitive
A primitive can be selected if all conditions are met:
isSelectable
in interface IPrimitive
true
if this object is selectablepublic boolean isDrawable()
IPrimitive
A primitive is complete if all conditions are met:
isDrawable
in interface IPrimitive
true
if this object is drawablepublic void setModified(boolean modified)
IPrimitive
setModified
in interface IPrimitive
setModified
in class AbstractPrimitive
modified
- true, if this primitive is to be modifiedpublic void setVisible(boolean visible)
IPrimitive
setVisible
in interface IPrimitive
setVisible
in class AbstractPrimitive
visible
- true
if this primitive is visibleIPrimitive.isVisible()
public void setDeleted(boolean deleted)
IPrimitive
setDeleted
in interface IPrimitive
setDeleted
in class AbstractPrimitive
deleted
- true, if this primitive is deleted; false, otherwiseprotected final void setIncomplete(boolean incomplete)
AbstractPrimitive
setIncomplete
in class AbstractPrimitive
incomplete
- incomplete flag valuepublic boolean isSelected()
IPrimitive
isSelected
in interface IPrimitive
public boolean isMemberOfSelected()
IPrimitive
isMemberOfSelected
in interface IPrimitive
true
if this primitive is a member of a selected relation, false
otherwisepublic boolean isOuterMemberOfSelected()
IPrimitive
isOuterMemberOfSelected
in interface IPrimitive
true
if this primitive is an outer member of a selected multipolygon relation, false
otherwiseprivate boolean isOuterMemberOfMultipolygon(OsmPrimitive ref)
public void setHighlighted(boolean highlighted)
IPrimitive
setHighlighted
in interface IPrimitive
highlighted
- The new highlight flag.public boolean isHighlighted()
IPrimitive
isHighlighted
in interface IPrimitive
private static SearchCompiler.Match compileDirectionKeys(java.lang.String prefName, java.lang.String defaultValue) throws java.lang.AssertionError
java.lang.AssertionError
private void updateTagged()
private void updateAnnotated()
public boolean isTagged()
IPrimitive
isTagged
in interface IPrimitive
public boolean isAnnotated()
IPrimitive
isAnnotated
in interface IPrimitive
private void updateDirectionFlags()
public boolean hasDirectionKeys()
IPrimitive
hasDirectionKeys
in interface IPrimitive
true
if this object has direction dependent tagspublic boolean reversedDirection()
IPrimitive
reversedDirection
in interface IPrimitive
true
if this object has the "reversed direction" flag enabledpublic final void setKeys(TagMap keys)
AbstractPrimitive
setKeys
in class AbstractPrimitive
keys
- The new key map.public final void setKeys(java.util.Map<java.lang.String,java.lang.String> keys)
AbstractPrimitive
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.
setKeys
in interface Tagged
setKeys
in class AbstractPrimitive
keys
- the key/value pairs to set. If null, removes all existing key/value pairs.public final void put(java.lang.String key, java.lang.String value)
AbstractPrimitive
AbstractPrimitive.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
put
in class AbstractPrimitive
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.AbstractPrimitive.remove(String)
public final void remove(java.lang.String key)
AbstractPrimitive
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.
remove
in interface Tagged
remove
in class AbstractPrimitive
key
- the key to be removed. Ignored, if key is null.public final void removeAll()
AbstractPrimitive
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.
removeAll
in interface Tagged
removeAll
in class AbstractPrimitive
protected void keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
AbstractPrimitive
keysChangedImpl
in class AbstractPrimitive
originalKeys
- original tagsprotected void addReferrer(OsmPrimitive referrer)
referrer
- The referrer to addprotected void removeReferrer(OsmPrimitive referrer)
referrer
- The referrer to removeprivate <T extends OsmPrimitive> java.util.stream.Stream<T> referrers(boolean allowWithoutDataset, java.lang.Class<T> filter)
public final <T extends OsmPrimitive> java.util.stream.Stream<T> referrers(java.lang.Class<T> filter)
T
- type of primitivesfilter
- restrict primitives to subclassespublic final java.util.List<OsmPrimitive> getReferrers(boolean allowWithoutDataset)
IPrimitive
Way wnew = new Way(existingWay)
getReferrers
in interface IPrimitive
allowWithoutDataset
- If true, method will return empty list if primitive is not part of the dataset. If false,
exception will be thrown in this casepublic final java.util.List<OsmPrimitive> getReferrers()
IPrimitive
getReferrers
in interface IPrimitive
public void visitReferrers(OsmPrimitiveVisitor visitor)
Visits visitor
for all referrers.
visitor
- the visitor. Ignored, if null.public void visitReferrers(PrimitiveVisitor visitor)
IPrimitive
Visits visitor
for all referrers.
visitReferrers
in interface IPrimitive
visitor
- the visitor. Ignored, if null.private void doVisitReferrers(java.util.function.Consumer<OsmPrimitive> visitor)
protected final boolean isNodeReferredByWays(int n)
n
- Minimal number of ways to return true. Must be positivetrue
if this primitive is referred by at least n wayspublic abstract void accept(OsmPrimitiveVisitor visitor)
visitor
- The visitor from which the visit() function must be called.public void cloneFrom(OsmPrimitive other)
other
- other primitivepublic void mergeFrom(OsmPrimitive other)
other
onto this.
Both this and other must be new, or both must be assigned an OSM ID. If both this and other
have an assigned OSM id, the IDs have to be the same.other
- the other primitive. Must not be null.java.lang.IllegalArgumentException
- if other is null.DataIntegrityProblemException
- if either this is new and other is not, or other is new and this is notDataIntegrityProblemException
- if other isn't new and other.getId() != this.getId()public final boolean hasEqualSemanticAttributes(OsmPrimitive other)
other
- other primitive to compareboolean hasEqualSemanticFlags(OsmPrimitive other)
boolean hasEqualSemanticAttributes(OsmPrimitive other, boolean testInterestingTagsOnly)
public boolean hasEqualTechnicalAttributes(OsmPrimitive other)
other
- the other primitivepublic void load(PrimitiveData data)
data
- The object which should be clonedpublic abstract PrimitiveData save()
protected void saveCommonAttributes(PrimitiveData data)
data
- The object to save the data intopublic abstract void updatePosition()
protected java.lang.String getFlagsAsString()
getFlagsAsString
in class AbstractPrimitive
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.util.Collection<java.lang.String> getTemplateKeys()
TemplateEngineDataProvider
getTemplateKeys
in interface TemplateEngineDataProvider
public java.lang.Object getTemplateValue(java.lang.String name, boolean special)
TemplateEngineDataProvider
getTemplateValue
in interface TemplateEngineDataProvider
name
- the key to mapspecial
- if the key is a "special:*" keyword that is used
to get certain information or automated behaviorspecial
is truepublic boolean evaluateCondition(SearchCompiler.Match condition)
TemplateEngineDataProvider
TemplateEngineDataProvider
.evaluateCondition
in interface TemplateEngineDataProvider
condition
- the condition to check (which is a search expression)public static java.util.Set<Relation> getParentRelations(java.util.Collection<? extends OsmPrimitive> primitives)
primitives
- primitives to fetch relations frompublic final boolean hasAreaTags()
true
if this primitive has tags denoting an area, false
otherwise.public abstract boolean concernsArea()
true
if this primitive semantically concerns an area, according to its type, geometry and tags, false
otherwise.public abstract boolean isOutsideDownloadArea()
DataSet
.true
if this primitive lies outside of the downloaded areaprotected abstract void addToBBox(BBox box, java.util.Set<PrimitiveId> visited)
box
- a bbox instancevisited
- a set of visited members or null