source: josm/trunk/src/org/openstreetmap/josm/command/SelectCommand.java@ 9917

Last change on this file since 9917 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.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.util.Collection;
7import java.util.Objects;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11
12/**
13 * Command that selects OSM primitives
14 *
15 * @author Landwirt
16 */
17public class SelectCommand extends Command {
18
19 /** the primitives to select when executing the command */
20 private final Collection<OsmPrimitive> newSelection;
21
22 /** the selection before applying the new selection */
23 private Collection<OsmPrimitive> oldSelection;
24
25 /**
26 * Constructs a new select command.
27 * @param newSelection the primitives to select when executing the command.
28 */
29 public SelectCommand(Collection<OsmPrimitive> newSelection) {
30 this.newSelection = newSelection;
31 }
32
33 @Override
34 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
35 }
36
37 @Override
38 public void undoCommand() {
39 Main.map.mapView.getEditLayer().data.setSelected(oldSelection);
40 }
41
42 @Override
43 public boolean executeCommand() {
44 oldSelection = Main.map.mapView.getEditLayer().data.getSelected();
45 Main.map.mapView.getEditLayer().data.setSelected(newSelection);
46 return true;
47 }
48
49 @Override
50 public String getDescriptionText() {
51 int size = newSelection != null ? newSelection.size() : 0;
52 return trn("Selected {0} object", "Selected {0} objects", size, size);
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(super.hashCode(), newSelection, oldSelection);
58 }
59
60 @Override
61 public boolean equals(Object obj) {
62 if (this == obj) return true;
63 if (obj == null || getClass() != obj.getClass()) return false;
64 if (!super.equals(obj)) return false;
65 SelectCommand that = (SelectCommand) obj;
66 return Objects.equals(newSelection, that.newSelection) &&
67 Objects.equals(oldSelection, that.oldSelection);
68 }
69}
Note: See TracBrowser for help on using the repository browser.