public abstract class OsmPrimitive extends AbstractPrimitive implements Comparable<OsmPrimitive>, 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 |
---|---|
static Predicate<OsmPrimitive> |
allPredicate |
private DataSet |
dataSet
the parent dataset
|
private static SearchCompiler.Match |
directionKeys |
private static Collection<String> |
discardable |
protected static int |
FLAG_ANNOTATED
If the primitive is annotated with a tag such as note, fixme, etc.
|
protected static int |
FLAG_DIRECTION_REVERSED
This flag is only relevant if FLAG_HAS_DIRECTIONS is set.
|
protected static int |
FLAG_DISABLED
An object can be disabled by the filter mechanism.
|
protected static int |
FLAG_DISABLED_TYPE
Flag used internally by the filter mechanism.
|
protected static int |
FLAG_HAS_DIRECTIONS
This flag is set if the primitive is a way and
according to the tags, the direction of the way is important.
|
protected static int |
FLAG_HIDDEN_TYPE
Flag used internally by the filter mechanism.
|
protected static int |
FLAG_HIDE_IF_DISABLED
This flag is only relevant if an object is disabled by the
filter mechanism (i.e. FLAG_DISABLED is set).
|
protected static int |
FLAG_HIGHLIGHTED
When hovering over ways and nodes in add mode, the
"target" objects are visually highlighted.
|
protected static int |
FLAG_TAGGED
If the primitive is tagged.
|
static Predicate<OsmPrimitive> |
isSelectablePredicate |
static Predicate<OsmPrimitive> |
isUsablePredicate
Some predicates, that describe conditions on primitives.
|
int |
mappaintCacheIdx |
StyleCache |
mappaintStyle |
static Predicate<OsmPrimitive> |
modifiedPredicate |
static Predicate<OsmPrimitive> |
multipolygonPredicate |
static Predicate<OsmPrimitive> |
nodePredicate |
static Predicate<OsmPrimitive> |
nonDeletedCompletePredicate |
static Predicate<OsmPrimitive> |
nonDeletedPhysicalPredicate |
static Predicate<OsmPrimitive> |
nonDeletedPredicate |
private Object |
referrers |
static Predicate<OsmPrimitive> |
relationPredicate |
private static SearchCompiler.Match |
reversedDirectionKeys |
private static String |
SPECIAL_VALUE_ID |
private static String |
SPECIAL_VALUE_LOCAL_NAME |
private static Collection<String> |
uninteresting |
static Predicate<OsmPrimitive> |
wayPredicate |
private static Collection<String> |
workinprogress |
changesetId, FLAG_DELETED, FLAG_INCOMPLETE, FLAG_MODIFIED, FLAG_VISIBLE, flags, id, keys, timestamp, user, version
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(Visitor visitor)
Implementation of the visitor scheme.
|
protected void |
addReferrer(OsmPrimitive referrer)
Add new referrer.
|
void |
checkDataset()
Throws exception if primitive is not part of the dataset
|
void |
clearCachedStyle() |
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.
|
abstract boolean |
concernsArea()
Determines if this primitive semantically concerns an area.
|
boolean |
equals(Object obj)
Equal, if the id (and class) is equal.
|
boolean |
evaluateCondition(SearchCompiler.Match condition) |
abstract BBox |
getBBox()
Fetch the bounding box of the primitive
|
DataSet |
getDataSet() |
boolean |
getDisabledType()
Get binary property used internally by the filter mechanism.
|
static Collection<String> |
getDiscardableKeys()
Returns a list of keys which have been deemed uninteresting to the point
that they can be silently removed from data which is being edited.
|
abstract String |
getDisplayName(NameFormatter formatter)
Replies the display name of a primitive formatted by
formatter |
static <T extends OsmPrimitive> |
getFilteredList(Collection<OsmPrimitive> list,
Class<T> type)
Replies the sub-collection of
OsmPrimitive s of type type present in
another collection of OsmPrimitive s. |
static <T extends OsmPrimitive> |
getFilteredSet(Collection<OsmPrimitive> set,
Class<T> type)
Replies the sub-collection of
OsmPrimitive s of type type present in
another collection of OsmPrimitive s. |
protected String |
getFlagsAsString() |
boolean |
getHiddenType()
Get binary property used internally by the filter mechanism.
|
Map<String,String> |
getInterestingTags()
Returns
AbstractPrimitive.getKeys() for which key does not fulfill isUninterestingKey(java.lang.String) . |
static Set<Relation> |
getParentRelations(Collection<? extends OsmPrimitive> primitives)
Replies the set of referring relations
|
static Set<OsmPrimitive> |
getReferrer(Collection<? extends OsmPrimitive> primitives)
Replies the collection of referring primitives for the primitives in
primitives . |
List<OsmPrimitive> |
getReferrers() |
List<OsmPrimitive> |
getReferrers(boolean allowWithoutDataset)
Find primitives that reference this primitive.
|
Collection<String> |
getTemplateKeys() |
Object |
getTemplateValue(String name,
boolean special) |
static Collection<String> |
getUninterestingKeys()
Returns a list of "uninteresting" keys that do not make an object
"tagged".
|
static Collection<String> |
getWorkInProgressKeys()
Returns a list of "work in progress" keys that do not make an object
"tagged" but "annotated".
|
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.
|
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 |
hasSameInterestingTags(OsmPrimitive other)
Replies true if other isn't null and has the same interesting tags (key/value-pairs) as this.
|
boolean |
isAnnotated()
Determines if this object is considered "annotated".
|
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() |
boolean |
isHighlighted() |
boolean |
isMemberOfSelected()
Determines if this primitive is a member of a selected relation.
|
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 |
isReferredByWays(int n)
Return true, if this primitive is referred by at least n ways
|
boolean |
isSelectable() |
boolean |
isSelected() |
boolean |
isTagged()
Determines if this object is considered "tagged".
|
static boolean |
isUninterestingKey(String key)
Determines if key is considered "uninteresting".
|
protected void |
keysChangedImpl(Map<String,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(String key,
String value)
Set the given value to the given key.
|
void |
remove(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() |
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 |
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) |
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(Map<String,String> keys)
Sets the keys of this primitives to the key/value pairs in
keys . |
void |
setOsmId(long id,
int version)
Sets the id and the version of this primitive if it is known to the OSM API.
|
void |
setTimestamp(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.
|
boolean |
unsetDisabledState()
Remove the disabled flag from the primitive.
|
private void |
updateAnnotated() |
private void |
updateDirectionFlags() |
protected void |
updateFlags(int flag,
boolean value) |
private void |
updateFlagsNoLock(int flag,
boolean value) |
abstract void |
updatePosition()
Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)
|
private void |
updateTagged() |
void |
visitReferrers(Visitor visitor)
Visits
visitor for all referrers. |
protected boolean |
writeLock() |
protected void |
writeUnlock(boolean locked) |
cloneFrom, generateUniqueId, get, getChangesetId, getDisplayType, getId, getIgnoreCase, getKeys, getLocalName, getName, getNumKeys, getPrimitiveId, getTimestamp, getUniqueId, getUser, getVersion, hasKey, hasKeys, hasTag, hasTag, hasTag, isDeleted, isIncomplete, isKeyFalse, isKeyTrue, isModified, isNew, isNewOrUndeleted, isTimestampEmpty, isUndeleted, isUsable, isVisible, keySet, setModified
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
compareTo
accept
getType
private static final String SPECIAL_VALUE_ID
private static final String SPECIAL_VALUE_LOCAL_NAME
protected static final int FLAG_DISABLED
protected static final int FLAG_HIDE_IF_DISABLED
protected static final int FLAG_DISABLED_TYPE
protected static final int FLAG_HIDDEN_TYPE
protected static final int FLAG_HAS_DIRECTIONS
protected static final int FLAG_TAGGED
protected static final int FLAG_DIRECTION_REVERSED
protected static final int FLAG_HIGHLIGHTED
protected static final int FLAG_ANNOTATED
public static final Predicate<OsmPrimitive> isUsablePredicate
public static final Predicate<OsmPrimitive> isSelectablePredicate
public static final Predicate<OsmPrimitive> nonDeletedPredicate
public static final Predicate<OsmPrimitive> nonDeletedCompletePredicate
public static final Predicate<OsmPrimitive> nonDeletedPhysicalPredicate
public static final Predicate<OsmPrimitive> modifiedPredicate
public static final Predicate<OsmPrimitive> nodePredicate
public static final Predicate<OsmPrimitive> wayPredicate
public static final Predicate<OsmPrimitive> relationPredicate
public static final Predicate<OsmPrimitive> multipolygonPredicate
public static final Predicate<OsmPrimitive> allPredicate
public StyleCache mappaintStyle
public int mappaintCacheIdx
private static volatile Collection<String> workinprogress
private static volatile Collection<String> uninteresting
private static volatile Collection<String> discardable
private static volatile SearchCompiler.Match directionKeys
private static volatile SearchCompiler.Match reversedDirectionKeys
protected OsmPrimitive(long id, boolean allowNegativeId) throws IllegalArgumentException
id
- the idallowNegativeId
- IllegalArgumentException
- thrown if id < 0 and allowNegativeId is falseprotected OsmPrimitive(long id, int version, boolean allowNegativeId) throws IllegalArgumentException
id
- version
- allowNegativeId
- IllegalArgumentException
- thrown if id < 0 and allowNegativeId is falsepublic static <T extends OsmPrimitive> List<T> getFilteredList(Collection<OsmPrimitive> list, Class<T> type)
OsmPrimitive
s of type type
present in
another collection of OsmPrimitive
s. The result collection is a list.
If list
is null, replies an empty list.T
- list
- the original listtype
- the type to filter fortype
public static <T extends OsmPrimitive> Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type)
OsmPrimitive
s of type type
present in
another collection of OsmPrimitive
s. The result collection is a set.
If list
is null, replies an empty set.T
- type of data (must be one of the OsmPrimitive
typesset
- the original collectiontype
- the type to filter fortype
public static Set<OsmPrimitive> getReferrer(Collection<? extends OsmPrimitive> primitives)
primitives
.primitives
- the collection of primitives.primitives
;
empty set if primitives is null or if there are no referring primitivespublic void clearCachedStyle()
void setDataset(DataSet dataSet)
dataSet
- public DataSet getDataSet()
public void checkDataset()
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 requiredIllegalArgumentException
- thrown if id <= 0IllegalArgumentException
- thrown 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)
AbstractPrimitive
setUser
in interface IPrimitive
setUser
in class AbstractPrimitive
user
- the userpublic void setChangesetId(int changesetId) throws IllegalStateException, IllegalArgumentException
AbstractPrimitive
setChangesetId
in interface IPrimitive
setChangesetId
in class AbstractPrimitive
changesetId
- the id. >= 0 required.IllegalStateException
- thrown if this primitive is new.IllegalArgumentException
- thrown if id < 0public void setTimestamp(Date timestamp)
setTimestamp
in interface IPrimitive
setTimestamp
in class AbstractPrimitive
private void updateFlagsNoLock(int flag, boolean value)
protected final void updateFlags(int 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()
public void setDisabledType(boolean isExplicit)
public void setHiddenType(boolean isExplicit)
public boolean isDisabled()
public boolean isDisabledAndHidden()
public boolean getHiddenType()
public boolean getDisabledType()
public boolean isSelectable()
public boolean isDrawable()
public void setVisible(boolean visible) throws IllegalStateException
AbstractPrimitive
setVisible
in interface IPrimitive
setVisible
in class AbstractPrimitive
IllegalStateException
- thrown if visible is set to false on an primitive with
id==0AbstractPrimitive.isVisible()
public void setDeleted(boolean deleted)
AbstractPrimitive
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
public boolean isSelected()
public boolean isMemberOfSelected()
true
if this primitive is a member of a selected relation, false
otherwisepublic boolean isOuterMemberOfSelected()
true
if this primitive is an outer member of a selected multipolygon relation, false
otherwiseprivate boolean isOuterMemberOfMultipolygon(OsmPrimitive ref)
public void setHighlighted(boolean highlighted)
public boolean isHighlighted()
public static Collection<String> getUninterestingKeys()
public static Collection<String> getDiscardableKeys()
public static Collection<String> getWorkInProgressKeys()
public static boolean isUninterestingKey(String key)
key
- The key to checkpublic Map<String,String> getInterestingTags()
AbstractPrimitive.getKeys()
for which key
does not fulfill isUninterestingKey(java.lang.String)
.private void updateTagged()
private void updateAnnotated()
public boolean isTagged()
public boolean isAnnotated()
private void updateDirectionFlags()
public boolean hasDirectionKeys()
public boolean reversedDirection()
public final void setKeys(Map<String,String> keys)
AbstractPrimitive
keys
.
Old key/value pairs are removed.
If keys
is null, clears existing key/value pairs.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(String key, String value)
AbstractPrimitive
AbstractPrimitive.remove(String)
.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(String key)
AbstractPrimitive
remove
in interface Tagged
remove
in class AbstractPrimitive
key
- the key to be removed. Ignored, if key is null.public final void removeAll()
AbstractPrimitive
removeAll
in interface Tagged
removeAll
in class AbstractPrimitive
protected void keysChangedImpl(Map<String,String> originalKeys)
AbstractPrimitive
keysChangedImpl
in class AbstractPrimitive
protected void addReferrer(OsmPrimitive referrer)
referrer
- The referrer to addprotected void removeReferrer(OsmPrimitive referrer)
referrer
- The referrer to removepublic final List<OsmPrimitive> getReferrers(boolean allowWithoutDataset)
Way wnew = new Way(existingWay)
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 List<OsmPrimitive> getReferrers()
public void visitReferrers(Visitor visitor)
Visits visitor
for all referrers.
visitor
- the visitor. Ignored, if null.public final boolean isReferredByWays(int n)
n
- Minimal number of ways to return true. Must be positivepublic abstract void accept(Visitor visitor)
visitor
- The visitor from which the visit() function must be called.public void cloneFrom(OsmPrimitive other)
public 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 assigend OSM id, the IDs have to be the same.other
- the other primitive. Must not be null.IllegalArgumentException
- thrown if other is null.DataIntegrityProblemException
- thrown if either this is new and other is not, or other is new and this is notDataIntegrityProblemException
- thrown if other isn't new and other.getId() != this.getId()public boolean hasSameInterestingTags(OsmPrimitive other)
other
- the other object primitivepublic boolean hasEqualSemanticAttributes(OsmPrimitive other)
other
- 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 BBox getBBox()
public abstract void updatePosition()
protected String getFlagsAsString()
getFlagsAsString
in class AbstractPrimitive
public boolean equals(Object obj)
public final int hashCode()
public abstract String getDisplayName(NameFormatter formatter)
formatter
public Collection<String> getTemplateKeys()
getTemplateKeys
in interface TemplateEngineDataProvider
public Object getTemplateValue(String name, boolean special)
getTemplateValue
in interface TemplateEngineDataProvider
public boolean evaluateCondition(SearchCompiler.Match condition)
evaluateCondition
in interface TemplateEngineDataProvider
public static Set<Relation> getParentRelations(Collection<? extends OsmPrimitive> primitives)
public 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 area