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

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

add unit test for ConflictAddCommand

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