Changeset 15013 in josm


Ignore:
Timestamp:
2019-04-22T15:00:55+02:00 (6 years ago)
Author:
Don-vip
Message:

remove duplicated code

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java

    r14654 r15013  
    1010import java.util.ArrayList;
    1111import java.util.Collection;
     12import java.util.HashSet;
    1213import java.util.LinkedList;
    1314import java.util.List;
     
    8990
    9091        // I'm sure there's a better way to handle this
    91         UndoRedoHandler.getInstance().add(new RemoveNodesCommand(selectedWay, selectedNodes));
     92        UndoRedoHandler.getInstance().add(
     93                new RemoveNodesCommand(selectedWay, new HashSet<>(selectedNodes)));
    9294    }
    9395
  • trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java

    r12726 r15013  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.Collection;
    76import java.util.List;
    8 import java.util.Objects;
    9 
    10 import javax.swing.Icon;
    117
    128import org.openstreetmap.josm.data.osm.DataSet;
    139import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1410import org.openstreetmap.josm.data.osm.Node;
    15 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1711import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.tools.ImageProvider;
    1912
    2013/**
     
    2215 * The same can be done with ChangeCommand, but this is more
    2316 * efficient. (Needed for the duplicate node fixing
    24  * tool of the validator plugin, when processing large data sets.)
     17 * tool of the validator, when processing large data sets.)
    2518 *
    2619 * @author Imi
    2720 */
    28 public class ChangeNodesCommand extends Command {
    29 
    30     private final Way way;
    31     private final List<Node> newNodes;
     21public class ChangeNodesCommand extends AbstractNodesCommand<List<Node>> {
    3222
    3323    /**
     
    3727     */
    3828    public ChangeNodesCommand(Way way, List<Node> newNodes) {
    39         this(way.getDataSet(), way, newNodes);
     29        super(way.getDataSet(), way, newNodes);
    4030    }
    4131
     
    4838     */
    4939    public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) {
    50         super(ds);
    51         this.way = way;
    52         this.newNodes = newNodes;
    53         if (newNodes.isEmpty()) {
    54             throw new IllegalArgumentException("Cannot set nodes to be an empty list.");
    55         }
     40        super(ds, way, newNodes);
    5641    }
    5742
    5843    @Override
    59     public boolean executeCommand() {
    60         super.executeCommand();
    61         way.setNodes(newNodes);
    62         way.setModified(true);
    63         return true;
    64     }
    65 
    66     @Override
    67     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    68         modified.add(way);
     44    public void modifyWay() {
     45        way.setNodes(cmdNodes);
    6946    }
    7047
     
    7350        return tr("Change nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
    7451    }
    75 
    76     @Override
    77     public Icon getDescriptionIcon() {
    78         return ImageProvider.get(OsmPrimitiveType.WAY);
    79     }
    80 
    81     @Override
    82     public int hashCode() {
    83         return Objects.hash(super.hashCode(), way, newNodes);
    84     }
    85 
    86     @Override
    87     public boolean equals(Object obj) {
    88         if (this == obj) return true;
    89         if (obj == null || getClass() != obj.getClass()) return false;
    90         if (!super.equals(obj)) return false;
    91         ChangeNodesCommand that = (ChangeNodesCommand) obj;
    92         return Objects.equals(way, that.way) &&
    93                 Objects.equals(newNodes, that.newNodes);
    94     }
    9552}
  • trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java

    r12726 r15013  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.Collection;
    76import java.util.HashSet;
    87import java.util.List;
    9 import java.util.Objects;
    108import java.util.Set;
    119
    12 import javax.swing.Icon;
    13 
     10import org.openstreetmap.josm.data.osm.DataSet;
    1411import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1512import org.openstreetmap.josm.data.osm.Node;
    16 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1813import org.openstreetmap.josm.data.osm.Way;
    19 import org.openstreetmap.josm.tools.ImageProvider;
    2014
    2115/**
     
    2620 * @author Giuseppe Bilotta
    2721 */
    28 public class RemoveNodesCommand extends Command {
    29 
    30     private final Way way;
    31     private final Set<Node> rmNodes;
     22public class RemoveNodesCommand extends AbstractNodesCommand<Set<Node>> {
    3223
    3324    /**
     
    3526     * @param way The way to modify. Must not be null, and belong to a data set
    3627     * @param rmNodes The list of nodes to remove
     28     * @deprecated Use {@link #RemoveNodesCommand(Way, Set)}
    3729     */
     30    @Deprecated
    3831    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
    39         super(way.getDataSet());
    40         this.way = way;
    41         this.rmNodes = new HashSet<>(rmNodes);
     32        super(way.getDataSet(), way, new HashSet<>(rmNodes));
     33    }
     34
     35    /**
     36     * Constructs a new {@code RemoveNodesCommand}.
     37     * @param way The way to modify. Must not be null, and belong to a data set
     38     * @param rmNodes The set of nodes to remove
     39     * @since xxx
     40     */
     41    public RemoveNodesCommand(Way way, Set<Node> rmNodes) {
     42        super(way.getDataSet(), way, rmNodes);
     43    }
     44
     45    /**
     46     * Constructs a new {@code RemoveNodesCommand}.
     47     * @param ds The target data set. Must not be {@code null}
     48     * @param way The way to modify. Must not be null, and belong to a data set
     49     * @param rmNodes The list of nodes to remove
     50     * @since 15013
     51     */
     52    public RemoveNodesCommand(DataSet ds, Way way, Set<Node> rmNodes) {
     53        super(ds, way, rmNodes);
    4254    }
    4355
    4456    @Override
    45     public boolean executeCommand() {
    46         super.executeCommand();
    47         way.removeNodes(rmNodes);
    48         way.setModified(true);
    49         return true;
    50     }
    51 
    52     @Override
    53     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
    54         modified.add(way);
     57    protected void modifyWay() {
     58        way.removeNodes(cmdNodes);
    5559    }
    5660
     
    5963        return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
    6064    }
    61 
    62     @Override
    63     public Icon getDescriptionIcon() {
    64         return ImageProvider.get(OsmPrimitiveType.WAY);
    65     }
    66 
    67     @Override
    68     public int hashCode() {
    69         return Objects.hash(super.hashCode(), way, rmNodes);
    70     }
    71 
    72     @Override
    73     public boolean equals(Object obj) {
    74         if (this == obj) return true;
    75         if (obj == null || getClass() != obj.getClass()) return false;
    76         if (!super.equals(obj)) return false;
    77         RemoveNodesCommand that = (RemoveNodesCommand) obj;
    78         return Objects.equals(way, that.way) &&
    79                 Objects.equals(rmNodes, that.rmNodes);
    80     }
    8165}
  • trunk/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java

    r13079 r15013  
    5252    public void testExecute() {
    5353        RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
    54                 Collections.singletonList(testData.existingNode));
     54                Collections.singleton(testData.existingNode));
    5555
    5656        command.executeCommand();
     
    6767    public void testUndo() {
    6868        RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
    69                 Collections.singletonList(testData.existingNode));
     69                Collections.singleton(testData.existingNode));
    7070
    7171        command.executeCommand();
     
    9292        ArrayList<OsmPrimitive> added = new ArrayList<>();
    9393        RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
    94                 Collections.singletonList(testData.existingNode));
     94                Collections.singleton(testData.existingNode));
    9595        command.fillModifiedData(modified, deleted, added);
    9696        assertArrayEquals(new Object[] {testData.existingWay }, modified.toArray());
     
    105105    public void testGetParticipatingPrimitives() {
    106106        RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay,
    107                 Collections.singletonList(testData.existingNode));
     107                Collections.singleton(testData.existingNode));
    108108        command.executeCommand();
    109109        assertArrayEquals(new Object[] {testData.existingWay }, command.getParticipatingPrimitives().toArray());
     
    115115    @Test
    116116    public void testDescription() {
    117         assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singletonList(testData.existingNode))
     117        assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singleton(testData.existingNode))
    118118                .getDescriptionText().matches("Removed nodes from .*"));
    119119    }
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r15010 r15013  
    280280     */
    281281    @Test
    282     public void testvalidateUploadTag() {
     282    public void testValidateUploadTag() {
    283283        doTestValidateUploadTag("upload.comment");
    284284        doTestValidateUploadTag("upload.source");
Note: See TracChangeset for help on using the changeset viewer.