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

Last change on this file since 13165 was 13158, checked in by Don-vip, 6 years ago

javadoc

  • Property svn:eol-style set to native
File size: 3.0 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.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;
17import org.openstreetmap.josm.tools.Logging;
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 * Constructs a new {@code WayNodesConflictResolverCommand}.
34 * @param conflict the conflict data set
35 * @param mergedNodeList the list of merged nodes
36 */
37 @SuppressWarnings("unchecked")
38 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
39 super(conflict.getMy().getDataSet());
40 this.conflict = (Conflict<Way>) conflict;
41 this.mergedNodeList = mergedNodeList;
42 }
43
44 @Override
45 public String getDescriptionText() {
46 return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId());
47 }
48
49 @Override
50 public Icon getDescriptionIcon() {
51 return ImageProvider.get("data", "object");
52 }
53
54 @Override
55 public boolean executeCommand() {
56 // remember the current state of 'my' way
57 //
58 super.executeCommand();
59
60 // replace the list of nodes of 'my' way by the list of merged nodes
61 //
62 for (Node n:mergedNodeList) {
63 if (!getAffectedDataSet().getNodes().contains(n)) {
64 Logging.warn(tr("Main dataset does not include node {0}", n.toString()));
65 }
66 }
67 conflict.getMy().setNodes(mergedNodeList);
68 rememberConflict(conflict);
69 return true;
70 }
71
72 @Override
73 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
74 Collection<OsmPrimitive> added) {
75 modified.add(conflict.getMy());
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hash(super.hashCode(), conflict, mergedNodeList);
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) return true;
86 if (obj == null || getClass() != obj.getClass()) return false;
87 if (!super.equals(obj)) return false;
88 WayNodesConflictResolverCommand that = (WayNodesConflictResolverCommand) obj;
89 return Objects.equals(conflict, that.conflict) &&
90 Objects.equals(mergedNodeList, that.mergedNodeList);
91 }
92}
Note: See TracBrowser for help on using the repository browser.