1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command.conflict;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.List;
|
---|
8 | import java.util.Objects;
|
---|
9 |
|
---|
10 | import javax.swing.Icon;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.conflict.Conflict;
|
---|
14 | import org.openstreetmap.josm.data.osm.Node;
|
---|
15 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
16 | import org.openstreetmap.josm.data.osm.Way;
|
---|
17 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Represents the resolution of conflicts in the node list of two {@link Way}s.
|
---|
21 | *
|
---|
22 | */
|
---|
23 | public 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 | }
|
---|