Class 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