org.openstreetmap.josm.data.osm
Class DataSetMerger

java.lang.Object
  extended by org.openstreetmap.josm.data.osm.DataSetMerger

public class DataSetMerger
extends java.lang.Object

A dataset merger which takes a target and a source dataset and merges the source data set onto the target dataset.


Field Summary
private  ConflictCollection conflicts
          the collection of conflicts created during merging
private  java.util.Map<PrimitiveId,PrimitiveId> mergedMap
          A map of all primitives that got replaced with other primitives.
private  java.util.Set<OsmPrimitive> objectsToDelete
           
private  java.util.Set<PrimitiveId> objectsWithChildrenToMerge
          a set of primitive ids for which we have to fix references (to nodes and to relation members) after the first phase of merging
private  DataSet sourceDataSet
          the source dataset where primitives are merged from
private  DataSet targetDataSet
          the target dataset for merging
 
Constructor Summary
DataSetMerger(DataSet targetDataSet, DataSet sourceDataSet)
          constructor The visitor will merge theirDataSet onto myDataSet
 
Method Summary
protected  void addConflict(Conflict<?> c)
           
protected  void addConflict(OsmPrimitive my, OsmPrimitive their)
           
protected  void deleteMarkedObjects()
          Deleted objects in objectsToDelete set and create conflicts for objects that cannot be deleted because they're referenced in the target dataset.
protected  void fixIncomplete(Way other)
           
 void fixReferences()
          Postprocess the dataset and fix all merged references to point to the actual data.
 ConflictCollection getConflicts()
          replies the map of conflicts
protected  OsmPrimitive getMergeTarget(OsmPrimitive mergeSource)
           
 DataSet getTargetDataSet()
          replies my dataset
 void merge()
          Runs the merge operation.
 void merge(ProgressMonitor progressMonitor)
          Runs the merge operation.
private  boolean mergeById(OsmPrimitive source)
          Tries to merge a primitive source into an existing primitive with the same id.
private  void mergeNodeList(Way source)
          Merges the node list of a source way onto its target way.
protected  void mergePrimitive(OsmPrimitive source, java.util.Collection<? extends OsmPrimitive> candidates)
          Merges a primitive other of type
private  void mergeRelationMembers(Relation source)
          Merges the relation members of a source relation onto the corresponding target relation.
private  void resetPrimitive(OsmPrimitive osm)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conflicts

private final ConflictCollection conflicts
the collection of conflicts created during merging


targetDataSet

private final DataSet targetDataSet
the target dataset for merging


sourceDataSet

private final DataSet sourceDataSet
the source dataset where primitives are merged from


mergedMap

private final java.util.Map<PrimitiveId,PrimitiveId> mergedMap
A map of all primitives that got replaced with other primitives. Key is the PrimitiveId in their dataset, the value is the PrimitiveId in my dataset


objectsWithChildrenToMerge

private final java.util.Set<PrimitiveId> objectsWithChildrenToMerge
a set of primitive ids for which we have to fix references (to nodes and to relation members) after the first phase of merging


objectsToDelete

private final java.util.Set<OsmPrimitive> objectsToDelete
Constructor Detail

DataSetMerger

public DataSetMerger(DataSet targetDataSet,
                     DataSet sourceDataSet)
              throws java.lang.IllegalArgumentException
constructor The visitor will merge theirDataSet onto myDataSet

Parameters:
targetDataSet - dataset with my primitives. Must not be null.
sourceDataSet - dataset with their primitives. Ignored, if null.
Throws:
java.lang.IllegalArgumentException - thrown if myDataSet is null
Method Detail

mergePrimitive

protected void mergePrimitive(OsmPrimitive source,
                              java.util.Collection<? extends OsmPrimitive> candidates)
Merges a primitive other of type

onto my primitives. If other.id != 0 it tries to merge it with an corresponding primitive from my dataset with the same id. If this is not possible a conflict is remembered in conflicts. If other.id == 0 it tries to find a primitive in my dataset with id == 0 which is semantically equal. If it finds one it merges its technical attributes onto my primitive.

Type Parameters:
P - the type of the other primitive
Parameters:
source - the other primitive

getMergeTarget

protected OsmPrimitive getMergeTarget(OsmPrimitive mergeSource)
                               throws java.lang.IllegalStateException
Throws:
java.lang.IllegalStateException

addConflict

protected void addConflict(Conflict<?> c)

addConflict

protected void addConflict(OsmPrimitive my,
                           OsmPrimitive their)

fixIncomplete

protected void fixIncomplete(Way other)

fixReferences

public void fixReferences()
Postprocess the dataset and fix all merged references to point to the actual data.


deleteMarkedObjects

protected void deleteMarkedObjects()
Deleted objects in objectsToDelete set and create conflicts for objects that cannot be deleted because they're referenced in the target dataset.


resetPrimitive

private final void resetPrimitive(OsmPrimitive osm)

mergeNodeList

private void mergeNodeList(Way source)
                    throws java.lang.IllegalStateException
Merges the node list of a source way onto its target way.

Parameters:
source - the source way
Throws:
java.lang.IllegalStateException - thrown if no target way can be found for the source way
java.lang.IllegalStateException - thrown if there isn't a target node for one of the nodes in the source way

mergeRelationMembers

private void mergeRelationMembers(Relation source)
                           throws java.lang.IllegalStateException
Merges the relation members of a source relation onto the corresponding target relation.

Parameters:
source - the source relation
Throws:
java.lang.IllegalStateException - thrown if there is no corresponding target relation
java.lang.IllegalStateException - thrown if there isn't a corresponding target object for one of the relation members in source

mergeById

private boolean mergeById(OsmPrimitive source)
Tries to merge a primitive source into an existing primitive with the same id.

Parameters:
source - the source primitive which is to be merged into a target primitive
Returns:
true, if this method was able to merge source into a target object; false, otherwise

merge

public void merge()
Runs the merge operation. Successfully merged OsmPrimitives are in #getMyDataSet(). See getConflicts() for a map of conflicts after the merge operation.


merge

public void merge(ProgressMonitor progressMonitor)
Runs the merge operation. Successfully merged OsmPrimitives are in #getMyDataSet(). See getConflicts() for a map of conflicts after the merge operation.


getTargetDataSet

public DataSet getTargetDataSet()
replies my dataset

Returns:

getConflicts

public ConflictCollection getConflicts()
replies the map of conflicts

Returns:
the map of conflicts


JOSM