source: josm/trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java@ 10378

Last change on this file since 10378 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.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collection;
7import java.util.Objects;
8
9import javax.swing.Icon;
10
11import org.openstreetmap.josm.data.conflict.Conflict;
12import org.openstreetmap.josm.data.osm.Node;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Represents the resolution of a conflict between the coordinates of two {@link Node}s.
19 *
20 */
21public class CoordinateConflictResolveCommand extends ConflictResolveCommand {
22
23 /** the conflict to resolve */
24 private final Conflict<? extends OsmPrimitive> conflict;
25
26 /** the merge decision */
27 private final MergeDecisionType decision;
28
29 /**
30 * constructor for coordinate conflict
31 *
32 * @param conflict the conflict data set
33 * @param decision the merge decision
34 */
35 public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
36 this.conflict = conflict;
37 this.decision = decision;
38 }
39
40 @Override
41 public String getDescriptionText() {
42 return tr("Resolve conflicts in coordinates in {0}", conflict.getMy().getId());
43 }
44
45 @Override
46 public Icon getDescriptionIcon() {
47 return ImageProvider.get("data", "object");
48 }
49
50 @Override
51 public boolean executeCommand() {
52 // remember the current state of modified primitives, i.e. of OSM primitive 'my'
53 super.executeCommand();
54
55 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
56 // do nothing
57 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
58 Node my = (Node) conflict.getMy();
59 Node their = (Node) conflict.getTheir();
60 my.setCoor(their.getCoor());
61 } else
62 // should not happen
63 throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
64
65 // remember the layer this command was applied to
66 rememberConflict(conflict);
67
68 return true;
69 }
70
71 @Override
72 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
73 Collection<OsmPrimitive> added) {
74 modified.add(conflict.getMy());
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(super.hashCode(), conflict, decision);
80 }
81
82 @Override
83 public boolean equals(Object obj) {
84 if (this == obj) return true;
85 if (obj == null || getClass() != obj.getClass()) return false;
86 if (!super.equals(obj)) return false;
87 CoordinateConflictResolveCommand that = (CoordinateConflictResolveCommand) obj;
88 return Objects.equals(conflict, that.conflict) &&
89 decision == that.decision;
90 }
91}
Note: See TracBrowser for help on using the repository browser.