Package org.openstreetmap.josm.data.osm
Class DataSet
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.DataSet
-
- All Implemented Interfaces:
Data
,Lockable
,OsmData<OsmPrimitive,Node,Way,Relation>
,ProjectionChangeListener
public final class DataSet extends Object implements OsmData<OsmPrimitive,Node,Way,Relation>, ProjectionChangeListener
DataSet is the data behind the application. It can consists of only a few points up to the whole osm database. DataSet's can be merged together, saved, (up/down/disk)loaded etc. Note that DataSet is not an osm-primitive and so has no key association but a few members to store some information. Dataset is threadsafe - accessing Dataset simultaneously from different threads should never lead to data corruption or ConcurrentModificationException. However when for example one thread removes primitive and other thread try to add another primitive referring to the removed primitive, DataIntegrityException will occur. To prevent such situations, read/write lock is provided. While read lock is used, it's guaranteed that Dataset will not change. Sample usage:ds.getReadLock().lock(); try { // .. do something with dataset } finally { ds.getReadLock().unlock(); }
Write lock should be used in case of bulk operations. In addition to ensuring that other threads can't use dataset in the middle of modifications it also stops sending of dataset events. That's good for performance reasons - GUI can be updated after all changes are done. Sample usage:ds.beginUpdate() try { // .. do modifications } finally { ds.endUpdate(); }
Note that it is not necessary to call beginUpdate/endUpdate for every dataset modification - dataset will get locked automatically. Note that locks cannot be upgraded - if one threads use read lock and and then write lock, dead lock will occur - see #5814 for sample ticket
-
-
Field Summary
Fields Modifier and Type Field Description private Storage<OsmPrimitive>
allPrimitives
private Area
cachedDataSourceArea
private List<Bounds>
cachedDataSourceBounds
private List<AbstractDatasetChangedEvent>
cachedEvents
private Map<String,String>
changeSetTags
Holding bin for changeset tag information, to be applied when or if this is ever uploaded.private ConflictCollection
conflicts
private Set<OsmPrimitive>
currentSelectedPrimitives
The current selected primitives.private ListenerList<DataSourceListener>
dataSourceListeners
A list of listeners that listen to DataSource changes on this layerprivate Collection<DataSource>
dataSources
All data sources of this DataSet.private DownloadPolicy
downloadPolicy
private List<GpxData.XMLNamespace>
gpxNamespaces
Used to temporarily store namespaces from the GPX file in case the user converts back and forth.private Collection<WaySegment>
highlightedVirtualNodes
private Collection<WaySegment>
highlightedWaySegments
private ListenerList<HighlightUpdateListener>
highlightUpdateListeners
private AtomicBoolean
isReadOnly
Flag used to know if the dataset should not be editableprivate CopyOnWriteArrayList<DataSetListener>
listeners
private ReadWriteLock
lock
private short
mappaintCacheIdx
private static int
MAX_EVENTS
Maximum number of events to kept between beginUpdate/endUpdate.private static int
MAX_SINGLE_EVENTS
Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)private String
name
private Map<PrimitiveId,OsmPrimitive>
primitivesMap
private String
remark
private LinkedList<Collection<? extends OsmPrimitive>>
selectionHistory
History of selections - shared by plugins and SelectionListDialogprivate ListenerList<DataSelectionListener>
selectionListeners
A list of listeners that listen to selection changes on this layer.private Object
selectionLock
The mutex lock that is used to synchronize selection changes.private QuadBucketPrimitiveStore<Node,Way,Relation>
store
private int
updateCount
private UploadPolicy
uploadPolicy
private String
version
The API version that created this data set, if any.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeSetTag(String k, String v)
Adds a new changeset tag.void
addDataSetListener(DataSetListener dsl)
Adds a new data set listener.boolean
addDataSource(DataSource source)
Adds a new data source.void
addDataSourceListener(DataSourceListener listener)
Adds a listener that gets notified whenever the data sources changeboolean
addDataSources(Collection<DataSource> sources)
Adds new data sources.void
addHighlightUpdateListener(HighlightUpdateListener listener)
Adds a listener that gets notified whenever way segment / virtual nodes highlights change.void
addPrimitive(OsmPrimitive primitive)
Adds a primitive to the dataset.void
addPrimitiveRecursive(OsmPrimitive primitive)
Adds recursively a primitive, and all its children, to the dataset.void
addSelected(Collection<? extends PrimitiveId> selection)
Adds the primitives inselection
to the current selection and notifies allDataSelectionListener
.private void
addSelected(Stream<? extends PrimitiveId> stream)
void
addSelected(PrimitiveId... osm)
Adds the primitives inosm
to the current selection and notifies allDataSelectionListener
.void
addSelectionListener(DataSelectionListener listener)
Add a listener that listens to selection changes in this specific data set.void
beginUpdate()
Can be called before bigger changes on dataset.private void
checkModifiable()
Checks the dataset is modifiable (not read-only).void
cleanupDeletedPrimitives()
Cleanups all deleted primitives (really delete them from the dataset).void
clear()
Removes all primitives from the dataset and resets the currently selected primitives to the empty collection.void
clearMappaintCache()
Clear the mappaint cache for this DataSet.void
clearSelection()
Clears the current selection.void
clearSelection(Collection<? extends PrimitiveId> list)
Removes the selection from every value in the collection.private void
clearSelection(Stream<? extends PrimitiveId> stream)
void
clearSelection(PrimitiveId... osm)
Removes the selection from every value in the collection.void
clearSelectionHistory()
Clears selection history listMap<OsmPrimitive,OsmPrimitive>
clonePrimitives(Iterable<Node> nodes, Iterable<Way> ways, Iterable<Relation> relations)
Clones the specified primitives into this data set.boolean
containsNode(Node n)
Determines if the given node can be retrieved in the data set through its bounding box.boolean
containsRelation(Relation r)
Determines if the given relation can be retrieved in the data set through its bounding box.boolean
containsWay(Way w)
Determines if the given way can be retrieved in the data set through its bounding box.void
deleteInvisible()
Marks all "invisible" objects as deleted.private static void
deleteWay(Way way)
private boolean
doSelectionChange(Function<Set<OsmPrimitive>,DataSelectionListener.SelectionChangeEvent> command)
Do a selection change.void
endUpdate()
Must be called after a previous call tobeginUpdate()
to fire change events.(package private) void
fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId)
private void
fireEvent(AbstractDatasetChangedEvent event)
private void
fireEventToListeners(AbstractDatasetChangedEvent event)
(package private) void
fireFilterChanged()
(package private) void
fireHighlightingChanged()
(package private) void
fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth)
(package private) void
firePrimitiveFlagsChanged(OsmPrimitive primitive)
(package private) void
firePrimitivesAdded(Collection<? extends OsmPrimitive> added, boolean wasIncomplete)
(package private) void
firePrimitivesRemoved(Collection<? extends OsmPrimitive> removed, boolean wasComplete)
(package private) void
fireRelationMembersChanged(Relation r)
(package private) void
fireTagsChanged(OsmPrimitive prim, Map<String,String> originalKeys)
(package private) void
fireWayNodesChanged(Way way)
Collection<OsmPrimitive>
getAllSelected()
Replies an unmodifiable collection of primitives currently selected in this dataset, including deleted ones.Map<String,String>
getChangeSetTags()
Replies the set of changeset tags to be applied when or if this is ever uploaded.ConflictCollection
getConflicts()
Replies the set of conflicts currently managed in this layer.Area
getDataSourceArea()
Returns the total area of downloaded data (the "yellow rectangles").ProjectionBounds
getDataSourceBoundingBox()
Returns the data sources bounding box.List<Bounds>
getDataSourceBounds()
Replies the list of data source bounds.Collection<DataSource>
getDataSources()
Returns the collection of data sources.DownloadPolicy
getDownloadPolicy()
Get the download policy.List<GpxData.XMLNamespace>
getGPXNamespaces()
Gets the GPX (XML) namespaces if this DataSet was created from a GPX fileCollection<WaySegment>
getHighlightedVirtualNodes()
Returns an unmodifiable collection of *WaySegments* whose virtual nodes should be highlighted.Collection<WaySegment>
getHighlightedWaySegments()
Returns an unmodifiable collection of WaySegments that should be highlighted.short
getMappaintCacheIndex()
Returns mappaint cache index for this DataSet.String
getName()
Returns the name of this data set (optional).Collection<Node>
getNodes()
Replies an unmodifiable collection of nodes in this datasetOsmPrimitive
getPrimitiveById(PrimitiveId primitiveId)
Returns a primitive with a given id from the data set.private OsmPrimitive
getPrimitiveByIdChecked(PrimitiveId primitiveId)
Show message and stack trace in log in case primitive is not found<T extends OsmPrimitive>
Collection<T>getPrimitives(Predicate<? super OsmPrimitive> predicate)
Gets a filtered collection of primitives matching the given predicate.Lock
getReadLock()
Returns the lock used for reading.Collection<Relation>
getRelations()
Replies an unmodifiable collection of relations in this datasetString
getRemark()
Returns an optional remark about this data set (used by Overpass API).Collection<OsmPrimitive>
getSelectedNodesAndWays()
Returns selected nodes and ways.LinkedList<Collection<? extends OsmPrimitive>>
getSelectionHistory()
Replies the history of JOSM selectionsUploadPolicy
getUploadPolicy()
Get the upload policy.String
getVersion()
Replies the API version this dataset was created from.Collection<Way>
getWays()
Replies an unmodifiable collection of ways in this datasetvoid
invalidateEastNorthCache()
Invalidates the internal cache of projected east/north coordinates.boolean
isEmpty()
Determines if this Dataset contains no primitives.boolean
isLocked()
Determines if this is read-only/locked (thus it cannot be modified).boolean
isModified()
Replies true if there is at least one primitive in this dataset withIPrimitive.isModified()
==true
.boolean
isSelected(OsmPrimitive osm)
Determines whether the given primitive is selected or notvoid
lock()
Enables the read-only/locked mode.void
mergeFrom(DataSet from)
Moves all primitives and datasources from DataSet "from" to this DataSet.void
mergeFrom(DataSet from, ProgressMonitor progressMonitor)
Moves all primitives and datasources from DataSet "from" to this DataSet.void
projectionChanged(Projection oldValue, Projection newValue)
void
removeDataSetListener(DataSetListener dsl)
Removes a data set listener.void
removeDataSourceListener(DataSourceListener listener)
Removes a listener that gets notified whenever the data sources changevoid
removeHighlightUpdateListener(HighlightUpdateListener listener)
Removes a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)
(package private) void
removePrimitive(OsmPrimitive primitive)
void
removePrimitive(PrimitiveId primitiveId)
Removes a primitive from the dataset.private void
removePrimitiveImpl(OsmPrimitive primitive)
void
removeSelectionListener(DataSelectionListener listener)
Remove a listener that listens to selection changes in this specific data set.boolean
requiresUploadToServer()
Replies true if there is at least one primitive in this dataset which requires to be uploaded to server.List<Node>
searchNodes(BBox bbox)
Searches for nodes in the given bounding box.List<OsmPrimitive>
searchPrimitives(BBox bbox)
Searches for all primitives in the given bounding boxList<Relation>
searchRelations(BBox bbox)
Searches for relations in the given bounding box.List<Way>
searchWays(BBox bbox)
Searches for ways in the given bounding box.boolean
selectionEmpty()
Determines whether the selection is empty or notvoid
setDownloadPolicy(DownloadPolicy downloadPolicy)
Sets the download policy.void
setGPXNamespaces(List<GpxData.XMLNamespace> gpxNamespaces)
Sets the GPX (XML) namespacesvoid
setHighlightedVirtualNodes(Collection<WaySegment> waySegments)
set what virtual nodes should be highlighted.void
setHighlightedWaySegments(Collection<WaySegment> waySegments)
set what virtual ways should be highlighted.void
setName(String name)
Sets the name of this data set.void
setRemark(String remark)
Sets an optional remark about this data set (used by Overpass API).void
setSelected(Collection<? extends PrimitiveId> selection)
Sets the current selection to the primitives inselection
and notifies allDataSelectionListener
.private void
setSelected(Stream<? extends PrimitiveId> stream)
void
setSelected(PrimitiveId... osm)
Sets the current selection to the primitives inosm
and notifies allDataSelectionListener
.void
setUploadPolicy(UploadPolicy uploadPolicy)
Sets the upload policy.void
setVersion(String version)
Sets the API version this dataset was created from.void
toggleSelected(Collection<? extends PrimitiveId> osm)
Toggles the selected state of the given collection of primitives.private void
toggleSelected(Stream<? extends PrimitiveId> stream)
void
toggleSelected(PrimitiveId... osm)
Toggles the selected state of the given collection of primitives.Set<Way>
unlinkNodeFromWays(Node node)
Removes all references from ways in this dataset to a particular node.Set<Relation>
unlinkPrimitiveFromRelations(OsmPrimitive primitive)
removes all references from relations in this dataset to this primitiveSet<OsmPrimitive>
unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
Removes all references from other primitives to the referenced primitive.void
unlock()
Disables the read-only/locked mode.void
update(Runnable runnable)
Performs the update runnable betweenbeginUpdate()
/endUpdate()
calls.<T,R>
Rupdate(Function<T,R> function, T t)
Performs the update function betweenbeginUpdate()
/endUpdate()
calls.<R> R
update(Supplier<R> supplier)
Performs the update supplier betweenbeginUpdate()
/endUpdate()
calls.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.osm.OsmData
allModifiedPrimitives, allNonDeletedCompletePrimitives, allNonDeletedPhysicalPrimitives, allNonDeletedPrimitives, allPreservedPrimitives, allPrimitives, clearHighlightedVirtualNodes, clearHighlightedWaySegments, getPrimitiveById, getSelected, getSelectedNodes, getSelectedRelations, getSelectedWays
-
-
-
-
Field Detail
-
MAX_SINGLE_EVENTS
private static final int MAX_SINGLE_EVENTS
Maximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)- See Also:
- Constant Field Values
-
MAX_EVENTS
private static final int MAX_EVENTS
Maximum number of events to kept between beginUpdate/endUpdate. When more events are created, that simple DatasetChangedEvent is sent)- See Also:
- Constant Field Values
-
store
private final QuadBucketPrimitiveStore<Node,Way,Relation> store
-
allPrimitives
private final Storage<OsmPrimitive> allPrimitives
-
primitivesMap
private final Map<PrimitiveId,OsmPrimitive> primitivesMap
-
listeners
private final CopyOnWriteArrayList<DataSetListener> listeners
-
highlightedVirtualNodes
private Collection<WaySegment> highlightedVirtualNodes
-
highlightedWaySegments
private Collection<WaySegment> highlightedWaySegments
-
highlightUpdateListeners
private final ListenerList<HighlightUpdateListener> highlightUpdateListeners
-
updateCount
private int updateCount
-
cachedEvents
private final List<AbstractDatasetChangedEvent> cachedEvents
-
downloadPolicy
private DownloadPolicy downloadPolicy
-
uploadPolicy
private UploadPolicy uploadPolicy
-
isReadOnly
private final AtomicBoolean isReadOnly
Flag used to know if the dataset should not be editable
-
lock
private final ReadWriteLock lock
-
selectionLock
private final Object selectionLock
The mutex lock that is used to synchronize selection changes.
-
currentSelectedPrimitives
private Set<OsmPrimitive> currentSelectedPrimitives
The current selected primitives. This is always a unmodifiable set. The set should be ordered in the order in which the primitives have been added to the selection.
-
selectionListeners
private final ListenerList<DataSelectionListener> selectionListeners
A list of listeners that listen to selection changes on this layer.
-
cachedDataSourceArea
private Area cachedDataSourceArea
-
cachedDataSourceBounds
private List<Bounds> cachedDataSourceBounds
-
dataSources
private final Collection<DataSource> dataSources
All data sources of this DataSet.
-
dataSourceListeners
private final ListenerList<DataSourceListener> dataSourceListeners
A list of listeners that listen to DataSource changes on this layer
-
conflicts
private final ConflictCollection conflicts
-
mappaintCacheIdx
private short mappaintCacheIdx
-
gpxNamespaces
private List<GpxData.XMLNamespace> gpxNamespaces
Used to temporarily store namespaces from the GPX file in case the user converts back and forth. Will not be saved to .osm files, but that's not necessary because GPX files won't automatically be overridden after that.
-
selectionHistory
private final LinkedList<Collection<? extends OsmPrimitive>> selectionHistory
History of selections - shared by plugins and SelectionListDialog
-
changeSetTags
private final Map<String,String> changeSetTags
Holding bin for changeset tag information, to be applied when or if this is ever uploaded.
-
-
Constructor Detail
-
DataSet
public DataSet()
Constructs a newDataSet
.
-
DataSet
public DataSet(DataSet copyFrom)
Creates a newDataSet
.- Parameters:
copyFrom
- An otherDataSet
to copy the contents of this dataset from.- Since:
- 10346
-
DataSet
public DataSet(OsmPrimitive... osmPrimitives)
Constructs a newDataSet
initially filled with the given primitives.- Parameters:
osmPrimitives
- primitives to add to this data set- Since:
- 12726
-
-
Method Detail
-
clonePrimitives
public Map<OsmPrimitive,OsmPrimitive> clonePrimitives(Iterable<Node> nodes, Iterable<Way> ways, Iterable<Relation> relations)
Clones the specified primitives into this data set.- Parameters:
nodes
- nodes to cloneways
- ways to clonerelations
- relations to clone- Returns:
- the map of cloned primitives indexed by their original version
- Since:
- 18001
-
addDataSource
public boolean addDataSource(DataSource source)
Adds a new data source.- Parameters:
source
- data source to add- Returns:
true
if the collection changed as a result of the call- Since:
- 11626
-
addDataSources
public boolean addDataSources(Collection<DataSource> sources)
Adds new data sources.- Parameters:
sources
- data sources to add- Returns:
true
if the collection changed as a result of the call- Since:
- 11626
-
getReadLock
public Lock getReadLock()
Description copied from interface:OsmData
Returns the lock used for reading.- Specified by:
getReadLock
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- the lock used for reading
-
getSelectionHistory
public LinkedList<Collection<? extends OsmPrimitive>> getSelectionHistory()
Replies the history of JOSM selections- Returns:
- list of history entries
-
clearSelectionHistory
public void clearSelectionHistory()
Clears selection history list
-
getVersion
public String getVersion()
Description copied from interface:OsmData
Replies the API version this dataset was created from. May be null.- Specified by:
getVersion
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- the API version this dataset was created from. May be null.
-
setVersion
public void setVersion(String version)
Sets the API version this dataset was created from.- Parameters:
version
- the API version, i.e. "0.6"- Throws:
IllegalStateException
- if the dataset is read-only
-
getDownloadPolicy
public DownloadPolicy getDownloadPolicy()
Description copied from interface:OsmData
Get the download policy.- Specified by:
getDownloadPolicy
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- the download policy
- See Also:
OsmData.setDownloadPolicy(DownloadPolicy)
-
setDownloadPolicy
public void setDownloadPolicy(DownloadPolicy downloadPolicy)
Description copied from interface:OsmData
Sets the download policy.- Specified by:
setDownloadPolicy
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
downloadPolicy
- the download policy. Must not be null- See Also:
OsmData.getUploadPolicy()
-
getUploadPolicy
public UploadPolicy getUploadPolicy()
Description copied from interface:OsmData
Get the upload policy.- Specified by:
getUploadPolicy
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- the upload policy
- See Also:
OsmData.setUploadPolicy(UploadPolicy)
-
setUploadPolicy
public void setUploadPolicy(UploadPolicy uploadPolicy)
Description copied from interface:OsmData
Sets the upload policy.- Specified by:
setUploadPolicy
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
uploadPolicy
- the upload policy. Must not be null- See Also:
OsmData.getUploadPolicy()
-
getChangeSetTags
public Map<String,String> getChangeSetTags()
Replies the set of changeset tags to be applied when or if this is ever uploaded.- Returns:
- the set of changeset tags
- See Also:
addChangeSetTag(java.lang.String, java.lang.String)
-
addChangeSetTag
public void addChangeSetTag(String k, String v)
Adds a new changeset tag.- Parameters:
k
- Keyv
- Value- See Also:
getChangeSetTags()
-
getPrimitives
public <T extends OsmPrimitive> Collection<T> getPrimitives(Predicate<? super OsmPrimitive> predicate)
Description copied from interface:OsmData
Gets a filtered collection of primitives matching the given predicate.- Specified by:
getPrimitives
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Type Parameters:
T
- The primitive type.- Parameters:
predicate
- The predicate to match- Returns:
- The list of primitives.
-
getNodes
public Collection<Node> getNodes()
Description copied from interface:OsmData
Replies an unmodifiable collection of nodes in this dataset
-
searchNodes
public List<Node> searchNodes(BBox bbox)
Description copied from interface:OsmData
Searches for nodes in the given bounding box.- Specified by:
searchNodes
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
bbox
- the bounding box- Returns:
- List of nodes in the given bbox. Can be empty but not null
-
getWays
public Collection<Way> getWays()
Description copied from interface:OsmData
Replies an unmodifiable collection of ways in this dataset
-
searchWays
public List<Way> searchWays(BBox bbox)
Description copied from interface:OsmData
Searches for ways in the given bounding box.- Specified by:
searchWays
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
bbox
- the bounding box- Returns:
- List of ways in the given bbox. Can be empty but not null
-
searchRelations
public List<Relation> searchRelations(BBox bbox)
Description copied from interface:OsmData
Searches for relations in the given bounding box.- Specified by:
searchRelations
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
bbox
- the bounding box- Returns:
- List of relations in the given bbox. Can be empty but not null
-
searchPrimitives
public List<OsmPrimitive> searchPrimitives(BBox bbox)
Searches for all primitives in the given bounding box- Parameters:
bbox
- the bounding box- Returns:
- List of primitives in the given bbox. Can be empty but not null
- Since:
- 15891
-
getRelations
public Collection<Relation> getRelations()
Description copied from interface:OsmData
Replies an unmodifiable collection of relations in this dataset- Specified by:
getRelations
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- an unmodifiable collection of relations in this dataset
-
containsNode
public boolean containsNode(Node n)
Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test. For efficiency reasons this method does not lock the dataset, you have to lock it manually.- Specified by:
containsNode
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
n
- The node to search- Returns:
true
ifn
can be retrieved in this data set,false
otherwise- Since:
- 7501
-
containsWay
public boolean containsWay(Way w)
Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test. For efficiency reasons this method does not lock the dataset, you have to lock it manually.- Specified by:
containsWay
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
w
- The way to search- Returns:
true
ifw
can be retrieved in this data set,false
otherwise- Since:
- 7501
-
containsRelation
public boolean containsRelation(Relation r)
Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test. For efficiency reasons this method does not lock the dataset, you have to lock it manually.- Specified by:
containsRelation
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
r
- The relation to search- Returns:
true
ifr
can be retrieved in this data set,false
otherwise- Since:
- 7501
-
addPrimitive
public void addPrimitive(OsmPrimitive primitive)
Adds a primitive to the dataset.- Specified by:
addPrimitive
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
primitive
- the primitive.- Throws:
IllegalStateException
- if the dataset is read-only
-
addPrimitiveRecursive
public void addPrimitiveRecursive(OsmPrimitive primitive)
Adds recursively a primitive, and all its children, to the dataset.- Parameters:
primitive
- the primitive.- Throws:
IllegalStateException
- if the dataset is read-only- Since:
- 17981
-
removePrimitive
public void removePrimitive(PrimitiveId primitiveId)
Removes a primitive from the dataset. This method only removes the primitive form the respective collection of primitives managed by this dataset, i.e. fromstore.nodes
,store.ways
, orstore.relations
. References from other primitives to this primitive are left unchanged.- Parameters:
primitiveId
- the id of the primitive- Throws:
IllegalStateException
- if the dataset is read-only
-
removePrimitiveImpl
private void removePrimitiveImpl(OsmPrimitive primitive)
-
removePrimitive
void removePrimitive(OsmPrimitive primitive)
-
addSelectionListener
public void addSelectionListener(DataSelectionListener listener)
Description copied from interface:OsmData
Add a listener that listens to selection changes in this specific data set.- Specified by:
addSelectionListener
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
listener
- The listener.- See Also:
OsmData.removeSelectionListener(DataSelectionListener)
,To add a global listener.
-
removeSelectionListener
public void removeSelectionListener(DataSelectionListener listener)
Description copied from interface:OsmData
Remove a listener that listens to selection changes in this specific data set.- Specified by:
removeSelectionListener
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
listener
- The listener.- See Also:
OsmData.addSelectionListener(DataSelectionListener)
-
getSelectedNodesAndWays
public Collection<OsmPrimitive> getSelectedNodesAndWays()
Returns selected nodes and ways.- Returns:
- selected nodes and ways
-
getHighlightedVirtualNodes
public Collection<WaySegment> getHighlightedVirtualNodes()
Description copied from interface:OsmData
Returns an unmodifiable collection of *WaySegments* whose virtual nodes should be highlighted. WaySegments are used to avoid having to create a VirtualNode class that wouldn't have much purpose otherwise.- Specified by:
getHighlightedVirtualNodes
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- unmodifiable collection of WaySegments
-
getHighlightedWaySegments
public Collection<WaySegment> getHighlightedWaySegments()
Description copied from interface:OsmData
Returns an unmodifiable collection of WaySegments that should be highlighted.- Specified by:
getHighlightedWaySegments
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- unmodifiable collection of WaySegments
-
addHighlightUpdateListener
public void addHighlightUpdateListener(HighlightUpdateListener listener)
Description copied from interface:OsmData
Adds a listener that gets notified whenever way segment / virtual nodes highlights change.- Specified by:
addHighlightUpdateListener
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
listener
- The Listener
-
removeHighlightUpdateListener
public void removeHighlightUpdateListener(HighlightUpdateListener listener)
Description copied from interface:OsmData
Removes a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)
- Specified by:
removeHighlightUpdateListener
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
listener
- The Listener
-
addDataSourceListener
public void addDataSourceListener(DataSourceListener listener)
Adds a listener that gets notified whenever the data sources change- Parameters:
listener
- The listener- Since:
- 15609
- See Also:
removeDataSourceListener(org.openstreetmap.josm.data.osm.DataSourceListener)
,getDataSources()
-
removeDataSourceListener
public void removeDataSourceListener(DataSourceListener listener)
Removes a listener that gets notified whenever the data sources change- Parameters:
listener
- The listener- Since:
- 15609
- See Also:
addDataSourceListener(org.openstreetmap.josm.data.osm.DataSourceListener)
,getDataSources()
-
getAllSelected
public Collection<OsmPrimitive> getAllSelected()
Description copied from interface:OsmData
Replies an unmodifiable collection of primitives currently selected in this dataset, including deleted ones. May be empty, but not null. When iterating through the set it is ordered by the order in which the primitives were added to the selection.- Specified by:
getAllSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- unmodifiable collection of primitives
-
selectionEmpty
public boolean selectionEmpty()
Description copied from interface:OsmData
Determines whether the selection is empty or not- Specified by:
selectionEmpty
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- whether the selection is empty or not
-
isSelected
public boolean isSelected(OsmPrimitive osm)
Description copied from interface:OsmData
Determines whether the given primitive is selected or not- Specified by:
isSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- the primitive- Returns:
- whether
osm
is selected or not
-
setHighlightedVirtualNodes
public void setHighlightedVirtualNodes(Collection<WaySegment> waySegments)
Description copied from interface:OsmData
set what virtual nodes should be highlighted. Requires a Collection of *WaySegments* to avoid a VirtualNode class that wouldn't have much use otherwise.- Specified by:
setHighlightedVirtualNodes
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
waySegments
- Collection of way segments
-
setHighlightedWaySegments
public void setHighlightedWaySegments(Collection<WaySegment> waySegments)
Description copied from interface:OsmData
set what virtual ways should be highlighted.- Specified by:
setHighlightedWaySegments
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
waySegments
- Collection of way segments
-
setSelected
public void setSelected(Collection<? extends PrimitiveId> selection)
Description copied from interface:OsmData
Sets the current selection to the primitives inselection
and notifies allDataSelectionListener
.- Specified by:
setSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
selection
- the selection
-
setSelected
public void setSelected(PrimitiveId... osm)
Description copied from interface:OsmData
Sets the current selection to the primitives inosm
and notifies allDataSelectionListener
.- Specified by:
setSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- the primitives to set.null
values are ignored for now, but this may be removed in the future.
-
setSelected
private void setSelected(Stream<? extends PrimitiveId> stream)
-
addSelected
public void addSelected(Collection<? extends PrimitiveId> selection)
Description copied from interface:OsmData
Adds the primitives inselection
to the current selection and notifies allDataSelectionListener
.- Specified by:
addSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
selection
- the selection
-
addSelected
public void addSelected(PrimitiveId... osm)
Description copied from interface:OsmData
Adds the primitives inosm
to the current selection and notifies allDataSelectionListener
.- Specified by:
addSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- the primitives to add
-
addSelected
private void addSelected(Stream<? extends PrimitiveId> stream)
-
clearSelection
public void clearSelection(PrimitiveId... osm)
Description copied from interface:OsmData
Removes the selection from every value in the collection.- Specified by:
clearSelection
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- The collection of ids to remove the selection from.
-
clearSelection
public void clearSelection(Collection<? extends PrimitiveId> list)
Description copied from interface:OsmData
Removes the selection from every value in the collection.- Specified by:
clearSelection
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
list
- The collection of ids to remove the selection from.
-
clearSelection
public void clearSelection()
Description copied from interface:OsmData
Clears the current selection.- Specified by:
clearSelection
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
-
clearSelection
private void clearSelection(Stream<? extends PrimitiveId> stream)
-
toggleSelected
public void toggleSelected(Collection<? extends PrimitiveId> osm)
Description copied from interface:OsmData
Toggles the selected state of the given collection of primitives.- Specified by:
toggleSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- The primitives to toggle
-
toggleSelected
public void toggleSelected(PrimitiveId... osm)
Description copied from interface:OsmData
Toggles the selected state of the given collection of primitives.- Specified by:
toggleSelected
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
osm
- The primitives to toggle
-
toggleSelected
private void toggleSelected(Stream<? extends PrimitiveId> stream)
-
doSelectionChange
private boolean doSelectionChange(Function<Set<OsmPrimitive>,DataSelectionListener.SelectionChangeEvent> command)
Do a selection change.This is the only method that changes the current selection state.
- Parameters:
command
- A generator that generates theDataSelectionListener.SelectionChangeEvent
for the given base set of currently selected primitives.- Returns:
- true iff the command did change the selection.
- Since:
- 12048
-
getDataSourceArea
public Area getDataSourceArea()
Description copied from interface:Data
Returns the total area of downloaded data (the "yellow rectangles").- Specified by:
getDataSourceArea
in interfaceData
- Returns:
- Area object encompassing downloaded data.
-
getDataSourceBounds
public List<Bounds> getDataSourceBounds()
Description copied from interface:Data
Replies the list of data source bounds.
Dataset maintains a list of data sources which have been merged into the data set. Each of these sources can optionally declare a bounding box of the data it supplied to the dataset.
This method replies the list of defined (non
null
) bounding boxes.- Specified by:
getDataSourceBounds
in interfaceData
- Returns:
- the list of data source bounds. An empty list, if no non-null data source bounds are defined.
-
getDataSources
public Collection<DataSource> getDataSources()
Description copied from interface:Data
Returns the collection of data sources.- Specified by:
getDataSources
in interfaceData
- Returns:
- the collection of data sources.
-
getPrimitiveById
public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId)
Description copied from interface:OsmData
Returns a primitive with a given id from the data set. null, if no such primitive exists- Specified by:
getPrimitiveById
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Parameters:
primitiveId
- type and uniqueId of the primitive. Might be < 0 for newly created primitives- Returns:
- the primitive
-
getPrimitiveByIdChecked
private OsmPrimitive getPrimitiveByIdChecked(PrimitiveId primitiveId)
Show message and stack trace in log in case primitive is not found- Parameters:
primitiveId
- primitive id to look for- Returns:
- Primitive by id.
-
unlinkNodeFromWays
public Set<Way> unlinkNodeFromWays(Node node)
Removes all references from ways in this dataset to a particular node.- Parameters:
node
- the node- Returns:
- The set of ways that have been modified
- Throws:
IllegalStateException
- if the dataset is read-only
-
unlinkPrimitiveFromRelations
public Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive)
removes all references from relations in this dataset to this primitive- Parameters:
primitive
- the primitive- Returns:
- The set of relations that have been modified
- Throws:
IllegalStateException
- if the dataset is read-only
-
unlinkReferencesToPrimitive
public Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
Removes all references from other primitives to the referenced primitive.- Parameters:
referencedPrimitive
- the referenced primitive- Returns:
- The set of primitives that have been modified
- Throws:
IllegalStateException
- if the dataset is read-only
-
isModified
public boolean isModified()
Description copied from interface:OsmData
Replies true if there is at least one primitive in this dataset withIPrimitive.isModified()
==true
.- Specified by:
isModified
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- true if there is at least one primitive in this dataset with
IPrimitive.isModified()
==true
.
-
requiresUploadToServer
public boolean requiresUploadToServer()
Replies true if there is at least one primitive in this dataset which requires to be uploaded to server.- Returns:
- true if there is at least one primitive in this dataset which requires to be uploaded to server
- Since:
- 13161
-
addDataSetListener
public void addDataSetListener(DataSetListener dsl)
Adds a new data set listener.- Parameters:
dsl
- The data set listener to add
-
removeDataSetListener
public void removeDataSetListener(DataSetListener dsl)
Removes a data set listener.- Parameters:
dsl
- The data set listener to remove
-
beginUpdate
public void beginUpdate()
Can be called before bigger changes on dataset. Events are disabled untilendUpdate()
.DataSetListener.dataChanged(DataChangedEvent event)
event is triggered after end of changes
Typical use case should look like this:ds.beginUpdate(); try { ... } finally { ds.endUpdate(); }
- See Also:
endUpdate()
-
endUpdate
public void endUpdate()
Must be called after a previous call tobeginUpdate()
to fire change events.
Typical use case should look like this:ds.beginUpdate(); try { ... } finally { ds.endUpdate(); }
- See Also:
beginUpdate()
-
update
public void update(Runnable runnable)
Performs the update runnable betweenbeginUpdate()
/endUpdate()
calls.- Parameters:
runnable
- update action- Since:
- 16187
-
update
public <T,R> R update(Function<T,R> function, T t)
Performs the update function betweenbeginUpdate()
/endUpdate()
calls.- Type Parameters:
T
- argument typeR
- result type- Parameters:
function
- update functiont
- function argument- Returns:
- function result
- Since:
- 16187
-
update
public <R> R update(Supplier<R> supplier)
Performs the update supplier betweenbeginUpdate()
/endUpdate()
calls.- Type Parameters:
R
- result type- Parameters:
supplier
- update supplier- Returns:
- supplier result
- Since:
- 16187
-
fireEventToListeners
private void fireEventToListeners(AbstractDatasetChangedEvent event)
-
fireEvent
private void fireEvent(AbstractDatasetChangedEvent event)
-
firePrimitivesAdded
void firePrimitivesAdded(Collection<? extends OsmPrimitive> added, boolean wasIncomplete)
-
firePrimitivesRemoved
void firePrimitivesRemoved(Collection<? extends OsmPrimitive> removed, boolean wasComplete)
-
fireTagsChanged
void fireTagsChanged(OsmPrimitive prim, Map<String,String> originalKeys)
-
fireRelationMembersChanged
void fireRelationMembersChanged(Relation r)
-
fireNodeMoved
void fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth)
-
fireWayNodesChanged
void fireWayNodesChanged(Way way)
-
fireChangesetIdChanged
void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId)
-
firePrimitiveFlagsChanged
void firePrimitiveFlagsChanged(OsmPrimitive primitive)
-
fireFilterChanged
void fireFilterChanged()
-
fireHighlightingChanged
void fireHighlightingChanged()
-
invalidateEastNorthCache
public void invalidateEastNorthCache()
Invalidates the internal cache of projected east/north coordinates. This method can be invoked after the globally configured projection method changed.
-
cleanupDeletedPrimitives
public void cleanupDeletedPrimitives()
Cleanups all deleted primitives (really delete them from the dataset).
-
clear
public void clear()
Removes all primitives from the dataset and resets the currently selected primitives to the empty collection. Also notifies selection change listeners if necessary.- Specified by:
clear
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Throws:
IllegalStateException
- if the dataset is read-only
-
deleteInvisible
public void deleteInvisible()
Marks all "invisible" objects as deleted. These objects should be always marked as deleted when downloaded from the server. They can be undeleted later if necessary.- Throws:
IllegalStateException
- if the dataset is read-only
-
mergeFrom
public void mergeFrom(DataSet from)
Moves all primitives and datasources from DataSet "from" to this DataSet.- Parameters:
from
- The source DataSet
-
mergeFrom
public void mergeFrom(DataSet from, ProgressMonitor progressMonitor)
Moves all primitives and datasources from DataSet "from" to this DataSet.- Parameters:
from
- The source DataSetprogressMonitor
- The progress monitor- Throws:
IllegalStateException
- if the dataset is read-only
-
getConflicts
public ConflictCollection getConflicts()
Replies the set of conflicts currently managed in this layer.- Returns:
- the set of conflicts currently managed in this layer
- Since:
- 12672
-
getName
public String getName()
Description copied from interface:OsmData
Returns the name of this data set (optional).
-
setName
public void setName(String name)
Description copied from interface:OsmData
Sets the name of this data set.
-
projectionChanged
public void projectionChanged(Projection oldValue, Projection newValue)
- Specified by:
projectionChanged
in interfaceProjectionChangeListener
-
getDataSourceBoundingBox
public ProjectionBounds getDataSourceBoundingBox()
Description copied from interface:OsmData
Returns the data sources bounding box.- Specified by:
getDataSourceBoundingBox
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
- Returns:
- the data sources bounding box
-
getMappaintCacheIndex
public short getMappaintCacheIndex()
Returns mappaint cache index for this DataSet. If theAbstractPrimitive.mappaintCacheIdx
is not equal to the DataSet mappaint cache index, this means the cache for that primitive is out of date.- Returns:
- mappaint cache index
- Since:
- 13420
-
clearMappaintCache
public void clearMappaintCache()
Description copied from interface:OsmData
Clear the mappaint cache for this DataSet.- Specified by:
clearMappaintCache
in interfaceOsmData<OsmPrimitive,Node,Way,Relation>
-
lock
public void lock()
Description copied from interface:Lockable
Enables the read-only/locked mode.
-
unlock
public void unlock()
Description copied from interface:Lockable
Disables the read-only/locked mode.
-
isLocked
public boolean isLocked()
Description copied from interface:Lockable
Determines if this is read-only/locked (thus it cannot be modified).
-
checkModifiable
private void checkModifiable()
Checks the dataset is modifiable (not read-only).- Throws:
IllegalStateException
- if the dataset is read-only
-
getRemark
public String getRemark()
Returns an optional remark about this data set (used by Overpass API).- Returns:
- a remark about this data set, or
null
- Since:
- 14219
-
setRemark
public void setRemark(String remark)
Sets an optional remark about this data set (used by Overpass API).- Parameters:
remark
- a remark about this data set, ornull
- Since:
- 14219
-
getGPXNamespaces
public List<GpxData.XMLNamespace> getGPXNamespaces()
Gets the GPX (XML) namespaces if this DataSet was created from a GPX file- Returns:
- the GPXNamespaces or
null
-
setGPXNamespaces
public void setGPXNamespaces(List<GpxData.XMLNamespace> gpxNamespaces)
Sets the GPX (XML) namespaces- Parameters:
gpxNamespaces
- the GPXNamespaces to set
-
isEmpty
public boolean isEmpty()
Determines if this Dataset contains no primitives.- Returns:
- true if this Dataset contains no primitives
- Since:
- 14835
-
-