public final class DataSet extends java.lang.Object implements Data, java.lang.Cloneable, ProjectionChangeListener
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 ticketModifier and Type | Field and Description |
---|---|
private Storage<OsmPrimitive> |
allPrimitives |
private AutoCompletionManager |
autocomplete
Maintains a list of used tags for autocompletion.
|
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.
|
java.util.Collection<DataSource> |
dataSources
All data sources of this DataSet.
|
private java.util.Collection<WaySegment> |
highlightedVirtualNodes |
private java.util.Collection<WaySegment> |
highlightedWaySegments |
private int |
highlightUpdateCount |
private java.util.concurrent.CopyOnWriteArrayList<DataSetListener> |
listeners |
private java.util.concurrent.locks.ReadWriteLock |
lock |
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 QuadBuckets<Node> |
nodes
All nodes goes here, even when included in other data (ways etc).
|
private java.util.Map<PrimitiveId,OsmPrimitive> |
primitivesMap |
private java.util.Collection<Relation> |
relations
All relations/relationships
|
private java.util.Set<OsmPrimitive> |
selectedPrimitives |
private java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>> |
selectionHistory
History of selections - shared by plugins and SelectionListDialog
|
private java.lang.Object |
selectionLock |
private java.util.Collection<OsmPrimitive> |
selectionSnapshot |
private static java.util.Collection<SelectionChangedListener> |
selListeners
A list of listeners to selection changed events.
|
private int |
updateCount |
private boolean |
uploadDiscouraged |
private java.lang.String |
version
The API version that created this data set, if any.
|
private QuadBuckets<Way> |
ways
All ways (Streets etc.) in the DataSet.
|
Constructor and Description |
---|
DataSet()
Constructs a new
DataSet . |
Modifier and Type | Method and Description |
---|---|
private boolean |
__toggleSelected(PrimitiveId primitiveId) |
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.
|
void |
addPrimitive(OsmPrimitive primitive)
Adds a primitive to the dataset.
|
void |
addSelected(java.util.Collection<? extends PrimitiveId> selection)
Adds the primitives in
selection to the current selection
and notifies all SelectionChangedListener . |
private boolean |
addSelected(java.util.Collection<? extends PrimitiveId> selection,
boolean fireSelectionChangeEvent)
Adds the primitives in
selection to the current selection. |
void |
addSelected(PrimitiveId... osm)
Adds the primitives in
osm to the current selection
and notifies all SelectionChangedListener . |
static void |
addSelectionListener(SelectionChangedListener listener)
Adds a new selection listener.
|
java.util.Collection<OsmPrimitive> |
allModifiedPrimitives()
Returns a collection containing all modified primitives.
|
java.util.Collection<OsmPrimitive> |
allNonDeletedCompletePrimitives()
Returns a collection containing all not-deleted complete primitives.
|
java.util.Collection<OsmPrimitive> |
allNonDeletedPhysicalPrimitives()
Returns a collection containing all not-deleted complete physical primitives.
|
java.util.Collection<OsmPrimitive> |
allNonDeletedPrimitives()
Returns a collection containing all not-deleted primitives.
|
java.util.Collection<OsmPrimitive> |
allPrimitives()
Returns a collection containing all primitives of the dataset.
|
void |
beginUpdate()
Can be called before bigger changes on dataset.
|
private boolean |
cleanupDeleted(java.util.Iterator<? extends OsmPrimitive> it) |
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 |
clearHighlightedVirtualNodes()
clear all highlights of virtual nodes
|
void |
clearHighlightedWaySegments()
clear all highlights of way segments
|
void |
clearSelection()
Clears the current selection.
|
void |
clearSelection(java.util.Collection<? extends PrimitiveId> list)
Removes the selection from every value in the collection.
|
void |
clearSelection(PrimitiveId... osm)
Removes the selection from every value in the collection.
|
void |
clearSelectionHistory()
Clears selection history list
|
DataSet |
clone() |
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) |
void |
endUpdate() |
(package private) void |
fireChangesetIdChanged(OsmPrimitive primitive,
int oldChangesetId,
int newChangesetId) |
private void |
fireEvent(AbstractDatasetChangedEvent event) |
private void |
fireEventToListeners(AbstractDatasetChangedEvent event) |
(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) |
void |
fireSelectionChanged()
Notifies all registered
SelectionChangedListener about the current selection in
this dataset. |
(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.
|
AutoCompletionManager |
getAutoCompletionManager()
Returns the autocompletion manager, which maintains a list of used tags for autocompletion.
|
java.util.Map<java.lang.String,java.lang.String> |
getChangeSetTags()
Replies the set of changeset tags to be applied when or if this is ever uploaded.
|
java.awt.geom.Area |
getDataSourceArea()
Returns the total area of downloaded data (the "yellow rectangles").
|
ProjectionBounds |
getDataSourceBoundingBox() |
java.util.List<Bounds> |
getDataSourceBounds()
Replies the list of data source bounds.
|
java.util.Collection<DataSource> |
getDataSources()
Returns the collection of data sources.
|
java.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.
|
int |
getHighlightUpdateCount()
This method can be used to detect changes in highlight state of primitives.
|
java.util.Collection<Node> |
getNodes()
Replies an unmodifiable collection of nodes in this dataset
|
OsmPrimitive |
getPrimitiveById(long id,
OsmPrimitiveType type)
Returns a primitive with a given id from the data set.
|
OsmPrimitive |
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
|
private <T extends OsmPrimitive> |
getPrimitives(Predicate<OsmPrimitive> 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 dataset
|
java.util.Collection<OsmPrimitive> |
getSelected()
Replies an unmodifiable collection of primitives currently selected
in this dataset, except deleted ones.
|
java.util.Collection<Node> |
getSelectedNodes()
Returns selected nodes.
|
java.util.Collection<OsmPrimitive> |
getSelectedNodesAndWays()
Returns selected nodes and ways.
|
java.util.Collection<Relation> |
getSelectedRelations()
Returns selected relations.
|
java.util.Collection<Way> |
getSelectedWays()
Returns selected ways.
|
java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>> |
getSelectionHistory()
Replies the history of JOSM selections
|
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 dataset
|
void |
invalidateEastNorthCache()
Invalidates the internal cache of projected east/north coordinates.
|
boolean |
isModified()
Replies true if there is at least one primitive in this dataset with
AbstractPrimitive.isModified() == true . |
boolean |
isSelected(OsmPrimitive osm)
Determines whether the given primitive is selected or not
|
boolean |
isUploadDiscouraged()
Determines if upload is being discouraged (i.e.
|
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) |
private void |
reindexNode(Node node,
LatLon newCoor,
EastNorth eastNorth) |
private static void |
reindexRelation(Relation relation) |
private void |
reindexWay(Way way) |
void |
removeDataSetListener(DataSetListener dsl)
Removes a data set listener.
|
void |
removePrimitive(PrimitiveId primitiveId)
Removes a primitive from the dataset.
|
static void |
removeSelectionListener(SelectionChangedListener listener)
Removes a selection listener.
|
java.util.List<Node> |
searchNodes(BBox bbox)
Searches for nodes in the given bounding box.
|
java.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 not
|
void |
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 |
setSelected(java.util.Collection<? extends PrimitiveId> selection)
Sets the current selection to the primitives in
selection
and notifies all SelectionChangedListener . |
void |
setSelected(java.util.Collection<? extends PrimitiveId> selection,
boolean fireSelectionChangeEvent)
Sets the current selection to the primitives in
selection . |
void |
setSelected(PrimitiveId... osm)
Sets the current selection to the primitives in
osm
and notifies all SelectionChangedListener . |
void |
setUploadDiscouraged(boolean uploadDiscouraged)
Sets the "upload discouraged" flag.
|
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.
|
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 primitive
|
java.util.Set<OsmPrimitive> |
unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
Removes all references from other primitives to the referenced primitive.
|
private static final int MAX_SINGLE_EVENTS
private static final int MAX_EVENTS
private final Storage<OsmPrimitive> allPrimitives
private final java.util.Map<PrimitiveId,OsmPrimitive> primitivesMap
private final java.util.concurrent.CopyOnWriteArrayList<DataSetListener> listeners
private java.util.Collection<WaySegment> highlightedVirtualNodes
private java.util.Collection<WaySegment> highlightedWaySegments
private int updateCount
private final java.util.List<AbstractDatasetChangedEvent> cachedEvents
private int highlightUpdateCount
private boolean uploadDiscouraged
private final java.util.concurrent.locks.ReadWriteLock lock
private final java.lang.Object selectionLock
private final java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>> selectionHistory
private AutoCompletionManager autocomplete
private java.lang.String version
private final java.util.Map<java.lang.String,java.lang.String> changeSetTags
private final QuadBuckets<Node> nodes
private final QuadBuckets<Way> ways
public final java.util.Collection<DataSource> dataSources
private static final java.util.Collection<SelectionChangedListener> selListeners
private java.util.Set<OsmPrimitive> selectedPrimitives
private java.util.Collection<OsmPrimitive> selectionSnapshot
public DataSet()
DataSet
.public java.util.concurrent.locks.Lock getReadLock()
public int getHighlightUpdateCount()
public java.util.LinkedList<java.util.Collection<? extends OsmPrimitive>> getSelectionHistory()
public void clearSelectionHistory()
public AutoCompletionManager getAutoCompletionManager()
public java.lang.String getVersion()
public void setVersion(java.lang.String version)
version
- the API version, i.e. "0.6"public boolean isUploadDiscouraged()
true
if upload is being discouraged, false
otherwisesetUploadDiscouraged(boolean)
public void setUploadDiscouraged(boolean uploadDiscouraged)
uploadDiscouraged
- true
if this dataset contains private data which should not be uploadedisUploadDiscouraged()
public java.util.Map<java.lang.String,java.lang.String> getChangeSetTags()
addChangeSetTag(java.lang.String, java.lang.String)
public void addChangeSetTag(java.lang.String k, java.lang.String v)
k
- Keyv
- ValuegetChangeSetTags()
private <T extends OsmPrimitive> java.util.Collection<T> getPrimitives(Predicate<OsmPrimitive> predicate)
public java.util.Collection<Node> getNodes()
public java.util.List<Node> searchNodes(BBox bbox)
bbox
- the bounding boxpublic boolean containsNode(Node n)
n
- The node to searchtrue
if n
ban be retrieved in this data set, false
otherwisepublic java.util.Collection<Way> getWays()
public java.util.List<Way> searchWays(BBox bbox)
bbox
- the bounding boxpublic boolean containsWay(Way w)
w
- The way to searchtrue
if w
ban be retrieved in this data set, false
otherwisepublic java.util.Collection<Relation> getRelations()
public java.util.List<Relation> searchRelations(BBox bbox)
bbox
- the bounding boxpublic boolean containsRelation(Relation r)
r
- The relation to searchtrue
if r
ban be retrieved in this data set, false
otherwisepublic java.util.Collection<OsmPrimitive> allPrimitives()
public java.util.Collection<OsmPrimitive> allNonDeletedPrimitives()
AbstractPrimitive.isDeleted()
public java.util.Collection<OsmPrimitive> allNonDeletedCompletePrimitives()
AbstractPrimitive.isDeleted()
,
AbstractPrimitive.isIncomplete()
public java.util.Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives()
AbstractPrimitive.isDeleted()
,
AbstractPrimitive.isIncomplete()
public java.util.Collection<OsmPrimitive> allModifiedPrimitives()
AbstractPrimitive.isModified()
public void addPrimitive(OsmPrimitive primitive)
primitive
- the primitive.public void removePrimitive(PrimitiveId primitiveId)
nodes
, ways
, or
relations
. References from other primitives to this
primitive are left unchanged.primitiveId
- the id of the primitivepublic static void addSelectionListener(SelectionChangedListener listener)
listener
- The selection listener to addpublic static void removeSelectionListener(SelectionChangedListener listener)
listener
- The selection listener to removepublic void fireSelectionChanged()
SelectionChangedListener
about the current selection in
this dataset.public java.util.Collection<OsmPrimitive> getSelectedNodesAndWays()
public java.util.Collection<WaySegment> getHighlightedVirtualNodes()
public java.util.Collection<WaySegment> getHighlightedWaySegments()
public java.util.Collection<OsmPrimitive> getSelected()
public java.util.Collection<OsmPrimitive> getAllSelected()
public java.util.Collection<Node> getSelectedNodes()
public java.util.Collection<Way> getSelectedWays()
public java.util.Collection<Relation> getSelectedRelations()
public boolean selectionEmpty()
public boolean isSelected(OsmPrimitive osm)
osm
- the primitiveosm
is selected or notpublic void toggleSelected(java.util.Collection<? extends PrimitiveId> osm)
osm
- The primitives to togglepublic void toggleSelected(PrimitiveId... osm)
osm
- The primitives to toggleprivate boolean __toggleSelected(PrimitiveId primitiveId)
public void setHighlightedVirtualNodes(java.util.Collection<WaySegment> waySegments)
waySegments
- Collection of way segmentspublic void setHighlightedWaySegments(java.util.Collection<WaySegment> waySegments)
waySegments
- Collection of way segmentspublic void setSelected(java.util.Collection<? extends PrimitiveId> selection, boolean fireSelectionChangeEvent)
selection
.
Notifies all SelectionChangedListener
if fireSelectionChangeEvent
is true.selection
- the selectionfireSelectionChangeEvent
- true, if the selection change listeners are to be notified; false, otherwisepublic void setSelected(java.util.Collection<? extends PrimitiveId> selection)
selection
and notifies all SelectionChangedListener
.selection
- the selectionpublic void setSelected(PrimitiveId... osm)
osm
and notifies all SelectionChangedListener
.osm
- the primitives to setpublic void addSelected(java.util.Collection<? extends PrimitiveId> selection)
selection
to the current selection
and notifies all SelectionChangedListener
.selection
- the selectionpublic void addSelected(PrimitiveId... osm)
osm
to the current selection
and notifies all SelectionChangedListener
.osm
- the primitives to addprivate boolean addSelected(java.util.Collection<? extends PrimitiveId> selection, boolean fireSelectionChangeEvent)
selection
to the current selection.
Notifies all SelectionChangedListener
if fireSelectionChangeEvent
is true.selection
- the selectionfireSelectionChangeEvent
- true, if the selection change listeners are to be notified; false, otherwisepublic void clearHighlightedVirtualNodes()
public void clearHighlightedWaySegments()
public void clearSelection(PrimitiveId... osm)
osm
- The collection of ids to remove the selection from.public void clearSelection(java.util.Collection<? extends PrimitiveId> list)
list
- The collection of ids to remove the selection from.public void clearSelection()
public java.util.Collection<DataSource> getDataSources()
Data
getDataSources
in interface Data
public java.awt.geom.Area getDataSourceArea()
Data
getDataSourceArea
in interface Data
public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type)
id
- uniqueId of the primitive. Might be < 0 for newly created primitivestype
- the type of the primitive. Must not be null.java.lang.NullPointerException
- if type is nullpublic OsmPrimitive getPrimitiveById(PrimitiveId primitiveId)
primitiveId
- type and uniqueId of the primitive. Might be < 0 for newly created primitivesprivate OsmPrimitive getPrimitiveByIdChecked(PrimitiveId primitiveId)
primitiveId
- primitive id to look forpublic java.util.Set<Way> unlinkNodeFromWays(Node node)
node
- the nodepublic java.util.Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive)
primitive
- the primitivepublic java.util.Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
referencedPrimitive
- the referenced primitivepublic boolean isModified()
AbstractPrimitive.isModified()
== true
.AbstractPrimitive.isModified()
== true
.private void reindexNode(Node node, LatLon newCoor, EastNorth eastNorth)
private void reindexWay(Way way)
private static void reindexRelation(Relation relation)
public void addDataSetListener(DataSetListener dsl)
dsl
- The data set listener to addpublic void removeDataSetListener(DataSetListener dsl)
dsl
- The data set listener to removepublic void beginUpdate()
endUpdate()
.
DataSetListener.dataChanged(DataChangedEvent event)
event is triggered after end of changes
ds.beginUpdate(); try { ... } finally { ds.endUpdate(); }
public void endUpdate()
beginUpdate()
private void fireEventToListeners(AbstractDatasetChangedEvent event)
private void fireEvent(AbstractDatasetChangedEvent event)
void firePrimitivesAdded(java.util.Collection<? extends OsmPrimitive> added, boolean wasIncomplete)
void firePrimitivesRemoved(java.util.Collection<? extends OsmPrimitive> removed, boolean wasComplete)
void fireTagsChanged(OsmPrimitive prim, java.util.Map<java.lang.String,java.lang.String> originalKeys)
void fireRelationMembersChanged(Relation r)
void fireNodeMoved(Node node, LatLon newCoor, EastNorth eastNorth)
void fireWayNodesChanged(Way way)
void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId)
void firePrimitiveFlagsChanged(OsmPrimitive primitive)
void fireHighlightingChanged()
public void invalidateEastNorthCache()
public void cleanupDeletedPrimitives()
private boolean cleanupDeleted(java.util.Iterator<? extends OsmPrimitive> it)
public void clear()
public void deleteInvisible()
public java.util.List<Bounds> getDataSourceBounds()
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.
getDataSourceBounds
in interface Data
public void mergeFrom(DataSet from)
from
- The source DataSetpublic void mergeFrom(DataSet from, ProgressMonitor progressMonitor)
from
- The source DataSetprogressMonitor
- The progress monitorpublic void projectionChanged(Projection oldValue, Projection newValue)
projectionChanged
in interface ProjectionChangeListener
public ProjectionBounds getDataSourceBoundingBox()