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.data.conflict.Conflict;
|
---|
13 | import org.openstreetmap.josm.data.osm.Node;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
15 | import org.openstreetmap.josm.data.osm.Way;
|
---|
16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
17 | import org.openstreetmap.josm.tools.Logging;
|
---|
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 | * 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 | }
|
---|