source: josm/trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java@ 13186

Last change on this file since 13186 was 12726, checked in by Don-vip, 7 years ago

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

  • Property svn:eol-style set to native
File size: 3.5 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.Objects;
8import java.util.Set;
9
10import javax.swing.Icon;
11
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Represents the resolution of a conflict between the deleted flag of two {@link OsmPrimitive}s.
19 * @since 1654
20 */
21public class DeletedStateConflictResolveCommand extends ConflictResolveCommand {
22
23 /** the conflict to resolve */
24 private final Conflict<? extends OsmPrimitive> conflict;
25
26 /** the merge decision */
27 private final MergeDecisionType decision;
28
29 /**
30 * Constructs a new {@code DeletedStateConflictResolveCommand}.
31 *
32 * @param conflict the conflict data set
33 * @param decision the merge decision
34 */
35 public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
36 super(conflict.getMy().getDataSet());
37 this.conflict = conflict;
38 this.decision = decision;
39 }
40
41 @Override
42 public String getDescriptionText() {
43 return tr("Resolve conflicts in deleted state in {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 modified primitives, i.e. of OSM primitive 'my'
54 super.executeCommand();
55
56 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
57 if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
58 // because my was involved in a conflict it my still be referred
59 // to from a way or a relation. Fix this now.
60 deleteMy();
61 }
62 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
63 if (conflict.getTheir().isDeleted()) {
64 deleteMy();
65 } else {
66 conflict.getMy().setDeleted(false);
67 }
68 } else
69 // should not happen
70 throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
71
72 rememberConflict(conflict);
73 return true;
74 }
75
76 private void deleteMy() {
77 Set<OsmPrimitive> referrers = getAffectedDataSet().unlinkReferencesToPrimitive(conflict.getMy());
78 for (OsmPrimitive p : referrers) {
79 if (!p.isNew() && !p.isDeleted()) {
80 p.setModified(true);
81 }
82 }
83 conflict.getMy().setDeleted(true);
84 }
85
86 @Override
87 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
88 Collection<OsmPrimitive> added) {
89 modified.add(conflict.getMy());
90 modified.addAll(conflict.getMy().getReferrers());
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hash(super.hashCode(), conflict, decision);
96 }
97
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj) return true;
101 if (obj == null || getClass() != obj.getClass()) return false;
102 if (!super.equals(obj)) return false;
103 DeletedStateConflictResolveCommand that = (DeletedStateConflictResolveCommand) obj;
104 return decision == that.decision && Objects.equals(conflict, that.conflict);
105 }
106}
Note: See TracBrowser for help on using the repository browser.