|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openstreetmap.josm.data.osm.DataSet
public class DataSet
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 ConccurentModificationException. However when for example one thread
removes primitive and other thread try to add another primitive reffering 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
Nested Class Summary | |
---|---|
private static class |
DataSet.IdHash
|
Field Summary | |
---|---|
private Storage<OsmPrimitive> |
allPrimitives
|
private AutoCompletionManager |
autocomplete
Maintain a list of used tags for autocompletion |
private java.util.List<AbstractDatasetChangedEvent> |
cachedEvents
|
private java.util.Map<java.lang.String,java.lang.String> |
changeSetTags
|
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.LinkedHashSet<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 Summary | |
---|---|
DataSet()
|
Method Summary | ||
---|---|---|
private boolean |
__toggleSelected(PrimitiveId primitiveId)
|
|
void |
addChangeSetTag(java.lang.String k,
java.lang.String v)
|
|
void |
addDataSetListener(DataSetListener dsl)
|
|
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)
|
|
static void |
addSelectionListener(SelectionChangedListener listener)
|
|
java.util.Collection<OsmPrimitive> |
allModifiedPrimitives()
|
|
java.util.Collection<OsmPrimitive> |
allNonDeletedCompletePrimitives()
|
|
java.util.Collection<OsmPrimitive> |
allNonDeletedPhysicalPrimitives()
|
|
java.util.Collection<OsmPrimitive> |
allNonDeletedPrimitives()
|
|
java.util.Collection<OsmPrimitive> |
allPrimitives()
|
|
void |
beginUpdate()
Can be called before bigger changes on dataset. |
|
private boolean |
cleanupDeleted(java.util.Iterator<? extends OsmPrimitive> it)
|
|
void |
cleanupDeletedPrimitives()
|
|
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()
|
|
void |
clearSelection(java.util.Collection<? extends PrimitiveId> list)
|
|
void |
clearSelection(PrimitiveId... osm)
Remove the selection from every value in the collection. |
|
void |
clearSelectionHistory()
Clears selection history list |
|
DataSet |
clone()
|
|
void |
deleteInvisible()
Marks all "invisible" objects as deleted. |
|
private 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(OsmPrimitive primitive)
|
|
(package private) void |
fireNodeMoved(Node node,
LatLon newCoor,
EastNorth eastNorth)
|
|
(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()
|
|
java.util.Map<java.lang.String,java.lang.String> |
getChangeSetTags()
|
|
java.awt.geom.Area |
getDataSourceArea()
Returns the total area of downloaded data (the "yellow rectangles"). |
|
java.util.List<Bounds> |
getDataSourceBounds()
Replies the list of data source bounds. |
|
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)
|
|
private OsmPrimitive |
getPrimitiveByIdChecked(PrimitiveId primitiveId)
Show message and stack trace in log in case primitive is not found |
|
private
|
getPrimitives(Predicate<OsmPrimitive> predicate)
|
|
java.util.concurrent.locks.Lock |
getReadLock()
|
|
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()
Return selected nodes. |
|
java.util.Collection<OsmPrimitive> |
getSelectedNodesAndWays()
|
|
java.util.Collection<Relation> |
getSelectedRelations()
Return selected relations. |
|
java.util.Collection<Way> |
getSelectedWays()
Return 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)
|
|
boolean |
isUploadDiscouraged()
|
|
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 void |
reindexRelation(Relation relation)
|
|
private void |
reindexWay(Way way)
|
|
void |
removeDataSetListener(DataSetListener dsl)
|
|
void |
removePrimitive(PrimitiveId primitiveId)
Removes a primitive from the dataset. |
|
static void |
removeSelectionListener(SelectionChangedListener listener)
|
|
java.util.List<Node> |
searchNodes(BBox bbox)
|
|
java.util.List<Relation> |
searchRelations(BBox bbox)
|
|
java.util.List<Way> |
searchWays(BBox bbox)
|
|
boolean |
selectionEmpty()
|
|
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)
|
|
void |
setUploadDiscouraged(boolean uploadDiscouraged)
|
|
void |
setVersion(java.lang.String version)
Sets the API version this dataset was created from. |
|
void |
toggleSelected(java.util.Collection<? extends PrimitiveId> osm)
|
|
void |
toggleSelected(PrimitiveId... osm)
|
|
void |
unlinkNodeFromWays(Node node)
removes all references from ways in this dataset to a particular node |
|
void |
unlinkPrimitiveFromRelations(OsmPrimitive primitive)
removes all references from relations in this dataset to this primitive |
|
void |
unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive)
removes all references from other primitives to the referenced primitive |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int MAX_SINGLE_EVENTS
private static final int MAX_EVENTS
private Storage<OsmPrimitive> allPrimitives
private java.util.Map<PrimitiveId,OsmPrimitive> primitivesMap
private 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 java.util.Map<java.lang.String,java.lang.String> changeSetTags
private QuadBuckets<Node> nodes
private QuadBuckets<Way> ways
private java.util.Collection<Relation> relations
public final java.util.Collection<DataSource> dataSources
private static final java.util.Collection<SelectionChangedListener> selListeners
private java.util.LinkedHashSet<OsmPrimitive> selectedPrimitives
private java.util.Collection<OsmPrimitive> selectionSnapshot
Constructor Detail |
---|
public DataSet()
Method Detail |
---|
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.5" or "0.6"public final boolean isUploadDiscouraged()
public final void setUploadDiscouraged(boolean uploadDiscouraged)
public java.util.Map<java.lang.String,java.lang.String> getChangeSetTags()
public void addChangeSetTag(java.lang.String k, java.lang.String v)
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)
public java.util.Collection<Way> getWays()
public java.util.List<Way> searchWays(BBox bbox)
public java.util.Collection<Relation> getRelations()
public java.util.List<Relation> searchRelations(BBox bbox)
public java.util.Collection<OsmPrimitive> allPrimitives()
public java.util.Collection<OsmPrimitive> allNonDeletedPrimitives()
public java.util.Collection<OsmPrimitive> allNonDeletedCompletePrimitives()
public java.util.Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives()
public java.util.Collection<OsmPrimitive> allModifiedPrimitives()
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.
primitive
- the primitivepublic static void addSelectionListener(SelectionChangedListener listener)
public static void removeSelectionListener(SelectionChangedListener listener)
public 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)
public void toggleSelected(java.util.Collection<? extends PrimitiveId> osm)
public void toggleSelected(PrimitiveId... osm)
private boolean __toggleSelected(PrimitiveId primitiveId)
public void setHighlightedVirtualNodes(java.util.Collection<WaySegment> waySegments)
Collection
- of waySegmentspublic void setHighlightedWaySegments(java.util.Collection<WaySegment> waySegments)
Collection
- of waySegmentspublic 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)
public void addSelected(java.util.Collection<? extends PrimitiveId> selection)
selection
to the current selection
and notifies all SelectionChangedListener
.
selection
- the selectionpublic void addSelected(PrimitiveId... osm)
private 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, otherwise
public void clearHighlightedVirtualNodes()
public void clearHighlightedWaySegments()
public void clearSelection(PrimitiveId... osm)
list
- The collection to remove the selection from.public void clearSelection(java.util.Collection<? extends PrimitiveId> list)
public void clearSelection()
public DataSet clone()
clone
in class java.lang.Object
public java.awt.geom.Area getDataSourceArea()
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
- thrown, if type is nullpublic OsmPrimitive getPrimitiveById(PrimitiveId primitiveId)
private OsmPrimitive getPrimitiveByIdChecked(PrimitiveId primitiveId)
primitiveId
-
private void deleteWay(Way way)
public void unlinkNodeFromWays(Node node)
node
- the nodepublic void unlinkPrimitiveFromRelations(OsmPrimitive primitive)
primitive
- the primitivepublic void 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 void reindexRelation(Relation relation)
public void addDataSetListener(DataSetListener dsl)
public void removeDataSetListener(DataSetListener dsl)
public void beginUpdate()
endUpdate()
.
DataSetListener#dataChanged()
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 fireHighlightingChanged(OsmPrimitive primitive)
public void invalidateEastNorthCache()
DataSet#reproject()
it only invalidates the
cache and doesn't reproject the coordinates.
public void cleanupDeletedPrimitives()
private boolean cleanupDeleted(java.util.Iterator<? extends OsmPrimitive> it)
public void clear()
public void deleteInvisible()
public java.util.List<Bounds> getDataSourceBounds()
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.
public void mergeFrom(DataSet from)
from
- The source DataSetpublic void mergeFrom(DataSet from, ProgressMonitor progressMonitor)
from
- The source DataSetpublic void projectionChanged(Projection oldValue, Projection newValue)
projectionChanged
in interface ProjectionChangeListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |