Ignore:
Timestamp:
2021-07-10T20:52:12+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21041 - Tagging preset validation: clone properly primitives children for nominal execution of validation tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetValidation.java

    r17643 r17981  
    22package org.openstreetmap.josm.gui.tagging.presets;
    33
     4import static java.util.Collections.singleton;
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
     7import java.util.ArrayList;
     8import java.util.Arrays;
     9import java.util.Collection;
     10import java.util.List;
     11
     12import javax.swing.JLabel;
     13
    414import org.openstreetmap.josm.command.Command;
    515import org.openstreetmap.josm.data.osm.DataSet;
    6 import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.FilterModel;
     17import org.openstreetmap.josm.data.osm.INode;
     18import org.openstreetmap.josm.data.osm.IRelation;
     19import org.openstreetmap.josm.data.osm.IWay;
    720import org.openstreetmap.josm.data.osm.OsmPrimitive;
    8 import org.openstreetmap.josm.data.osm.Relation;
    921import org.openstreetmap.josm.data.osm.Tag;
    10 import org.openstreetmap.josm.data.osm.Way;
    1122import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    1223import org.openstreetmap.josm.data.validation.OsmValidator;
     
    1728import org.openstreetmap.josm.gui.util.GuiHelper;
    1829import org.openstreetmap.josm.tools.Logging;
     30import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1931import org.openstreetmap.josm.tools.Utils;
    20 
    21 import javax.swing.JLabel;
    22 import java.util.ArrayList;
    23 import java.util.Arrays;
    24 import java.util.Collections;
    25 import java.util.List;
    26 
    27 import static org.openstreetmap.josm.tools.I18n.tr;
    2832
    2933/**
     
    7478
    7579    static OsmPrimitive applyChangedTags(OsmPrimitive original, List<Tag> changedTags) {
    76         OsmPrimitive primitive = clone(original);
    77         new DataSet(primitive);
    78         Command command = TaggingPreset.createCommand(Collections.singleton(primitive), changedTags);
     80        DataSet ds = new DataSet();
     81        Collection<OsmPrimitive> primitives = FilterModel.getAffectedPrimitives(singleton(original));
     82        ds.clonePrimitives(
     83                new SubclassFilteredCollection<>(primitives, INode.class::isInstance),
     84                new SubclassFilteredCollection<>(primitives, IWay.class::isInstance),
     85                new SubclassFilteredCollection<>(primitives, IRelation.class::isInstance));
     86        OsmPrimitive primitive = ds.getPrimitiveById(original.getOsmPrimitiveId());
     87        Command command = TaggingPreset.createCommand(singleton(primitive), changedTags);
    7988        if (command != null) {
    8089            command.executeCommand();
     
    8291        return primitive;
    8392    }
    84 
    85     static OsmPrimitive clone(OsmPrimitive original) {
    86         if (original instanceof Node) {
    87             return new Node(((Node) original));
    88         } else if (original instanceof Way) {
    89             return new Way(((Way) original), false, false);
    90         } else if (original instanceof Relation) {
    91             return new Relation(((Relation) original), false, false);
    92         } else {
    93             throw new IllegalStateException();
    94         }
    95     }
    9693}
Note: See TracChangeset for help on using the changeset viewer.