source: josm/trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java@ 12167

Last change on this file since 12167 was 10467, checked in by Don-vip, 8 years ago

fix #13037 - Small fixes for unit tests (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.8 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.List;
8import java.util.Objects;
9
10import javax.swing.Icon;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.conflict.Conflict;
14import org.openstreetmap.josm.data.osm.Node;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.Way;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Represents the resolution of conflicts in the node list of two {@link Way}s.
21 *
22 */
23public class WayNodesConflictResolverCommand extends ConflictResolveCommand {
24 /** the conflict to resolve */
25 private final Conflict<Way> conflict;
26
27 /** the list of merged nodes. This becomes the list of news of my way after the
28 * command is executed
29 */
30 private final List<Node> mergedNodeList;
31
32 /**
33 * @param conflict the conflict data set
34 * @param mergedNodeList the list of merged nodes
35 */
36 @SuppressWarnings("unchecked")
37 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
38 this.conflict = (Conflict<Way>) conflict;
39 this.mergedNodeList = mergedNodeList;
40 }
41
42 @Override
43 public String getDescriptionText() {
44 return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId());
45 }
46
47 @Override
48 public Icon getDescriptionIcon() {
49 return ImageProvider.get("data", "object");
50 }
51
52 @Override
53 public boolean executeCommand() {
54 // remember the current state of 'my' way
55 //
56 super.executeCommand();
57
58 // replace the list of nodes of 'my' way by the list of merged nodes
59 //
60 for (Node n:mergedNodeList) {
61 if (!getAffectedDataSet().getNodes().contains(n)) {
62 Main.warn(tr("Main dataset does not include node {0}", n.toString()));
63 }
64 }
65 conflict.getMy().setNodes(mergedNodeList);
66 rememberConflict(conflict);
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 return Objects.hash(super.hashCode(), conflict, mergedNodeList);
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (this == obj) return true;
84 if (obj == null || getClass() != obj.getClass()) return false;
85 if (!super.equals(obj)) return false;
86 WayNodesConflictResolverCommand that = (WayNodesConflictResolverCommand) obj;
87 return Objects.equals(conflict, that.conflict) &&
88 Objects.equals(mergedNodeList, that.mergedNodeList);
89 }
90}
Note: See TracBrowser for help on using the repository browser.