Ticket #2510: conflict-resolution.patch

File conflict-resolution.patch, 2.4 KB (added by Gubaer, 16 years ago)
  • MergeVisitor.java

     
    216216    }
    217217
    218218    /**
    219      * @return <code>true</code>, if no merge is needed or merge is performed already.
     219     * Tries to merge a primitive <code>other</code> into an existing primitive with the same id.
     220     *
     221     * @param myPrimitives the complete set of my primitives (potential merge targets)
     222     * @param myPrimitivesWithID the map of primitives (potential merge targets) with an id <> 0, for faster lookup
     223     *    by id. Key is the id, value the primitive with the given value. myPrimitives.valueSet() is a
     224     *    subset of primitives.
     225     * @param other  the other primitive which is to be merged with a primitive in primitives if possible
     226     * @return true, if this method was able to merge <code>other</code> with an existing node; false, otherwise 
    220227     */
    221228    private <P extends OsmPrimitive> boolean mergeById(
    222             Collection<P> primitives, HashMap<Long, P> hash, P other) {
    223         // Fast-path merging of identical objects
    224         if (hash.containsKey(other.id)) {
    225             P my = hash.get(other.id);
    226             if (my.realEqual(other, true)) {
     229            Collection<P> myPrimitives, HashMap<Long, P> myPrimitivesWithID, P other) {
     230       
     231        // merge other into an existing primitive with the same id, if possible
     232        //
     233        if (myPrimitivesWithID.containsKey(other.id)) {
     234            P my = myPrimitivesWithID.get(other.id);
     235            if (my.realEqual(other, true /* compare semantic fields only */)) {
     236                // make sure the merge target becomes the higher version number
     237                // and the later timestamp
     238                //
     239                my.version = Math.max(other.version, my.version);
     240                if (other.getTimestamp().after(my.getTimestamp())) {
     241                    my.setTimestamp(other.getTimestamp());
     242                }
    227243                merged.put(other, my);
    228244                return true;
    229245            }
    230246        }
    231247
    232         for (P my : primitives) {
    233             if (my.realEqual(other, false)) {
     248        // try to merge into one of the existing primitives
     249        //
     250        for (P my : myPrimitives) {
     251            if (my.realEqual(other, false /* compare all fields */)) {
    234252                merged.put(other, my);
    235253                return true; // no merge needed.
    236254            }