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, versionMAX_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, visitKeysclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitaccept, getBBox, getDisplayName, getDisplayType, getLocalName, getName, getOsmId, getOsmPrimitiveId, getPrimitiveId, hasSameInterestingTags, isMultipolygonhasTag, hasTag, hasTag, hasTag, hasTagDifferent, hasTagDifferent, hasTagDifferent, isKeyFalse, isKeyTrue, putgetTypeclearCachedStyleprivate 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_DIRECTIONSprivate 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()
StylablegetCachedStyle in interface Stylablepublic final void setCachedStyle(StyleCache mappaintStyle)
StylablesetCachedStyle in interface StylablemappaintStyle - the cached stylepublic final boolean isCachedStyleUpToDate()
StylableisCachedStyleUpToDate in interface Stylablepublic final void declareCachedStyleUpToDate()
StylabledeclareCachedStyleUpToDate in interface Stylablevoid setDataset(DataSet dataSet)
dataSet - the parent datasetpublic DataSet getDataSet()
IPrimitivegetDataSet in interface IPrimitivepublic void checkDataset()
protected final void checkDatasetNotReadOnly()
protected boolean writeLock()
protected void writeUnlock(boolean locked)
public void setOsmId(long id, int version)
setOsmId in interface IPrimitivesetOsmId in class AbstractPrimitiveid - 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 AbstractPrimitiveDataIntegrityProblemException - If primitive was already added to the datasetpublic void setUser(User user)
IPrimitivesetUser in interface IPrimitivesetUser in class AbstractPrimitiveuser - the userpublic void setChangesetId(int changesetId)
IPrimitivesetChangesetId in interface IPrimitivesetChangesetId in class AbstractPrimitivechangesetId - the id. >= 0 required.public void setTimestamp(java.util.Date timestamp)
IPrimitivesetTimestamp in interface IPrimitivesetTimestamp in class AbstractPrimitivetimestamp - date of last modificationIPrimitive.getTimestamp()private void updateFlagsNoLock(short flag, boolean value)
protected final void updateFlags(short flag, boolean value)
updateFlags in class AbstractPrimitivepublic 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()
IPrimitiveisDisabled in interface IPrimitivetrue if this object has the "disabled" flag enabledpublic boolean isDisabledAndHidden()
IPrimitiveisDisabledAndHidden in interface IPrimitivetrue 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()
IPrimitiveisPreserved in interface IPrimitivetrue if this object has the "preserved" flag enabledpublic boolean isSelectable()
IPrimitiveA primitive can be selected if all conditions are met:
isSelectable in interface IPrimitivetrue if this object is selectablepublic boolean isDrawable()
IPrimitiveA primitive is drawable if all conditions are met:
isDrawable in interface IPrimitivetrue if this object is drawablepublic void setModified(boolean modified)
IPrimitivesetModified in interface IPrimitivesetModified in class AbstractPrimitivemodified - true, if this primitive is to be modifiedpublic void setVisible(boolean visible)
IPrimitivesetVisible in interface IPrimitivesetVisible in class AbstractPrimitivevisible - true if this primitive is visibleIPrimitive.isVisible()public void setDeleted(boolean deleted)
IPrimitivesetDeleted in interface IPrimitivesetDeleted in class AbstractPrimitivedeleted - true, if this primitive is deleted; false, otherwiseprotected final void setIncomplete(boolean incomplete)
AbstractPrimitivesetIncomplete in class AbstractPrimitiveincomplete - incomplete flag valuepublic boolean isSelected()
IPrimitiveisSelected in interface IPrimitivepublic boolean isMemberOfSelected()
IPrimitiveisMemberOfSelected in interface IPrimitivetrue if this primitive is a member of a selected relation, false otherwisepublic boolean isOuterMemberOfSelected()
IPrimitiveisOuterMemberOfSelected in interface IPrimitivetrue if this primitive is an outer member of a selected multipolygon relation, false otherwiseprivate boolean isOuterMemberOfMultipolygon(OsmPrimitive ref)
public void setHighlighted(boolean highlighted)
IPrimitivesetHighlighted in interface IPrimitivehighlighted - The new highlight flag.public boolean isHighlighted()
IPrimitiveisHighlighted in interface IPrimitiveprivate static SearchCompiler.Match compileDirectionKeys(java.lang.String prefName, java.lang.String defaultValue) throws java.lang.AssertionError
java.lang.AssertionErrorprivate void updateTagged()
private void updateAnnotated()
public boolean isTagged()
IPrimitiveisTagged in interface IPrimitivepublic boolean isAnnotated()
IPrimitiveisAnnotated in interface IPrimitiveprivate void updateDirectionFlags()
public boolean hasDirectionKeys()
IPrimitivehasDirectionKeys in interface IPrimitivetrue if this object has direction dependent tagspublic boolean reversedDirection()
IPrimitivereversedDirection in interface IPrimitivetrue if this object has the "reversed direction" flag enabledpublic final void setKeys(TagMap keys)
AbstractPrimitivesetKeys in class AbstractPrimitivekeys - The new key map.public final void setKeys(java.util.Map<java.lang.String,java.lang.String> keys)
AbstractPrimitivekeys.
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 TaggedsetKeys in class AbstractPrimitivekeys - 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)
AbstractPrimitiveAbstractPrimitive.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 Taggedput in class AbstractPrimitivekey - 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)
AbstractPrimitiveNote 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 Taggedremove in class AbstractPrimitivekey - the key to be removed. Ignored, if key is null.public final void removeAll()
AbstractPrimitiveNote 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 TaggedremoveAll in class AbstractPrimitiveprotected void keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
AbstractPrimitivekeysChangedImpl in class AbstractPrimitiveoriginalKeys - 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)
IPrimitiveWay wnew = new Way(existingWay)getReferrers in interface IPrimitiveallowWithoutDataset - 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()
IPrimitivegetReferrers in interface IPrimitivepublic void visitReferrers(OsmPrimitiveVisitor visitor)
Visits visitor for all referrers.
visitor - the visitor. Ignored, if null.public void visitReferrers(PrimitiveVisitor visitor)
IPrimitiveVisits visitor for all referrers.
visitReferrers in interface IPrimitivevisitor - 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 AbstractPrimitivepublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.util.Collection<java.lang.String> getTemplateKeys()
TemplateEngineDataProvidergetTemplateKeys in interface TemplateEngineDataProviderpublic java.lang.Object getTemplateValue(java.lang.String name, boolean special)
TemplateEngineDataProvidergetTemplateValue in interface TemplateEngineDataProvidername - 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)
TemplateEngineDataProviderTemplateEngineDataProvider.evaluateCondition in interface TemplateEngineDataProvidercondition - 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