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

Last change on this file since 12288 was 9371, checked in by simon04, 8 years ago

Java 7: use Objects.equals and Objects.hash

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