source: josm/trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java@ 12726

Last change on this file since 12726 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: 4.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.util.Collection;
7import java.util.List;
8import java.util.Objects;
9
10import javax.swing.Icon;
11
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
16import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeItem;
17import org.openstreetmap.josm.tools.ImageProvider;
18
19/**
20 * Represents the resolution of a tag conflict in an {@link OsmPrimitive}.
21 *
22 */
23public class TagConflictResolveCommand extends ConflictResolveCommand {
24 /** the conflict to resolve */
25 private final Conflict<? extends OsmPrimitive> conflict;
26
27 /** the list of merge decisions, represented as {@link TagMergeItem}s */
28 private final List<TagMergeItem> mergeItems;
29
30 /**
31 * replies the number of decided conflicts
32 *
33 * @return the number of decided conflicts
34 */
35 public int getNumDecidedConflicts() {
36 int n = 0;
37 for (TagMergeItem item: mergeItems) {
38 if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
39 n++;
40 }
41 }
42 return n;
43 }
44
45 /**
46 * constructor
47 *
48 * @param conflict the conflict data set
49 * @param mergeItems the list of merge decisions, represented as {@link TagMergeItem}s
50 */
51 public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
52 super(conflict.getMy().getDataSet());
53 this.conflict = conflict;
54 this.mergeItems = mergeItems;
55 }
56
57 @Override
58 public String getDescriptionText() {
59 switch (OsmPrimitiveType.from(conflict.getMy())) {
60 case NODE:
61 /* for correct i18n of plural forms - see #9110 */
62 return trn("Resolve {0} tag conflict in node {1}", "Resolve {0} tag conflicts in node {1}",
63 getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
64 case WAY:
65 /* for correct i18n of plural forms - see #9110 */
66 return trn("Resolve {0} tag conflict in way {1}", "Resolve {0} tag conflicts in way {1}",
67 getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
68 case RELATION:
69 /* for correct i18n of plural forms - see #9110 */
70 return trn("Resolve {0} tag conflict in relation {1}", "Resolve {0} tag conflicts in relation {1}",
71 getNumDecidedConflicts(), getNumDecidedConflicts(), conflict.getMy().getId());
72 default:
73 return "";
74 }
75 }
76
77 @Override
78 public Icon getDescriptionIcon() {
79 return ImageProvider.get("data", "object");
80 }
81
82 @Override
83 public boolean executeCommand() {
84 // remember the current state of modified primitives, i.e. of
85 // OSM primitive 'my'
86 //
87 super.executeCommand();
88
89 // apply the merge decisions to OSM primitive 'my'
90 //
91 for (TagMergeItem item: mergeItems) {
92 if (!item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) {
93 item.applyToMyPrimitive(conflict.getMy());
94 }
95 }
96 rememberConflict(conflict);
97 return true;
98 }
99
100 @Override
101 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
102 Collection<OsmPrimitive> added) {
103 modified.add(conflict.getMy());
104 }
105
106 @Override
107 public int hashCode() {
108 return Objects.hash(super.hashCode(), conflict, mergeItems);
109 }
110
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) return true;
114 if (obj == null || getClass() != obj.getClass()) return false;
115 if (!super.equals(obj)) return false;
116 TagConflictResolveCommand that = (TagConflictResolveCommand) obj;
117 return Objects.equals(conflict, that.conflict) &&
118 Objects.equals(mergeItems, that.mergeItems);
119 }
120}
Note: See TracBrowser for help on using the repository browser.