Ignore:
Timestamp:
2009-11-10T21:25:40+01:00 (17 years ago)
Author:
Gubaer
Message:

Improved test cases for MergeVisitor.
Moved MergeVisitor and removed Visitor-pattern. Double-dispatching isn't necessary and only slows down the merge process.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r2418 r2433  
    1 package org.openstreetmap.josm.data.osm.visitor;
     1package org.openstreetmap.josm.data.osm;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
     
    1313
    1414import org.openstreetmap.josm.data.conflict.ConflictCollection;
    15 import org.openstreetmap.josm.data.osm.DataSet;
    16 import org.openstreetmap.josm.data.osm.Node;
    17 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    18 import org.openstreetmap.josm.data.osm.Relation;
    19 import org.openstreetmap.josm.data.osm.RelationMember;
    20 import org.openstreetmap.josm.data.osm.Way;
    2115
    2216/**
    23  * A visitor that gets a data set at construction time and merges every visited object
    24  * into it.
    25  *
     17 * A dataset merger which takes a target and a source dataset and merges the source data set
     18 * onto the target dataset.
     19 * 
    2620 */
    27 public class MergeVisitor extends AbstractVisitor {
    28     private static Logger logger = Logger.getLogger(MergeVisitor.class.getName());
     21public class DataSetMerger {
     22    private static Logger logger = Logger.getLogger(DataSetMerger.class.getName());
    2923
    3024    /** the collection of conflicts created during merging */
     
    5145     * The visitor will merge <code>theirDataSet</code> onto <code>myDataSet</code>
    5246     *
    53      * @param myDataSet  dataset with my primitives
    54      * @param theirDataSet dataset with their primitives.
    55      */
    56     public MergeVisitor(DataSet myDataSet, DataSet theirDataSet) {
     47     * @param myDataSet  dataset with my primitives. Must not be null.
     48     * @param theirDataSet dataset with their primitives. Ignored, if null.
     49     * @throws IllegalArgumentException thrown if myDataSet is null
     50     */
     51    public DataSetMerger(DataSet myDataSet, DataSet theirDataSet) throws IllegalArgumentException {
     52        if (myDataSet == null)
     53            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null"));
    5754        this.myDataSet = myDataSet;
    5855        this.theirDataSet = theirDataSet;
     
    8279            //
    8380            if (mergeById(other))
     81                return;
     82            if (!other.isVisible())
     83                // ignore it
    8484                return;
    8585        } else {
     
    116116            }
    117117        }
     118
    118119        // If we get here we didn't find a suitable primitive in
    119120        // my dataset. Create a clone and add it to my dataset.
     
    129130        mergedMap.put(other.getUniqueId(), my.getUniqueId());
    130131        fixReferences.add(other.getUniqueId());
    131     }
    132 
    133     public void visit(Node other) {
    134         mergePrimitive(other);
    135     }
    136 
    137     public void visit(Way other) {
    138         mergePrimitive(other);
    139     }
    140 
    141     public void visit(Relation other) {
    142         mergePrimitive(other);
    143132    }
    144133
     
    357346     */
    358347    public void merge() {
     348        if (theirDataSet == null)
     349            return;
    359350        for (Node node: theirDataSet.getNodes()) {
    360             node.visit(this);
     351            mergePrimitive(node);
    361352        }
    362353        for (Way way: theirDataSet.getWays()) {
    363             way.visit(this);
     354            mergePrimitive(way);
    364355        }
    365356        for (Relation relation: theirDataSet.getRelations()) {
    366             relation.visit(this);
     357            mergePrimitive(relation);
    367358        }
    368359        fixReferences();
Note: See TracChangeset for help on using the changeset viewer.