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

Last change on this file since 8961 was 8910, checked in by Don-vip, 9 years ago

add unit test for ConflictAddCommand

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