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 java.lang.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 java.awt.geom.Area
cachedDataSourceArea
private java.util.List<Bounds>
cachedDataSourceBounds
private java.util.List<AbstractDatasetChangedEvent>
cachedEvents
private java.util.Map<java.lang.String,java.lang.String>
changeSetTags
Holding bin for changeset tag information, to be applied when or if this is ever uploaded.private ConflictCollection
conflicts
private java.util.Set<OsmPrimitive>
currentSelectedPrimitives
The current selected primitives.private ListenerList<DataSourceListener>
dataSourceListeners
A list of listeners that listen to DataSource changes on this layerprivate java.util.Collection<DataSource>
dataSources
All data sources of this DataSet.private DownloadPolicy
downloadPolicy
private java.util.List<GpxData.XMLNamespace>
gpxNamespaces
Used to temporarily store namespaces from the GPX file in case the user converts back and forth.private java.util.Collection<WaySegment>
highlightedVirtualNodes
private java.util.Collection<WaySegment>
highlightedWaySegments
private ListenerList<HighlightUpdateListener>
highlightUpdateListeners
private java.util.concurrent.atomic.AtomicBoolean
isReadOnly
Flag used to know if the dataset should not be editableprivate java.util.concurrent.CopyOnWriteArrayList<DataSetListener>
listeners
private java.util.concurrent.locks.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 java.lang.String
name
private java.util.Map<PrimitiveId,OsmPrimitive>
primitivesMap
private java.lang.String
remark
private java.util.LinkedList<java.util.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 java.lang.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 java.lang.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(java.lang.String k, java.lang.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(java.util.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(java.util.Collection<? extends PrimitiveId> selection)
Adds the primitives inselection
to the current selection and notifies allDataSelectionListener
.private void
addSelected(java.util.stream.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(java.util.Collection<? extends PrimitiveId> list)
Removes the selection from every value in the collection.private void
clearSelection(java.util.stream.Stream<? extends PrimitiveId> stream)
void
clearSelection(PrimitiveId... osm)
Removes the selection from every value in the collection.void
clearSelectionHistory()
Clears selection history listjava.util.Map<OsmPrimitive,OsmPrimitive>
clonePrimitives(java.lang.Iterable<Node> nodes, java.lang.Iterable<Way> ways, java.lang.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(java.util.function.Function<java.util.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(java.util.Collection<? extends OsmPrimitive> added, boolean wasIncomplete)
(package private) void
firePrimitivesRemoved(java.util.Collection<? extends OsmPrimitive> removed, boolean wasComplete)
(package private) void
fireRelationMembersChanged(Relation r)
(package private) void
fireTagsChanged(OsmPrimitive prim, java.util.Map<java.lang.String,java.lang.String> originalKeys)
(package private) void
fireWayNodesChanged(Way way)
java.util.Collection<OsmPrimitive>
getAllSelected()
Replies an unmodifiable collection of primitives currently selected in this dataset, including deleted ones.java.util.Map<java.lang.String,java.lang.String>
getChangeSetTags()
Replies the map 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.java.awt.geom.Area
getDataSourceArea()
Returns the total area of downloaded data (the "yellow rectangles").ProjectionBounds
getDataSourceBoundingBox()
Returns the data sources bounding box.java.util.List<Bounds>
getDataSourceBounds()
Replies the list of data source bounds.java.util.Collection<DataSource>
getDataSources()
Returns the collection of data sources.DownloadPolicy
getDownloadPolicy()
Get the download policy.java.util.List<GpxData.XMLNamespace>
getGPXNamespaces()
Gets the GPX (XML) namespaces if this DataSet was created from a GPX filejava.util.Collection<WaySegment>
getHighlightedVirtualNodes()
Returns an unmodifiable collection of *WaySegments* whose virtual nodes should be highlighted.java.util.Collection<WaySegment>
getHighlightedWaySegments()
Returns an unmodifiable collection of WaySegments that should be highlighted.Way
getLastSelectedWay()
Returns the way selected last or null if no way primitives were selected or selection is empty.short
getMappaintCacheIndex()
Returns mappaint cache index for this DataSet.java.lang.String
getName()
Returns the name of this data set (optional).java.util.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>
java.util.Collection<T>getPrimitives(java.util.function.Predicate<? super OsmPrimitive> predicate)
Gets a filtered collection of primitives matching the given predicate.java.util.concurrent.locks.Lock
getReadLock()
Returns the lock used for reading.java.util.Collection<Relation>
getRelations()
Replies an unmodifiable collection of relations in this datasetjava.lang.String
getRemark()
Returns an optional remark about this data set (used by Overpass API).java.util.Collection<OsmPrimitive>
getSelectedNodesAndWays()
Returns selected nodes and ways.java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>>
getSelectionHistory()
Replies the history of JOSM selectionsUploadPolicy
getUploadPolicy()
Get the upload policy.java.lang.String
getVersion()
Replies the API version this dataset was created from.java.util.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
removePrimitiveFromStorage(OsmPrimitive primitive)
private void
removePrimitiveImpl(OsmPrimitive primitive)
void
removePrimitives(java.util.Collection<PrimitiveId> primitiveIds)
Removes primitives from the dataset.void
removePrimitives(PrimitiveId... primitiveIds)
Removes primitives from the dataset.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.java.util.List<Node>
searchNodes(BBox bbox)
Searches for nodes in the given bounding box.java.util.List<OsmPrimitive>
searchPrimitives(BBox bbox)
Searches for all primitives in the given bounding boxjava.util.List<Relation>
searchRelations(BBox bbox)
Searches for relations in the given bounding box.java.util.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(java.util.List<GpxData.XMLNamespace> gpxNamespaces)
Sets the GPX (XML) namespacesvoid
setHighlightedVirtualNodes(java.util.Collection<WaySegment> waySegments)
set what virtual nodes should be highlighted.void
setHighlightedWaySegments(java.util.Collection<WaySegment> waySegments)
set what virtual ways should be highlighted.void
setName(java.lang.String name)
Sets the name of this data set.void
setRemark(java.lang.String remark)
Sets an optional remark about this data set (used by Overpass API).void
setSelected(java.util.Collection<? extends PrimitiveId> selection)
Sets the current selection to the primitives inselection
and notifies allDataSelectionListener
.private void
setSelected(java.util.stream.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(java.lang.String version)
Sets the API version this dataset was created from.void
toggleSelected(java.util.Collection<? extends PrimitiveId> osm)
Toggles the selected state of the given collection of primitives.private void
toggleSelected(java.util.stream.Stream<? extends PrimitiveId> stream)
void
toggleSelected(PrimitiveId... osm)
Toggles the selected state of the given collection of primitives.java.util.Set<Way>
unlinkNodeFromWays(Node node)
Removes all references from ways in this dataset to a particular node.java.util.Set<Relation>
unlinkPrimitiveFromRelations(OsmPrimitive primitive)
removes all references from relations in this dataset to this primitivejava.util.Set<OsmPrimitive>
unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
Removes all references from other primitives to the referenced primitive.void
unlock()
Disables the read-only/locked mode.void
update(java.lang.Runnable runnable)
Performs the update runnable betweenbeginUpdate()
/endUpdate()
calls.<T,R>
Rupdate(java.util.function.Function<T,R> function, T t)
Performs the update function betweenbeginUpdate()
/endUpdate()
calls.<R> R
update(java.util.function.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 java.util.Map<PrimitiveId,OsmPrimitive> primitivesMap
-
listeners
private final java.util.concurrent.CopyOnWriteArrayList<DataSetListener> listeners
-
highlightedVirtualNodes
private java.util.Collection<WaySegment> highlightedVirtualNodes
-
highlightedWaySegments
private java.util.Collection<WaySegment> highlightedWaySegments
-
highlightUpdateListeners
private final ListenerList<HighlightUpdateListener> highlightUpdateListeners
-
updateCount
private int updateCount
-
cachedEvents
private final java.util.List<AbstractDatasetChangedEvent> cachedEvents
-
name
private java.lang.String name
-
downloadPolicy
private DownloadPolicy downloadPolicy
-
uploadPolicy
private UploadPolicy uploadPolicy
-
isReadOnly
private final java.util.concurrent.atomic.AtomicBoolean isReadOnly
Flag used to know if the dataset should not be editable
-
lock
private final java.util.concurrent.locks.ReadWriteLock lock
-
selectionLock
private final java.lang.Object selectionLock
The mutex lock that is used to synchronize selection changes.
-
currentSelectedPrimitives
private java.util.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 java.awt.geom.Area cachedDataSourceArea
-
cachedDataSourceBounds
private java.util.List<Bounds> cachedDataSourceBounds
-
dataSources
private final java.util.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
-
remark
private java.lang.String remark
-
gpxNamespaces
private java.util.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 java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>> selectionHistory
History of selections - shared by plugins and SelectionListDialog
-
version
private java.lang.String version
The API version that created this data set, if any.
-
changeSetTags
private final java.util.Map<java.lang.String,java.lang.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 java.util.Map<OsmPrimitive,OsmPrimitive> clonePrimitives(java.lang.Iterable<Node> nodes, java.lang.Iterable<Way> ways, java.lang.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(java.util.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 java.util.concurrent.locks.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 java.util.LinkedList<java.util.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 java.lang.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(java.lang.String version)
Sets the API version this dataset was created from.- Parameters:
version
- the API version, i.e. "0.6"- Throws:
java.lang.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 java.util.Map<java.lang.String,java.lang.String> getChangeSetTags()
Replies the map of changeset tags to be applied when or if this is ever uploaded.- Returns:
- the map of changeset tags
- See Also:
addChangeSetTag(java.lang.String, java.lang.String)
-
addChangeSetTag
public void addChangeSetTag(java.lang.String k, java.lang.String v)
Adds a new changeset tag.- Parameters:
k
- Keyv
- Value- See Also:
getChangeSetTags()
-
getPrimitives
public <T extends OsmPrimitive> java.util.Collection<T> getPrimitives(java.util.function.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 java.util.Collection<Node> getNodes()
Description copied from interface:OsmData
Replies an unmodifiable collection of nodes in this dataset
-
searchNodes
public java.util.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 java.util.Collection<Way> getWays()
Description copied from interface:OsmData
Replies an unmodifiable collection of ways in this dataset
-
searchWays
public java.util.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 java.util.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 java.util.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 java.util.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:
java.lang.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:
java.lang.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 from 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:
java.lang.IllegalStateException
- if the dataset is read-only
-
removePrimitives
public void removePrimitives(PrimitiveId... primitiveIds)
Removes primitives from the dataset. This method only removes the primitives from 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:
primitiveIds
- the ids of the primitive- Throws:
java.lang.IllegalStateException
- if the dataset is read-only- Since:
- 18724
-
removePrimitives
public void removePrimitives(java.util.Collection<PrimitiveId> primitiveIds)
Removes primitives from the dataset. This method only removes the primitives from 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:
primitiveIds
- the ids of the primitive- Throws:
java.lang.IllegalStateException
- if the dataset is read-only- Since:
- 18724
-
removePrimitiveImpl
private void removePrimitiveImpl(OsmPrimitive primitive)
-
removePrimitiveFromStorage
private void removePrimitiveFromStorage(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 java.util.Collection<OsmPrimitive> getSelectedNodesAndWays()
Returns selected nodes and ways.- Returns:
- selected nodes and ways
-
getLastSelectedWay
public Way getLastSelectedWay()
Returns the way selected last or null if no way primitives were selected or selection is empty.- Returns:
- last way in selection or null
- Since:
- 18468
-
getHighlightedVirtualNodes
public java.util.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 java.util.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 java.util.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(java.util.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(java.util.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(java.util.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(java.util.stream.Stream<? extends PrimitiveId> stream)
-
addSelected
public void addSelected(java.util.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(java.util.stream.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(java.util.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(java.util.stream.Stream<? extends PrimitiveId> stream)
-
toggleSelected
public void toggleSelected(java.util.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(java.util.stream.Stream<? extends PrimitiveId> stream)
-
doSelectionChange
private boolean doSelectionChange(java.util.function.Function<java.util.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 java.awt.geom.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 java.util.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 java.util.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 java.util.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:
java.lang.IllegalStateException
- if the dataset is read-only
-
unlinkPrimitiveFromRelations
public java.util.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:
java.lang.IllegalStateException
- if the dataset is read-only
-
unlinkReferencesToPrimitive
public java.util.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:
java.lang.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(java.lang.Runnable runnable)
Performs the update runnable betweenbeginUpdate()
/endUpdate()
calls.- Parameters:
runnable
- update action- Since:
- 16187
-
update
public <T,R> R update(java.util.function.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(java.util.function.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(java.util.Collection<? extends OsmPrimitive> added, boolean wasIncomplete)
-
firePrimitivesRemoved
void firePrimitivesRemoved(java.util.Collection<? extends OsmPrimitive> removed, boolean wasComplete)
-
fireTagsChanged
void fireTagsChanged(OsmPrimitive prim, java.util.Map<java.lang.String,java.lang.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.
-
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:
java.lang.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:
java.lang.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 java.lang.String getName()
Description copied from interface:OsmData
Returns the name of this data set (optional).
-
setName
public void setName(java.lang.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:
java.lang.IllegalStateException
- if the dataset is read-only
-
getRemark
public java.lang.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(java.lang.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 java.util.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(java.util.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
-
-