source: josm/trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.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.3 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;
8
9import javax.swing.Icon;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.Node;
14import org.openstreetmap.josm.data.osm.OsmPrimitive;
15import org.openstreetmap.josm.data.osm.Way;
16import org.openstreetmap.josm.tools.ImageProvider;
17
18/**
19 * Represents the resolution of conflicts in the node list of two {@link Way}s.
20 *
21 */
22public class WayNodesConflictResolverCommand extends ConflictResolveCommand {
23 /** the conflict to resolve */
24 private final Conflict<Way> conflict;
25
26 /** the list of merged nodes. This becomes the list of news of my way after the
27 * command is executed
28 */
29 private final List<Node> mergedNodeList;
30
31 /**
32 * @param conflict the conflict data set
33 * @param mergedNodeList the list of merged nodes
34 */
35 @SuppressWarnings("unchecked")
36 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
37 this.conflict = (Conflict<Way>) conflict;
38 this.mergedNodeList = mergedNodeList;
39 }
40
41 @Override
42 public String getDescriptionText() {
43 return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId());
44 }
45
46 @Override
47 public Icon getDescriptionIcon() {
48 return ImageProvider.get("data", "object");
49 }
50
51 @Override
52 public boolean executeCommand() {
53 // remember the current state of 'my' way
54 //
55 super.executeCommand();
56
57 // replace the list of nodes of 'my' way by the list of merged nodes
58 //
59 for (Node n:mergedNodeList) {
60 if (!getLayer().data.getNodes().contains(n)) {
61 Main.warn(tr("Main dataset does not include node {0}", n.toString()));
62 }
63 }
64 conflict.getMy().setNodes(mergedNodeList);
65 rememberConflict(conflict);
66 return true;
67 }
68
69 @Override
70 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
71 Collection<OsmPrimitive> added) {
72 modified.add(conflict.getMy());
73 }
74
75 @Override
76 public int hashCode() {
77 final int prime = 31;
78 int result = super.hashCode();
79 result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
80 result = prime * result + ((mergedNodeList == null) ? 0 : mergedNodeList.hashCode());
81 return result;
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj)
87 return true;
88 if (!super.equals(obj))
89 return false;
90 if (getClass() != obj.getClass())
91 return false;
92 WayNodesConflictResolverCommand other = (WayNodesConflictResolverCommand) obj;
93 if (conflict == null) {
94 if (other.conflict != null)
95 return false;
96 } else if (!conflict.equals(other.conflict))
97 return false;
98 if (mergedNodeList == null) {
99 if (other.mergedNodeList != null)
100 return false;
101 } else if (!mergedNodeList.equals(other.mergedNodeList))
102 return false;
103 return true;
104 }
105}
Note: See TracBrowser for help on using the repository browser.