Class VectorDataSet
java.lang.Object
org.openstreetmap.josm.data.vector.VectorDataSet
- All Implemented Interfaces:
Data,IDataSelectionEventSource<VectorPrimitive,,VectorNode, VectorWay, VectorRelation, VectorDataSet> Lockable,OsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation>
public class VectorDataSet
extends Object
implements OsmData<VectorPrimitive,VectorNode,VectorWay,VectorRelation>, IDataSelectionEventSource<VectorPrimitive,VectorNode,VectorWay,VectorRelation,VectorDataSet>
A data class for Vector Data
- Since:
- 17862
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Set<PrimitiveId>The current selected primitives.private final VectorDataStoreprivate final ListenerList<DataSelectionListener>private DownloadPolicyDefault to normal download policyprotected static final floatThe distance to consider nodes duplicates -- mostly a memory saving measure.private final Collection<PrimitiveId>private final ListenerList<HighlightUpdateListener>private final ListenerList<IDataSelectionListener<VectorPrimitive,VectorNode, VectorWay, VectorRelation, VectorDataSet>> private booleanprivate shortprivate Stringprivate final ReentrantReadWriteLockprivate final Objectprivate ElemStylesThe paint style for this layerprivate UploadPolicyDefault to a blocked upload policyprivate intThe current zoom we are getting/adding to -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener that gets notified whenever way segment / virtual nodes highlights change.voidaddPrimitive(VectorPrimitive primitive) Add a primitive to the custom data storevoidaddSelected(Collection<? extends PrimitiveId> selection) Adds the primitives inselectionto the current selection and notifies allDataSelectionListener.voidaddSelected(PrimitiveId... osm) Adds the primitives inosmto the current selection and notifies allDataSelectionListener.private voidaddSelectedImpl(Stream<? extends PrimitiveId> osm) voidaddSelectionListener(DataSelectionListener listener) Add a listener that listens to selection changes in this specific data set.booleanaddSelectionListener(IDataSelectionListener<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> listener) Add a listenervoidaddTileData(MVTTile tile) Add tile data to this datasetvoidclear()Removes all primitives.voidClear the mappaint cache for this DataSet.voidClears the current selection.voidclearSelection(Collection<? extends PrimitiveId> list) Removes the selection from every value in the collection.voidclearSelection(PrimitiveId... osm) Removes the selection from every value in the collection.private voidclearSelectionImpl(Stream<? extends PrimitiveId> osm) booleancontainsNode(VectorNode vectorNode) Determines if the given node can be retrieved in the data set through its bounding box.booleancontainsRelation(VectorRelation vectorRelation) Determines if the given relation can be retrieved in the data set through its bounding box.booleancontainsWay(VectorWay vectorWay) Determines if the given way can be retrieved in the data set through its bounding box.private booleandoSelectionChange(Function<Set<VectorPrimitive>, IDataSelectionListener.SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet>> command) Do a selection change.Replies an unmodifiable collection of primitives currently selected in this dataset, including deleted ones.Get the best zoom datastoreReturns the collection of data sources.Get the download policy.Get the highlighted objectsReturns an unmodifiable collection of *WaySegments* whose virtual nodes should be highlighted.Returns an unmodifiable collection of WaySegments that should be highlighted.shortgetName()Returns the name of this data set (optional).getNodes()Replies an unmodifiable collection of nodes in this datasetgetPrimitiveById(PrimitiveId primitiveId) Get a primitive for an id<T extends VectorPrimitive>
Collection<T>getPrimitives(Predicate<? super VectorPrimitive> predicate) Gets a filtered collection of primitives matching the given predicate.getPrimitivesById(PrimitiveId... primitiveIds) Get all primitives for idsGet the current Read/Write lock.Replies an unmodifiable collection of relations in this datasetGet the styles for this layerGet the upload policy.Replies the API version this dataset was created from.getWays()Replies an unmodifiable collection of ways in this datasetintgetZoom()booleanisLocked()Determines if this is read-only/locked (thus it cannot be modified).booleanDetermines whether the given primitive is selected or notvoidlock()Enables the read-only/locked mode.voidRemoves a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)voidremovePrimitive(VectorPrimitive primitive) Remove a primitive from the custom data storevoidremoveSelectionListener(DataSelectionListener listener) Remove a listener that listens to selection changes in this specific data set.booleanremoveSelectionListener(IDataSelectionListener<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> listener) Remove a listenersearchNodes(BBox bbox) Searches for nodes in the given bounding box.searchRelations(BBox bbox) Searches for relations in the given bounding box.searchWays(BBox bbox) Searches for ways in the given bounding box.booleanDetermines whether the selection is empty or notvoidsetDownloadPolicy(DownloadPolicy downloadPolicy) Sets the download policy.voidsetHighlighted(Collection<PrimitiveId> primitives) Mark some primitives as highlighted.voidsetHighlightedVirtualNodes(Collection<WaySegment> waySegments) set what virtual nodes should be highlighted.voidsetHighlightedWaySegments(Collection<WaySegment> waySegments) set what virtual ways should be highlighted.voidsetInvisibleLayers(Collection<String> invisibleLayers) Mark some layers as invisiblevoidSets the name of this data set.voidsetSelected(Collection<? extends PrimitiveId> selection) Sets the current selection to the primitives inselectionand notifies allDataSelectionListener.voidsetSelected(PrimitiveId... osm) Sets the current selection to the primitives inosmand notifies allDataSelectionListener.private voidsetSelectedImpl(Stream<? extends PrimitiveId> osm) voidsetStyles(Collection<ElemStyles> styles) Set the styles for this layervoidsetUploadPolicy(UploadPolicy uploadPolicy) Sets the upload policy.voidsetZoom(int zoom) voidtoggleSelected(Collection<? extends PrimitiveId> osm) Toggles the selected state of the given collection of primitives.voidtoggleSelected(PrimitiveId... osm) Toggles the selected state of the given collection of primitives.private voidtoggleSelectedImpl(Stream<? extends PrimitiveId> osm) private static <T> Optional<T>tryRead(ReentrantReadWriteLock lock, Supplier<T> supplier) Try to read something (here to avoid boilerplate)private static voidtryWrite(ReentrantReadWriteLock lock, Runnable runnable) Try to write something (here to avoid boilerplate)voidunlock()Disables the read-only/locked mode.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openstreetmap.josm.data.Data
getDataSourceArea, getDataSourceBoundsMethods inherited from interface org.openstreetmap.josm.data.osm.OsmData
allModifiedPrimitives, allNonDeletedCompletePrimitives, allNonDeletedPhysicalPrimitives, allNonDeletedPrimitives, allPreservedPrimitives, allPrimitives, clearHighlightedVirtualNodes, clearHighlightedWaySegments, getDataSourceBoundingBox, getPrimitiveById, getSelected, getSelectedNodes, getSelectedRelations, getSelectedWays, isModified
-
Field Details
-
dataStoreMap
-
customDataStore
-
highlightUpdateListenerListenerList
-
dataSelectionListenerListenerList
-
lock
-
name
-
mappaintCacheIdx
-
selectionLock
-
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. -
listeners
-
readWriteLock
-
DUPE_NODE_DISTANCE
The distance to consider nodes duplicates -- mostly a memory saving measure. 0.000_000_1 ~1.2 cm (+- 5.57 mm) Descriptions from https://xkcd.com/2170/ Notes on https://wiki.openstreetmap.org/wiki/Node indicate that IEEE 32-bit floats should not be used at high longitude (0.000_01 precision)- See Also:
-
zoom
The current zoom we are getting/adding to -
downloadPolicy
Default to normal download policy -
uploadPolicy
Default to a blocked upload policy -
styles
The paint style for this layer -
highlighted
-
-
Constructor Details
-
VectorDataSet
public VectorDataSet()
-
-
Method Details
-
getDataSources
Description copied from interface:DataReturns the collection of data sources.- Specified by:
getDataSourcesin interfaceData- Returns:
- the collection of data sources.
-
lock
Description copied from interface:LockableEnables the read-only/locked mode. -
unlock
Description copied from interface:LockableDisables the read-only/locked mode. -
isLocked
Description copied from interface:LockableDetermines if this is read-only/locked (thus it cannot be modified). -
getVersion
Description copied from interface:OsmDataReplies the API version this dataset was created from. May be null.- Specified by:
getVersionin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- the API version this dataset was created from. May be null.
-
getName
Description copied from interface:OsmDataReturns the name of this data set (optional).- Specified by:
getNamein interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- the name of this data set. Can be
null
-
setName
Description copied from interface:OsmDataSets the name of this data set.- Specified by:
setNamein interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
name- the new name of this data set. Can benullto reset it
-
addPrimitive
Add a primitive to the custom data store- Specified by:
addPrimitivein interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
primitive- the primitive to add
-
removePrimitive
Remove a primitive from the custom data store- Parameters:
primitive- The primitive to add to the custom data store
-
clear
Description copied from interface:OsmDataRemoves all primitives.- Specified by:
clearin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation>
-
searchNodes
Description copied from interface:OsmDataSearches for nodes in the given bounding box.- Specified by:
searchNodesin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
bbox- the bounding box- Returns:
- List of nodes in the given bbox. Can be empty but not null
-
containsNode
Description copied from interface:OsmDataDetermines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test.- Specified by:
containsNodein interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
vectorNode- The node to search- Returns:
trueifncan be retrieved in this data set,falseotherwise
-
searchWays
Description copied from interface:OsmDataSearches for ways in the given bounding box.- Specified by:
searchWaysin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
bbox- the bounding box- Returns:
- List of ways in the given bbox. Can be empty but not null
-
containsWay
Description copied from interface:OsmDataDetermines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test.- Specified by:
containsWayin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
vectorWay- The way to search- Returns:
trueifwcan be retrieved in this data set,falseotherwise
-
searchRelations
Description copied from interface:OsmDataSearches for relations in the given bounding box.- Specified by:
searchRelationsin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
bbox- the bounding box- Returns:
- List of relations in the given bbox. Can be empty but not null
-
containsRelation
Description copied from interface:OsmDataDetermines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test.- Specified by:
containsRelationin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
vectorRelation- The relation to search- Returns:
trueifrcan be retrieved in this data set,falseotherwise
-
getPrimitiveById
Get a primitive for an id- Specified by:
getPrimitiveByIdin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
primitiveId- type and uniqueId of the primitive. Might be < 0 for newly created primitives- Returns:
- The primitive for the id. Please note that since this is vector data, there may be more primitives with this id.
Please use
getPrimitivesById(PrimitiveId...)to get all primitives for thatPrimitiveId.
-
getPrimitivesById
Get all primitives for ids- Parameters:
primitiveIds- The ids to search for- Returns:
- The primitives for the ids (note: as this is vector data, a
PrimitiveIdmay have multiple associated primitives)
-
getPrimitives
public <T extends VectorPrimitive> Collection<T> getPrimitives(Predicate<? super VectorPrimitive> predicate) Description copied from interface:OsmDataGets a filtered collection of primitives matching the given predicate.- Specified by:
getPrimitivesin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Type Parameters:
T- The primitive type.- Parameters:
predicate- The predicate to match- Returns:
- The list of primitives.
-
getNodes
Description copied from interface:OsmDataReplies an unmodifiable collection of nodes in this dataset- Specified by:
getNodesin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- an unmodifiable collection of nodes in this dataset
-
getWays
Description copied from interface:OsmDataReplies an unmodifiable collection of ways in this dataset- Specified by:
getWaysin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- an unmodifiable collection of ways in this dataset
-
getRelations
Description copied from interface:OsmDataReplies an unmodifiable collection of relations in this dataset- Specified by:
getRelationsin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- an unmodifiable collection of relations in this dataset
-
getDownloadPolicy
Description copied from interface:OsmDataGet the download policy.- Specified by:
getDownloadPolicyin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- the download policy
- See Also:
-
setDownloadPolicy
Description copied from interface:OsmDataSets the download policy.- Specified by:
setDownloadPolicyin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
downloadPolicy- the download policy. Must not be null- See Also:
-
getUploadPolicy
Description copied from interface:OsmDataGet the upload policy.- Specified by:
getUploadPolicyin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- the upload policy
- See Also:
-
setUploadPolicy
Description copied from interface:OsmDataSets the upload policy.- Specified by:
setUploadPolicyin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
uploadPolicy- the upload policy. Must not be null- See Also:
-
getReadLock
Get the current Read/Write lock. This changes based off of zoom level. Please do not use this in a finally block- Specified by:
getReadLockin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- The current read/write lock
-
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<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- unmodifiable collection of WaySegments
-
setHighlightedVirtualNodes
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<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
waySegments- Collection of way segments
-
getHighlightedWaySegments
Description copied from interface:OsmDataReturns an unmodifiable collection of WaySegments that should be highlighted.- Specified by:
getHighlightedWaySegmentsin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- unmodifiable collection of WaySegments
-
setHighlightedWaySegments
Description copied from interface:OsmDataset what virtual ways should be highlighted.- Specified by:
setHighlightedWaySegmentsin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
waySegments- Collection of way segments
-
setHighlighted
Mark some primitives as highlighted. API is *highly likely* to change, as the inherited methods are modified to accept primitives other than OSM primitives.- Parameters:
primitives- The primitives to highlight
-
getHighlighted
Get the highlighted objects- Returns:
- The highlighted objects
-
addHighlightUpdateListener
Description copied from interface:OsmDataAdds a listener that gets notified whenever way segment / virtual nodes highlights change.- Specified by:
addHighlightUpdateListenerin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
listener- The Listener
-
removeHighlightUpdateListener
Description copied from interface:OsmDataRemoves a listener that was added withOsmData.addHighlightUpdateListener(HighlightUpdateListener)- Specified by:
removeHighlightUpdateListenerin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
listener- The Listener
-
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<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- unmodifiable collection of primitives
-
getBestZoomDataStore
Get the best zoom datastore- Returns:
- A datastore with data, or
nullif no good datastore exists.
-
selectionEmpty
Description copied from interface:OsmDataDetermines whether the selection is empty or not- Specified by:
selectionEmptyin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Returns:
- whether the selection is empty or not
-
isSelected
Description copied from interface:OsmDataDetermines whether the given primitive is selected or not- Specified by:
isSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- the primitive- Returns:
- whether
osmis selected or not
-
toggleSelected
Description copied from interface:OsmDataToggles the selected state of the given collection of primitives.- Specified by:
toggleSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- The primitives to toggle
-
toggleSelected
Description copied from interface:OsmDataToggles the selected state of the given collection of primitives.- Specified by:
toggleSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- The primitives to toggle
-
toggleSelectedImpl
-
setSelected
Description copied from interface:OsmDataSets the current selection to the primitives inselectionand notifies allDataSelectionListener.- Specified by:
setSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
selection- the selection
-
setSelected
Description copied from interface:OsmDataSets the current selection to the primitives inosmand notifies allDataSelectionListener.- Specified by:
setSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- the primitives to set.nullvalues are ignored for now, but this may be removed in the future.
-
setSelectedImpl
-
addSelected
Description copied from interface:OsmDataAdds the primitives inselectionto the current selection and notifies allDataSelectionListener.- Specified by:
addSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
selection- the selection
-
addSelected
Description copied from interface:OsmDataAdds the primitives inosmto the current selection and notifies allDataSelectionListener.- Specified by:
addSelectedin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- the primitives to add
-
addSelectedImpl
-
clearSelection
Description copied from interface:OsmDataRemoves the selection from every value in the collection.- Specified by:
clearSelectionin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
osm- The collection of ids to remove the selection from.
-
clearSelection
Description copied from interface:OsmDataRemoves the selection from every value in the collection.- Specified by:
clearSelectionin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
list- The collection of ids to remove the selection from.
-
clearSelection
Description copied from interface:OsmDataClears the current selection.- Specified by:
clearSelectionin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation>
-
clearSelectionImpl
-
doSelectionChange
private boolean doSelectionChange(Function<Set<VectorPrimitive>, IDataSelectionListener.SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet>> command) Do a selection change.This is the only method that changes the current selection state.
- Parameters:
command- A generator that generates theIDataSelectionListener.SelectionChangeEventfor the given base set of currently selected primitives.- Returns:
- true iff the command did change the selection.
-
addSelectionListener
Description copied from interface:OsmDataAdd a listener that listens to selection changes in this specific data set.- Specified by:
addSelectionListenerin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
listener- The listener.- See Also:
-
removeSelectionListener
Description copied from interface:OsmDataRemove a listener that listens to selection changes in this specific data set.- Specified by:
removeSelectionListenerin interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation> - Parameters:
listener- The listener.- See Also:
-
getMappaintCacheIndex
-
clearMappaintCache
Description copied from interface:OsmDataClear the mappaint cache for this DataSet.- Specified by:
clearMappaintCachein interfaceOsmData<VectorPrimitive,VectorNode, VectorWay, VectorRelation>
-
setZoom
-
getZoom
-
addTileData
Add tile data to this dataset- Parameters:
tile- The tile to add
-
tryRead
Try to read something (here to avoid boilerplate)- Type Parameters:
T- The return type- Parameters:
lock- The locksupplier- The reading function- Returns:
- The optional return
-
tryWrite
Try to write something (here to avoid boilerplate)- Parameters:
lock- lockrunnable- The writing function
-
getStyles
Get the styles for this layer- Returns:
- The styles
-
setStyles
Set the styles for this layer- Parameters:
styles- The styles to set for this layer
-
setInvisibleLayers
Mark some layers as invisible- Parameters:
invisibleLayers- The layer to not show
-
addSelectionListener
public boolean addSelectionListener(IDataSelectionListener<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> listener) Description copied from interface:IDataSelectionEventSourceAdd a listener- Specified by:
addSelectionListenerin interfaceIDataSelectionEventSource<VectorPrimitive,VectorNode, VectorWay, VectorRelation, VectorDataSet> - Parameters:
listener- The listener to add- Returns:
trueif the listener was added
-
removeSelectionListener
public boolean removeSelectionListener(IDataSelectionListener<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> listener) Description copied from interface:IDataSelectionEventSourceRemove a listener- Specified by:
removeSelectionListenerin interfaceIDataSelectionEventSource<VectorPrimitive,VectorNode, VectorWay, VectorRelation, VectorDataSet> - Parameters:
listener- The listener to remove- Returns:
trueif the listener was removed
-