source: josm/trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java@ 8855

Last change on this file since 8855 was 8456, checked in by Don-vip, 9 years ago

see #11508 - override hashCode() and equals() in other commands as well

  • Property svn:eol-style set to native
File size: 2.7 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.HashSet;
8import java.util.List;
9import java.util.Set;
10
11import javax.swing.Icon;
12
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
16import org.openstreetmap.josm.data.osm.Way;
17import org.openstreetmap.josm.gui.DefaultNameFormatter;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * Command that removes a set of nodes from a way.
22 * The same can be done with ChangeNodesCommand, but this is more
23 * efficient. (Needed for the tool to disconnect nodes from ways.)
24 *
25 * @author Giuseppe Bilotta
26 */
27public class RemoveNodesCommand extends Command {
28
29 private final Way way;
30 private final Set<Node> rmNodes;
31
32 /**
33 * Constructs a new {@code RemoveNodesCommand}.
34 * @param way The way to modify
35 * @param rmNodes The list of nodes to remove
36 */
37 public RemoveNodesCommand(Way way, List<Node> rmNodes) {
38 this.way = way;
39 this.rmNodes = new HashSet<>(rmNodes);
40 }
41
42 @Override
43 public boolean executeCommand() {
44 super.executeCommand();
45 way.removeNodes(rmNodes);
46 way.setModified(true);
47 return true;
48 }
49
50 @Override
51 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
52 modified.add(way);
53 }
54
55 @Override
56 public String getDescriptionText() {
57 return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
58 }
59
60 @Override
61 public Icon getDescriptionIcon() {
62 return ImageProvider.get(OsmPrimitiveType.WAY);
63 }
64
65 @Override
66 public int hashCode() {
67 final int prime = 31;
68 int result = super.hashCode();
69 result = prime * result + ((rmNodes == null) ? 0 : rmNodes.hashCode());
70 result = prime * result + ((way == null) ? 0 : way.hashCode());
71 return result;
72 }
73
74 @Override
75 public boolean equals(Object obj) {
76 if (this == obj)
77 return true;
78 if (!super.equals(obj))
79 return false;
80 if (getClass() != obj.getClass())
81 return false;
82 RemoveNodesCommand other = (RemoveNodesCommand) obj;
83 if (rmNodes == null) {
84 if (other.rmNodes != null)
85 return false;
86 } else if (!rmNodes.equals(other.rmNodes))
87 return false;
88 if (way == null) {
89 if (other.way != null)
90 return false;
91 } else if (!way.equals(other.way))
92 return false;
93 return true;
94 }
95}
Note: See TracBrowser for help on using the repository browser.