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

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

sonar - fb-contrib:SEO_SUBOPTIMAL_EXPRESSION_ORDER - Performance - Method orders expressions in a conditional in a sub optimal way

  • 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 this.conflict = conflict;
37 this.decision = decision;
38 }
39
40 @Override
41 public String getDescriptionText() {
42 return tr("Resolve conflicts in deleted state in {0}", conflict.getMy().getId());
43 }
44
45 @Override
46 public Icon getDescriptionIcon() {
47 return ImageProvider.get("data", "object");
48 }
49
50 @Override
51 public boolean executeCommand() {
52 // remember the current state of modified primitives, i.e. of OSM primitive 'my'
53 super.executeCommand();
54
55 if (decision.equals(MergeDecisionType.KEEP_MINE)) {
56 if (conflict.getMy().isDeleted() || conflict.isMyDeleted()) {
57 // because my was involved in a conflict it my still be referred
58 // to from a way or a relation. Fix this now.
59 deleteMy();
60 }
61 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) {
62 if (conflict.getTheir().isDeleted()) {
63 deleteMy();
64 } else {
65 conflict.getMy().setDeleted(false);
66 }
67 } else
68 // should not happen
69 throw new IllegalStateException(tr("Cannot resolve undecided conflict."));
70
71 rememberConflict(conflict);
72 return true;
73 }
74
75 private void deleteMy() {
76 Set<OsmPrimitive> referrers = getAffectedDataSet().unlinkReferencesToPrimitive(conflict.getMy());
77 for (OsmPrimitive p : referrers) {
78 if (!p.isNew() && !p.isDeleted()) {
79 p.setModified(true);
80 }
81 }
82 conflict.getMy().setDeleted(true);
83 }
84
85 @Override
86 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
87 Collection<OsmPrimitive> added) {
88 modified.add(conflict.getMy());
89 modified.addAll(conflict.getMy().getReferrers());
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(super.hashCode(), conflict, decision);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) return true;
100 if (obj == null || getClass() != obj.getClass()) return false;
101 if (!super.equals(obj)) return false;
102 DeletedStateConflictResolveCommand that = (DeletedStateConflictResolveCommand) obj;
103 return decision == that.decision && Objects.equals(conflict, that.conflict);
104 }
105}
Note: See TracBrowser for help on using the repository browser.