source: josm/trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java@ 11170

Last change on this file since 11170 was 10663, checked in by Don-vip, 8 years ago

fix #13223 - Minor command class fixes (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7import java.util.List;
8import java.util.Objects;
9
10import javax.swing.Icon;
11
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.data.osm.Way;
16import org.openstreetmap.josm.gui.DefaultNameFormatter;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Command that changes the nodes list of a way.
21 * The same can be done with ChangeCommand, but this is more
22 * efficient. (Needed for the duplicate node fixing
23 * tool of the validator plugin, when processing large data sets.)
24 *
25 * @author Imi
26 */
27public class ChangeNodesCommand extends Command {
28
29 private final Way way;
30 private final List<Node> newNodes;
31
32 /**
33 * Constructs a new {@code ChangeNodesCommand}.
34 * @param way The way to modify
35 * @param newNodes The new list of nodes for the given way
36 */
37 public ChangeNodesCommand(Way way, List<Node> newNodes) {
38 this.way = way;
39 this.newNodes = newNodes;
40 if (newNodes.isEmpty()) {
41 throw new IllegalArgumentException("Cannot set nodes to be an empty list.");
42 }
43 }
44
45 @Override
46 public boolean executeCommand() {
47 super.executeCommand();
48 way.setNodes(newNodes);
49 way.setModified(true);
50 return true;
51 }
52
53 @Override
54 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
55 modified.add(way);
56 }
57
58 @Override
59 public String getDescriptionText() {
60 return tr("Change nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
61 }
62
63 @Override
64 public Icon getDescriptionIcon() {
65 return ImageProvider.get(OsmPrimitiveType.WAY);
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(super.hashCode(), way, newNodes);
71 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) return true;
76 if (obj == null || getClass() != obj.getClass()) return false;
77 if (!super.equals(obj)) return false;
78 ChangeNodesCommand that = (ChangeNodesCommand) obj;
79 return Objects.equals(way, that.way) &&
80 Objects.equals(newNodes, that.newNodes);
81 }
82}
Note: See TracBrowser for help on using the repository browser.