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>allPrimitivesprivate java.awt.geom.AreacachedDataSourceAreaprivate java.util.List<Bounds>cachedDataSourceBoundsprivate java.util.List<AbstractDatasetChangedEvent>cachedEventsprivate java.util.Map<java.lang.String,java.lang.String>changeSetTagsHolding bin for changeset tag information, to be applied when or if this is ever uploaded.private ConflictCollectionconflictsprivate java.util.Set<OsmPrimitive>currentSelectedPrimitivesThe current selected primitives.private ListenerList<DataSourceListener>dataSourceListenersA list of listeners that listen to DataSource changes on this layerprivate java.util.Collection<DataSource>dataSourcesAll data sources of this DataSet.private DownloadPolicydownloadPolicyprivate java.util.List<GpxData.XMLNamespace>gpxNamespacesUsed to temporarily store namespaces from the GPX file in case the user converts back and forth.private java.util.Collection<WaySegment>highlightedVirtualNodesprivate java.util.Collection<WaySegment>highlightedWaySegmentsprivate ListenerList<HighlightUpdateListener>highlightUpdateListenersprivate java.util.concurrent.atomic.AtomicBooleanisReadOnlyFlag used to know if the dataset should not be editableprivate java.util.concurrent.CopyOnWriteArrayList<DataSetListener>listenersprivate java.util.concurrent.locks.ReadWriteLocklockprivate shortmappaintCacheIdxprivate static intMAX_EVENTSMaximum number of events to kept between beginUpdate/endUpdate.private static intMAX_SINGLE_EVENTSMaximum number of events that can be fired between beginUpdate/endUpdate to be send as single events (ie without DatasetChangedEvent)private java.lang.Stringnameprivate java.util.Map<PrimitiveId,OsmPrimitive>primitivesMapprivate java.lang.Stringremarkprivate java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>>selectionHistoryHistory of selections - shared by plugins and SelectionListDialogprivate ListenerList<DataSelectionListener>selectionListenersA list of listeners that listen to selection changes on this layer.private java.lang.ObjectselectionLockThe mutex lock that is used to synchronize selection changes.private QuadBucketPrimitiveStore<Node,Way,Relation>storeprivate intupdateCountprivate UploadPolicyuploadPolicyprivate java.lang.StringversionThe API version that created this data set, if any. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeSetTag(java.lang.String k, java.lang.String v)Adds a new changeset tag.voidaddDataSetListener(DataSetListener dsl)Adds a new data set listener.booleanaddDataSource(DataSource source)Adds a new data source.voidaddDataSourceListener(DataSourceListener listener)Adds a listener that gets notified whenever the data sources changebooleanaddDataSources(java.util.Collection<DataSource> sources)Adds new data sources.voidaddHighlightUpdateListener(HighlightUpdateListener listener)Adds a listener that gets notified whenever way segment / virtual nodes highlights change.voidaddPrimitive(OsmPrimitive primitive)Adds a primitive to the dataset.voidaddPrimitiveRecursive(OsmPrimitive primitive)Adds recursively a primitive, and all its children, to the dataset.voidaddSelected(java.util.Collection<? extends PrimitiveId> selection)Adds the primitives inselectionto the current selection and notifies allDataSelectionListener.private voidaddSelected(java.util.stream.Stream<? extends PrimitiveId> stream)voidaddSelected(PrimitiveId... osm)Adds the primitives inosmto the current selection and notifies allDataSelectionListener.voidaddSelectionListener(DataSelectionListener listener)Add a listener that listens to selection changes in this specific data set.voidbeginUpdate()Can be called before bigger changes on dataset.private voidcheckModifiable()Checks the dataset is modifiable (not read-only).voidcleanupDeletedPrimitives()Cleanups all deleted primitives (really delete them from the dataset).voidclear()Removes all primitives from the dataset and resets the currently selected primitives to the empty collection.voidclearMappaintCache()Clear the mappaint cache for this DataSet.voidclearSelection()Clears the current selection.voidclearSelection(java.util.Collection<? extends PrimitiveId> list)Removes the selection from every value in the collection.private voidclearSelection(java.util.stream.Stream<? extends PrimitiveId> stream)voidclearSelection(PrimitiveId... osm)Removes the selection from every value in the collection.voidclearSelectionHistory()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.booleancontainsNode(Node n)Determines if the given node can be retrieved in the data set through its bounding box.booleancontainsRelation(Relation r)Determines if the given relation can be retrieved in the data set through its bounding box.booleancontainsWay(Way w)Determines if the given way can be retrieved in the data set through its bounding box.voiddeleteInvisible()Marks all "invisible" objects as deleted.private static voiddeleteWay(Way way)private booleandoSelectionChange(java.util.function.Function<java.util.Set<OsmPrimitive>,DataSelectionListener.SelectionChangeEvent> command)Do a selection change.voidendUpdate()Must be called after a previous call tobeginUpdate()to fire change events.(package private) voidfireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId)private voidfireEvent(AbstractDatasetChangedEvent event)private voidfireEventToListeners(AbstractDatasetChangedEvent event)(package private) voidfireFilterChanged()(package private) voidfireHighlightingChanged()(package private) voidfireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth)(package private) voidfirePrimitiveFlagsChanged(OsmPrimitive primitive)(package private) voidfirePrimitivesAdded(java.util.Collection<? extends OsmPrimitive> added, boolean wasIncomplete)(package private) voidfirePrimitivesRemoved(java.util.Collection<? extends OsmPrimitive> removed, boolean wasComplete)(package private) voidfireRelationMembersChanged(Relation r)(package private) voidfireTagsChanged(OsmPrimitive prim, java.util.Map<java.lang.String,java.lang.String> originalKeys)(package private) voidfireWayNodesChanged(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.ConflictCollectiongetConflicts()Replies the set of conflicts currently managed in this layer.java.awt.geom.AreagetDataSourceArea()Returns the total area of downloaded data (the "yellow rectangles").ProjectionBoundsgetDataSourceBoundingBox()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.DownloadPolicygetDownloadPolicy()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.WaygetLastSelectedWay()Returns the way selected last or null if no way primitives were selected or selection is empty.shortgetMappaintCacheIndex()Returns mappaint cache index for this DataSet.java.lang.StringgetName()Returns the name of this data set (optional).java.util.Collection<Node>getNodes()Replies an unmodifiable collection of nodes in this datasetOsmPrimitivegetPrimitiveById(PrimitiveId primitiveId)Returns a primitive with a given id from the data set.private OsmPrimitivegetPrimitiveByIdChecked(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.LockgetReadLock()Returns the lock used for reading.java.util.Collection<Relation>getRelations()Replies an unmodifiable collection of relations in this datasetjava.lang.StringgetRemark()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 selectionsUploadPolicygetUploadPolicy()Get the upload policy.java.lang.StringgetVersion()Replies the API version this dataset was created from.java.util.Collection<Way>getWays()Replies an unmodifiable collection of ways in this datasetvoidinvalidateEastNorthCache()Invalidates the internal cache of projected east/north coordinates.booleanisEmpty()Determines if this Dataset contains no primitives.booleanisLocked()Determines if this is read-only/locked (thus it cannot be modified).booleanisModified()Replies true if there is at least one primitive in this dataset withIPrimitive.isModified()==true.booleanisSelected(OsmPrimitive osm)Determines whether the given primitive is selected or notvoidlock()Enables the read-only/locked mode.voidmergeFrom(DataSet from)Moves all primitives and datasources from DataSet "from" to this DataSet.voidmergeFrom(DataSet from, ProgressMonitor progressMonitor)Moves all primitives and datasources from DataSet "from" to this DataSet.voidprojectionChanged(Projection oldValue, Projection newValue)voidremoveDataSetListener(DataSetListener dsl)Removes a data set listener.voidremoveDataSourceListener(DataSourceListener listener)Removes a listener that gets notified whenever the data sources changevoidremoveHighlightUpdateListener(HighlightUpdateListener listener)Removes a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)(package private) voidremovePrimitive(OsmPrimitive primitive)voidremovePrimitive(PrimitiveId primitiveId)Removes a primitive from the dataset.private voidremovePrimitiveFromStorage(OsmPrimitive primitive)private voidremovePrimitiveImpl(OsmPrimitive primitive)voidremovePrimitives(java.util.Collection<PrimitiveId> primitiveIds)Removes primitives from the dataset.voidremovePrimitives(PrimitiveId... primitiveIds)Removes primitives from the dataset.voidremoveSelectionListener(DataSelectionListener listener)Remove a listener that listens to selection changes in this specific data set.booleanrequiresUploadToServer()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.booleanselectionEmpty()Determines whether the selection is empty or notvoidsetDownloadPolicy(DownloadPolicy downloadPolicy)Sets the download policy.voidsetGPXNamespaces(java.util.List<GpxData.XMLNamespace> gpxNamespaces)Sets the GPX (XML) namespacesvoidsetHighlightedVirtualNodes(java.util.Collection<WaySegment> waySegments)set what virtual nodes should be highlighted.voidsetHighlightedWaySegments(java.util.Collection<WaySegment> waySegments)set what virtual ways should be highlighted.voidsetName(java.lang.String name)Sets the name of this data set.voidsetRemark(java.lang.String remark)Sets an optional remark about this data set (used by Overpass API).voidsetSelected(java.util.Collection<? extends PrimitiveId> selection)Sets the current selection to the primitives inselectionand notifies allDataSelectionListener.private voidsetSelected(java.util.stream.Stream<? extends PrimitiveId> stream)voidsetSelected(PrimitiveId... osm)Sets the current selection to the primitives inosmand notifies allDataSelectionListener.voidsetUploadPolicy(UploadPolicy uploadPolicy)Sets the upload policy.voidsetVersion(java.lang.String version)Sets the API version this dataset was created from.voidtoggleSelected(java.util.Collection<? extends PrimitiveId> osm)Toggles the selected state of the given collection of primitives.private voidtoggleSelected(java.util.stream.Stream<? extends PrimitiveId> stream)voidtoggleSelected(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.voidunlock()Disables the read-only/locked mode.voidupdate(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> Rupdate(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 otherDataSetto copy the contents of this dataset from.- Since:
 - 10346
 
 
- 
DataSet
public DataSet(OsmPrimitive... osmPrimitives)
Constructs a newDataSetinitially 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:
 trueif 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:
 trueif the collection changed as a result of the call- Since:
 - 11626
 
 
- 
getReadLock
public java.util.concurrent.locks.Lock getReadLock()
Description copied from interface:OsmDataReturns the lock used for reading.- Specified by:
 getReadLockin 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:OsmDataReplies the API version this dataset was created from. May be null.- Specified by:
 getVersionin 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:OsmDataGet the download policy.- Specified by:
 getDownloadPolicyin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - the download policy
 - See Also:
 OsmData.setDownloadPolicy(DownloadPolicy)
 
- 
setDownloadPolicy
public void setDownloadPolicy(DownloadPolicy downloadPolicy)
Description copied from interface:OsmDataSets the download policy.- Specified by:
 setDownloadPolicyin 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:OsmDataGet the upload policy.- Specified by:
 getUploadPolicyin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - the upload policy
 - See Also:
 OsmData.setUploadPolicy(UploadPolicy)
 
- 
setUploadPolicy
public void setUploadPolicy(UploadPolicy uploadPolicy)
Description copied from interface:OsmDataSets the upload policy.- Specified by:
 setUploadPolicyin 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:OsmDataGets a filtered collection of primitives matching the given predicate.- Specified by:
 getPrimitivesin 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:OsmDataReplies an unmodifiable collection of nodes in this dataset 
- 
searchNodes
public java.util.List<Node> searchNodes(BBox bbox)
Description copied from interface:OsmDataSearches for nodes in the given bounding box.- Specified by:
 searchNodesin 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:OsmDataReplies an unmodifiable collection of ways in this dataset 
- 
searchWays
public java.util.List<Way> searchWays(BBox bbox)
Description copied from interface:OsmDataSearches for ways in the given bounding box.- Specified by:
 searchWaysin 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:OsmDataSearches for relations in the given bounding box.- Specified by:
 searchRelationsin 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:OsmDataReplies an unmodifiable collection of relations in this dataset- Specified by:
 getRelationsin 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:
 containsNodein interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 n- The node to search- Returns:
 trueifncan be retrieved in this data set,falseotherwise- 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:
 containsWayin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 w- The way to search- Returns:
 trueifwcan be retrieved in this data set,falseotherwise- 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:
 containsRelationin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 r- The relation to search- Returns:
 trueifrcan be retrieved in this data set,falseotherwise- Since:
 - 7501
 
 
- 
addPrimitive
public void addPrimitive(OsmPrimitive primitive)
Adds a primitive to the dataset.- Specified by:
 addPrimitivein 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:OsmDataAdd a listener that listens to selection changes in this specific data set.- Specified by:
 addSelectionListenerin 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:OsmDataRemove a listener that listens to selection changes in this specific data set.- Specified by:
 removeSelectionListenerin 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:OsmDataReturns 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:
 getHighlightedVirtualNodesin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - unmodifiable collection of WaySegments
 
 
- 
getHighlightedWaySegments
public java.util.Collection<WaySegment> getHighlightedWaySegments()
Description copied from interface:OsmDataReturns an unmodifiable collection of WaySegments that should be highlighted.- Specified by:
 getHighlightedWaySegmentsin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - unmodifiable collection of WaySegments
 
 
- 
addHighlightUpdateListener
public void addHighlightUpdateListener(HighlightUpdateListener listener)
Description copied from interface:OsmDataAdds a listener that gets notified whenever way segment / virtual nodes highlights change.- Specified by:
 addHighlightUpdateListenerin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 listener- The Listener
 
- 
removeHighlightUpdateListener
public void removeHighlightUpdateListener(HighlightUpdateListener listener)
Description copied from interface:OsmDataRemoves a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)- Specified by:
 removeHighlightUpdateListenerin 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:OsmDataReplies 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:
 getAllSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - unmodifiable collection of primitives
 
 
- 
selectionEmpty
public boolean selectionEmpty()
Description copied from interface:OsmDataDetermines whether the selection is empty or not- Specified by:
 selectionEmptyin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - whether the selection is empty or not
 
 
- 
isSelected
public boolean isSelected(OsmPrimitive osm)
Description copied from interface:OsmDataDetermines whether the given primitive is selected or not- Specified by:
 isSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 osm- the primitive- Returns:
 - whether 
osmis selected or not 
 
- 
setHighlightedVirtualNodes
public void setHighlightedVirtualNodes(java.util.Collection<WaySegment> waySegments)
Description copied from interface:OsmDataset 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:
 setHighlightedVirtualNodesin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 waySegments- Collection of way segments
 
- 
setHighlightedWaySegments
public void setHighlightedWaySegments(java.util.Collection<WaySegment> waySegments)
Description copied from interface:OsmDataset what virtual ways should be highlighted.- Specified by:
 setHighlightedWaySegmentsin 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:OsmDataSets the current selection to the primitives inselectionand notifies allDataSelectionListener.- Specified by:
 setSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 selection- the selection
 
- 
setSelected
public void setSelected(PrimitiveId... osm)
Description copied from interface:OsmDataSets the current selection to the primitives inosmand notifies allDataSelectionListener.- Specified by:
 setSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 osm- the primitives to set.nullvalues 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:OsmDataAdds the primitives inselectionto the current selection and notifies allDataSelectionListener.- Specified by:
 addSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 selection- the selection
 
- 
addSelected
public void addSelected(PrimitiveId... osm)
Description copied from interface:OsmDataAdds the primitives inosmto the current selection and notifies allDataSelectionListener.- Specified by:
 addSelectedin 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:OsmDataRemoves the selection from every value in the collection.- Specified by:
 clearSelectionin 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:OsmDataRemoves the selection from every value in the collection.- Specified by:
 clearSelectionin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 list- The collection of ids to remove the selection from.
 
- 
clearSelection
public void clearSelection()
Description copied from interface:OsmDataClears the current selection.- Specified by:
 clearSelectionin 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:OsmDataToggles the selected state of the given collection of primitives.- Specified by:
 toggleSelectedin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Parameters:
 osm- The primitives to toggle
 
- 
toggleSelected
public void toggleSelected(PrimitiveId... osm)
Description copied from interface:OsmDataToggles the selected state of the given collection of primitives.- Specified by:
 toggleSelectedin 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.SelectionChangeEventfor 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:DataReturns the total area of downloaded data (the "yellow rectangles").- Specified by:
 getDataSourceAreain interfaceData- Returns:
 - Area object encompassing downloaded data.
 
 
- 
getDataSourceBounds
public java.util.List<Bounds> getDataSourceBounds()
Description copied from interface:DataReplies 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:
 getDataSourceBoundsin 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:DataReturns the collection of data sources.- Specified by:
 getDataSourcesin interfaceData- Returns:
 - the collection of data sources.
 
 
- 
getPrimitiveById
public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId)
Description copied from interface:OsmDataReturns a primitive with a given id from the data set. null, if no such primitive exists- Specified by:
 getPrimitiveByIdin 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:OsmDataReplies true if there is at least one primitive in this dataset withIPrimitive.isModified()==true.- Specified by:
 isModifiedin 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:OsmDataReturns the name of this data set (optional). 
- 
setName
public void setName(java.lang.String name)
Description copied from interface:OsmDataSets the name of this data set. 
- 
projectionChanged
public void projectionChanged(Projection oldValue, Projection newValue)
- Specified by:
 projectionChangedin interfaceProjectionChangeListener
 
- 
getDataSourceBoundingBox
public ProjectionBounds getDataSourceBoundingBox()
Description copied from interface:OsmDataReturns the data sources bounding box.- Specified by:
 getDataSourceBoundingBoxin interfaceOsmData<OsmPrimitive,Node,Way,Relation>- Returns:
 - the data sources bounding box
 
 
- 
getMappaintCacheIndex
public short getMappaintCacheIndex()
Returns mappaint cache index for this DataSet. If theAbstractPrimitive.mappaintCacheIdxis 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:OsmDataClear the mappaint cache for this DataSet.- Specified by:
 clearMappaintCachein interfaceOsmData<OsmPrimitive,Node,Way,Relation>
 
- 
lock
public void lock()
Description copied from interface:LockableEnables the read-only/locked mode. 
- 
unlock
public void unlock()
Description copied from interface:LockableDisables the read-only/locked mode. 
- 
isLocked
public boolean isLocked()
Description copied from interface:LockableDetermines 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
 
 
 - 
 
 -