Package org.openstreetmap.josm.data.osm
Class Relation
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.AbstractPrimitive
-
- org.openstreetmap.josm.data.osm.OsmPrimitive
-
- org.openstreetmap.josm.data.osm.Relation
-
- All Implemented Interfaces:
java.lang.Comparable<IPrimitive>
,IQuadBucketType
,IFilterablePrimitive
,IPrimitive
,IRelation<RelationMember>
,PrimitiveId
,Stylable
,Tagged
,TemplateEngineDataProvider
public final class Relation extends OsmPrimitive implements IRelation<RelationMember>
A relation, having a set of tags and any number (0...n) of members.- Since:
- 343
-
-
Field Summary
Fields Modifier and Type Field Description private BBox
bbox
(package private) static UniqueIdGenerator
idGenerator
private RelationMember[]
members
-
Fields inherited from class org.openstreetmap.josm.data.osm.OsmPrimitive
directionKeys
-
Fields inherited from class org.openstreetmap.josm.data.osm.AbstractPrimitive
changesetId, FLAG_ALL_REFERRERS_DOWNLOADED, 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, mappaintCacheIdx, timestamp, user, version
-
Fields inherited from interface org.openstreetmap.josm.data.osm.Tagged
MAX_TAG_LENGTH
-
-
Constructor Summary
Constructors Constructor Description Relation()
Create a new relation with id 0Relation(long id)
Creates a new relation for the given id.Relation(long id, boolean allowNegative)
Relation(long id, int version)
Creates new relationRelation(Relation clone)
Create an identical clone of the argument (including the id) and links members to it.Relation(Relation clone, boolean clearMetadata)
Constructs an identical clone of the argument and links members to it.Relation(Relation clone, boolean clearMetadata, boolean copyMembers)
Constructs an identical clone of the argument and links members to it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(OsmPrimitiveVisitor visitor)
Implementation of the visitor scheme.void
accept(PrimitiveVisitor visitor)
Makes the given visitor visit this primitive.void
addMember(int index, RelationMember member)
Adds the specified relation member at the specified index.void
addMember(RelationMember member)
Adds the specified relation member at the last position.protected void
addToBBox(BBox box, java.util.Set<PrimitiveId> visited)
If necessary, extend the bbox to contain this primitiveprivate void
checkMembers()
Checks that members are part of the same dataset, and that they're not deleted.void
cloneFrom(OsmPrimitive osm, boolean copyMembers)
Get and write all attributes from the parameter.boolean
concernsArea()
Determines if this primitive semantically concerns an area.java.util.List<? extends OsmPrimitive>
findRelationMembers(java.lang.String role)
Returns a list of relation members having the specified role.private void
fireMembersChanged()
Fires theRelationMembersChangedEvent
to listeners.RelationMember
firstMember()
Returns the first member.BBox
getBBox()
Fetches the bounding box of the primitive.java.util.List<OsmPrimitive>
getChildren()
Get child primitives that are referred by this primitive.OsmPrimitiveType
getDisplayType()
Gets the type this primitive is displayed atUniqueIdGenerator
getIdGenerator()
Returns the unique identifier generator.java.util.Collection<OsmPrimitive>
getIncompleteMembers()
Replies a collection with the incomplete children this relation refers to.RelationMember
getMember(int index)
Returns the relation member at the specified index.long
getMemberId(int idx)
Returns id of the member at given index.java.util.Set<OsmPrimitive>
getMemberPrimitives()
Replies the set ofOsmPrimitive
s referred to by at least one member of this relation.<T extends OsmPrimitive>
java.util.Collection<T>getMemberPrimitives(java.lang.Class<T> tClass)
Returns theOsmPrimitive
s of the specified type referred to by at least one member of this relation.java.util.List<OsmPrimitive>
getMemberPrimitivesList()
Returns an unmodifiable list of theOsmPrimitive
s referred to by at least one member of this relation.java.util.Set<java.lang.String>
getMemberRoles()
Returns the set of roles used in this relation.java.util.List<RelationMember>
getMembers()
Returns members of the relation.int
getMembersCount()
Returns the number of members.java.util.Collection<RelationMember>
getMembersFor(java.util.Collection<? extends OsmPrimitive> primitives)
Obtains all members with member.member == primitiveOsmPrimitiveType
getMemberType(int idx)
Returns type of the member at given index.java.lang.String
getRole(int idx)
Returns role of the member at given index.OsmPrimitiveType
getType()
Gets the type of object represented by this object.boolean
hasEqualSemanticAttributes(OsmPrimitive other, boolean testInterestingTagsOnly)
boolean
hasIncompleteMembers()
Determines if at least one child primitive is incomplete.boolean
isOutsideDownloadArea()
Tests if this primitive lies outside of the downloaded area of itsDataSet
.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.RelationMember
lastMember()
Returns the last member.void
load(PrimitiveData data)
Loads (clone) this primitive from provided PrimitiveDataRelationMember
removeMember(int index)
Removes member at specified position.void
removeMembersFor(java.util.Collection<? extends OsmPrimitive> primitives)
removes all members with member.member == primitivevoid
removeMembersFor(OsmPrimitive primitive)
removes all members with member.member == primitiveRelationData
save()
Save parameters of this primitive to the transport objectprivate void
setBBox(BBox bbox)
(package private) void
setDataset(DataSet dataSet)
This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methodsvoid
setDeleted(boolean deleted)
Sets whether this primitive is deleted or not.RelationMember
setMember(int index, RelationMember member)
Replace member at position specified by index.void
setMembers(java.util.List<RelationMember> members)
Sets members of the relation.java.lang.String
toString()
void
updatePosition()
Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)-
Methods inherited from class org.openstreetmap.josm.data.osm.OsmPrimitive
addReferrer, checkDataset, checkDatasetNotReadOnly, clearOsmMetadata, cloneFrom, declareCachedStyleUpToDate, equals, evaluateCondition, getCachedStyle, getDataSet, getFlagsAsString, getParentRelations, getReferrer, getReferrers, getReferrers, getTemplateKeys, getTemplateValue, hasAreaTags, hasEqualSemanticAttributes, hasEqualSemanticFlags, hasEqualTechnicalAttributes, hashCode, isCachedStyleUpToDate, isMemberOfSelected, isNodeReferredByWays, isOuterMemberOfSelected, isSelectable, isSelected, mergeFrom, put, referrers, remove, removeAll, removeReferrer, saveCommonAttributes, setCachedStyle, setChangesetId, setDisabledState, setHighlighted, setIncomplete, setKeys, setKeys, setModified, setOsmId, setPreserved, setTimestamp, setUser, setVisible, unsetDisabledState, updateDirectionFlags, updateFlags, visitReferrers, visitReferrers, writeLock, writeUnlock
-
Methods inherited from class org.openstreetmap.josm.data.osm.AbstractPrimitive
cloneFrom, doGet, get, getChangesetId, getDisabledType, getDiscardableKeys, getHiddenType, getId, getIgnoreCase, getInstant, getInterestingTags, getKeys, getNumKeys, getRawTimestamp, getTimestamp, getUninterestingKeys, getUniqueId, getUser, getVersion, getWorkInProgressKeys, hasDirectionKeys, hasKey, hasKey, hasKeys, isAnnotated, isDeleted, isDisabled, isDisabledAndHidden, isDrawable, isHighlighted, isIncomplete, isModified, isNew, isNewOrUndeleted, isPreserved, isReferrersDownloaded, isTagged, isTimestampEmpty, isUndeleted, isUninterestingKey, isUsable, isVisible, keys, keySet, putAll, reversedDirection, setDisabledType, setHiddenType, setInstant, setRawTimestamp, setReferrersDownloaded, updateFlagsChanged, visitKeys
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.osm.IPrimitive
getChangesetId, getDataSet, getId, getInstant, getInterestingTags, getLocalName, getName, getOsmId, getOsmPrimitiveId, getPrimitiveId, getRawTimestamp, getReferrers, getReferrers, getStyleCacheSyncObject, getTimestamp, getUser, getVersion, hasDirectionKeys, hasSameInterestingTags, isAnnotated, isDeleted, isDisabled, isDisabledAndHidden, isDrawable, isHighlighted, isIncomplete, isMemberOfSelected, isModified, isNewOrUndeleted, isOuterMemberOfSelected, isPreserved, isReferrersDownloaded, isSelectable, isSelected, isTagged, isTimestampEmpty, isUndeleted, isUsable, isVisible, reversedDirection, setChangesetId, setHighlighted, setInstant, setModified, setOsmId, setRawTimestamp, setReferrersDownloaded, setTimestamp, setUser, setVisible, visitReferrers
-
Methods inherited from interface org.openstreetmap.josm.data.osm.IRelation
compareTo, getDisplayName, isBoundary, isEmpty, isMultipolygon, isUseful
-
Methods inherited from interface org.openstreetmap.josm.data.osm.PrimitiveId
getUniqueId, isNew
-
Methods inherited from interface org.openstreetmap.josm.data.osm.Stylable
clearCachedStyle, declareCachedStyleUpToDate, getCachedStyle, isCachedStyleUpToDate, setCachedStyle
-
Methods inherited from interface org.openstreetmap.josm.data.osm.Tagged
get, getKeys, getNumKeys, hasKey, hasKeys, hasTag, hasTag, hasTag, hasTag, hasTagDifferent, hasTagDifferent, hasTagDifferent, isKeyFalse, isKeyTrue, keys, keySet, put, put, putAll, remove, removeAll, setKeys, visitKeys
-
-
-
-
Field Detail
-
idGenerator
static final UniqueIdGenerator idGenerator
-
members
private RelationMember[] members
-
-
Constructor Detail
-
Relation
Relation(long id, boolean allowNegative)
-
Relation
public Relation()
Create a new relation with id 0
-
Relation
public Relation(Relation clone, boolean clearMetadata, boolean copyMembers)
Constructs an identical clone of the argument and links members to it. See #19885 for possible memory leaks.- Parameters:
clone
- The relation to cloneclearMetadata
- Iftrue
, clears the OSM id and other metadata as defined byOsmPrimitive.clearOsmMetadata()
. Iffalse
, does nothingcopyMembers
- whether to copy relation members too- Since:
- 16212
-
Relation
public Relation(Relation clone, boolean clearMetadata)
Constructs an identical clone of the argument and links members to it. See #19885 for possible memory leaks.- Parameters:
clone
- The relation to cloneclearMetadata
- Iftrue
, clears the OSM id and other metadata as defined byOsmPrimitive.clearOsmMetadata()
. Iffalse
, does nothing
-
Relation
public Relation(Relation clone)
Create an identical clone of the argument (including the id) and links members to it. See #19885 for possible memory leaks.- Parameters:
clone
- The relation to clone, including its id
-
Relation
public Relation(long id)
Creates a new relation for the given id. If the id > 0, the way is marked as incomplete.- Parameters:
id
- the id. > 0 required- Throws:
java.lang.IllegalArgumentException
- if id < 0
-
Relation
public Relation(long id, int version)
Creates new relation- Parameters:
id
- the idversion
- version number (positive integer)
-
-
Method Detail
-
getMembers
public java.util.List<RelationMember> getMembers()
Description copied from interface:IRelation
Returns members of the relation.- Specified by:
getMembers
in interfaceIRelation<RelationMember>
- Returns:
- Members of the relation. Changes made in returned list are not mapped
back to the primitive, use
IRelation.setMembers(java.util.List<M>)
to modify the members
-
setMembers
public void setMembers(java.util.List<RelationMember> members)
Description copied from interface:IRelation
Sets members of the relation.- Specified by:
setMembers
in interfaceIRelation<RelationMember>
- Parameters:
members
- Can be null, in that case all members are removed
-
getMembersCount
public int getMembersCount()
Description copied from interface:IRelation
Returns the number of members.- Specified by:
getMembersCount
in interfaceIRelation<RelationMember>
- Returns:
- number of members
-
getMember
public RelationMember getMember(int index)
Description copied from interface:IRelation
Returns the relation member at the specified index.- Specified by:
getMember
in interfaceIRelation<RelationMember>
- Parameters:
index
- the index of the relation member- Returns:
- relation member at the specified index
-
addMember
public void addMember(RelationMember member)
Adds the specified relation member at the last position.- Parameters:
member
- the member to add
-
addMember
public void addMember(int index, RelationMember member)
Adds the specified relation member at the specified index.- Parameters:
member
- the member to addindex
- the index at which the specified element is to be inserted
-
setMember
public RelationMember setMember(int index, RelationMember member)
Replace member at position specified by index.- Parameters:
index
- index (positive integer)member
- relation member to set- Returns:
- Member that was at the position
-
removeMember
public RelationMember removeMember(int index)
Removes member at specified position.- Parameters:
index
- index (positive integer)- Returns:
- Member that was at the position
-
getMemberId
public long getMemberId(int idx)
Description copied from interface:IRelation
Returns id of the member at given index.- Specified by:
getMemberId
in interfaceIRelation<RelationMember>
- Parameters:
idx
- member index- Returns:
- id of the member at given index
-
getRole
public java.lang.String getRole(int idx)
Description copied from interface:IRelation
Returns role of the member at given index.- Specified by:
getRole
in interfaceIRelation<RelationMember>
- Parameters:
idx
- member index- Returns:
- role of the member at given index
-
getMemberType
public OsmPrimitiveType getMemberType(int idx)
Description copied from interface:IRelation
Returns type of the member at given index.- Specified by:
getMemberType
in interfaceIRelation<RelationMember>
- Parameters:
idx
- member index- Returns:
- type of the member at given index
-
accept
public void accept(OsmPrimitiveVisitor visitor)
Description copied from class:OsmPrimitive
Implementation of the visitor scheme. Subclasses have to call the correct visitor function.- Specified by:
accept
in classOsmPrimitive
- Parameters:
visitor
- The visitor from which the visit() function must be called.
-
accept
public void accept(PrimitiveVisitor visitor)
Description copied from interface:IPrimitive
Makes the given visitor visit this primitive.- Specified by:
accept
in interfaceIPrimitive
- Parameters:
visitor
- visitor
-
cloneFrom
public void cloneFrom(OsmPrimitive osm, boolean copyMembers)
Description copied from class:OsmPrimitive
Get and write all attributes from the parameter. Does not fire any listener, so use this only in the data initializing phase- Overrides:
cloneFrom
in classOsmPrimitive
- Parameters:
osm
- other primitivecopyMembers
- whether to copy child primitives too
-
load
public void load(PrimitiveData data)
Description copied from class:OsmPrimitive
Loads (clone) this primitive from provided PrimitiveData- Overrides:
load
in classOsmPrimitive
- Parameters:
data
- The object which should be cloned
-
save
public RelationData save()
Description copied from class:OsmPrimitive
Save parameters of this primitive to the transport object- Specified by:
save
in classOsmPrimitive
- Returns:
- The saved object data
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hasEqualSemanticAttributes
public boolean hasEqualSemanticAttributes(OsmPrimitive other, boolean testInterestingTagsOnly)
- Overrides:
hasEqualSemanticAttributes
in classOsmPrimitive
-
firstMember
public RelationMember firstMember()
Returns the first member.- Returns:
- first member, or
null
-
lastMember
public RelationMember lastMember()
Returns the last member.- Returns:
- last member, or
null
-
removeMembersFor
public void removeMembersFor(OsmPrimitive primitive)
removes all members with member.member == primitive- Parameters:
primitive
- the primitive to check for
-
setDeleted
public void setDeleted(boolean deleted)
Description copied from interface:IPrimitive
Sets whether this primitive is deleted or not.Also marks this primitive as modified if deleted is true.
- Specified by:
setDeleted
in interfaceIPrimitive
- Overrides:
setDeleted
in classOsmPrimitive
- Parameters:
deleted
- true, if this primitive is deleted; false, otherwise
-
getMembersFor
public java.util.Collection<RelationMember> getMembersFor(java.util.Collection<? extends OsmPrimitive> primitives)
Obtains all members with member.member == primitive- Parameters:
primitives
- the primitives to check for- Returns:
- all relation members for the given primitives
-
removeMembersFor
public void removeMembersFor(java.util.Collection<? extends OsmPrimitive> primitives)
removes all members with member.member == primitive- Parameters:
primitives
- the primitives to check for- Since:
- 5613
-
getMemberPrimitives
public java.util.Set<OsmPrimitive> getMemberPrimitives()
Replies the set ofOsmPrimitive
s referred to by at least one member of this relation.- Returns:
- the set of
OsmPrimitive
s referred to by at least one member of this relation - See Also:
getMemberPrimitivesList()
-
getMemberPrimitives
public <T extends OsmPrimitive> java.util.Collection<T> getMemberPrimitives(java.lang.Class<T> tClass)
Returns theOsmPrimitive
s of the specified type referred to by at least one member of this relation.- Type Parameters:
T
- the type of the primitive- Parameters:
tClass
- the type of the primitive- Returns:
- the primitives
-
getMemberPrimitivesList
public java.util.List<OsmPrimitive> getMemberPrimitivesList()
Returns an unmodifiable list of theOsmPrimitive
s referred to by at least one member of this relation.- Specified by:
getMemberPrimitivesList
in interfaceIRelation<RelationMember>
- Returns:
- an unmodifiable list of the primitives
-
getChildren
public java.util.List<OsmPrimitive> getChildren()
Description copied from interface:IPrimitive
Get child primitives that are referred by this primitive.Relation
: Members of the relationWay
: Nodes used by the wayNode
: None- Specified by:
getChildren
in interfaceIPrimitive
- Specified by:
getChildren
in interfaceIRelation<RelationMember>
- Returns:
- List of child primitives
-
getType
public OsmPrimitiveType getType()
Description copied from interface:PrimitiveId
Gets the type of object represented by this object. Note that this should return the base primitive type (OsmPrimitiveType.NODE
,OsmPrimitiveType.WAY
, andOsmPrimitiveType.RELATION
).- Specified by:
getType
in interfacePrimitiveId
- Returns:
- the object type
- See Also:
Node
,Way
,Relation
-
getDisplayType
public OsmPrimitiveType getDisplayType()
Description copied from interface:IPrimitive
Gets the type this primitive is displayed at- Specified by:
getDisplayType
in interfaceIPrimitive
- Returns:
- A
OsmPrimitiveType
-
getBBox
public BBox getBBox()
Description copied from interface:IPrimitive
Fetches the bounding box of the primitive. Since 17752, the returned bounding box might be immutable, i.e., modifying calls throw anUnsupportedOperationException
.- Specified by:
getBBox
in interfaceIPrimitive
- Specified by:
getBBox
in interfaceIQuadBucketType
- Returns:
- Bounding box of the object
-
addToBBox
protected void addToBBox(BBox box, java.util.Set<PrimitiveId> visited)
Description copied from class:OsmPrimitive
If necessary, extend the bbox to contain this primitive- Specified by:
addToBBox
in classOsmPrimitive
- Parameters:
box
- a bbox instancevisited
- a set of visited members or null
-
updatePosition
public void updatePosition()
Description copied from class:OsmPrimitive
Called by Dataset to update cached position information of primitive (bbox, cached EarthNorth, ...)- Specified by:
updatePosition
in classOsmPrimitive
-
setDataset
void setDataset(DataSet dataSet)
Description copied from class:OsmPrimitive
This method should never ever by called from somewhere else than Dataset.addPrimitive or removePrimitive methods- Overrides:
setDataset
in classOsmPrimitive
- Parameters:
dataSet
- the parent dataset
-
checkMembers
private void checkMembers()
Checks that members are part of the same dataset, and that they're not deleted.- Throws:
DataIntegrityProblemException
- if one the above conditions is not met
-
fireMembersChanged
private void fireMembersChanged()
Fires theRelationMembersChangedEvent
to listeners.- Throws:
DataIntegrityProblemException
- if members are not valid- See Also:
checkMembers()
-
hasIncompleteMembers
public boolean hasIncompleteMembers()
Description copied from interface:IRelation
Determines if at least one child primitive is incomplete.- Specified by:
hasIncompleteMembers
in interfaceIRelation<RelationMember>
- Returns:
- true if at least one child primitive is incomplete
-
getIncompleteMembers
public java.util.Collection<OsmPrimitive> getIncompleteMembers()
Replies a collection with the incomplete children this relation refers to.- Specified by:
getIncompleteMembers
in interfaceIRelation<RelationMember>
- Returns:
- the incomplete children. Empty collection if no children are incomplete.
-
keysChangedImpl
protected void keysChangedImpl(java.util.Map<java.lang.String,java.lang.String> originalKeys)
Description copied from class:AbstractPrimitive
What to do, when the tags have changed by one of the tag-changing methods.- Overrides:
keysChangedImpl
in classOsmPrimitive
- Parameters:
originalKeys
- original tags
-
concernsArea
public boolean concernsArea()
Description copied from class:OsmPrimitive
Determines if this primitive semantically concerns an area.- Specified by:
concernsArea
in classOsmPrimitive
- Returns:
true
if this primitive semantically concerns an area, according to its type, geometry and tags,false
otherwise.
-
isOutsideDownloadArea
public boolean isOutsideDownloadArea()
Description copied from class:OsmPrimitive
Tests if this primitive lies outside of the downloaded area of itsDataSet
.- Specified by:
isOutsideDownloadArea
in classOsmPrimitive
- Returns:
true
if this primitive lies outside of the downloaded area
-
getMemberRoles
public java.util.Set<java.lang.String> getMemberRoles()
Returns the set of roles used in this relation.- Returns:
- the set of roles used in this relation. Can be empty but never null
- Since:
- 7556
-
findRelationMembers
public java.util.List<? extends OsmPrimitive> findRelationMembers(java.lang.String role)
Description copied from interface:IRelation
Returns a list of relation members having the specified role.- Specified by:
findRelationMembers
in interfaceIRelation<RelationMember>
- Parameters:
role
- role- Returns:
- a list of relation members having the specified role
-
getIdGenerator
public UniqueIdGenerator getIdGenerator()
Description copied from class:AbstractPrimitive
Returns the unique identifier generator.- Specified by:
getIdGenerator
in classAbstractPrimitive
- Returns:
- the unique identifier generator
-
-