source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/pair/tags/TagMergeItem.java@ 10378

Last change on this file since 10378 was 10378, checked in by Don-vip, 8 years ago

Checkstyle 6.19: enable SingleSpaceSeparator and fix violations

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.pair.tags;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
8import org.openstreetmap.josm.tools.CheckParameterUtil;
9
10/**
11 * TagMergeItem represents an individual merge action for a specific pair of key/value.
12 *
13 * A TagMergeItem manages the values of the two key/value-pairs and keeps track of the applied
14 * merge decision.
15 *
16 */
17public class TagMergeItem {
18
19 private final String key;
20 private final String myTagValue;
21 private final String theirTagValue;
22 private MergeDecisionType mergeDecision = MergeDecisionType.UNDECIDED;
23
24 /**
25 * constructor
26 *
27 * @param key the common tag key. Must not be null.
28 * @param myTagValue the value for this key known in the local dataset
29 * @param theirTagValue the value for this key known in the dataset on the server
30 * @throws IllegalArgumentException if key is null
31 */
32 public TagMergeItem(String key, String myTagValue, String theirTagValue) {
33 CheckParameterUtil.ensureParameterNotNull(key, "key");
34 this.key = key;
35 this.myTagValue = myTagValue;
36 this.theirTagValue = theirTagValue;
37 this.mergeDecision = MergeDecisionType.UNDECIDED;
38 }
39
40 /**
41 * constructor
42 *
43 * @param key the tag key common to the merged OSM primitives. Must not be null.
44 * @param my my version of the OSM primitive (i.e. the version known in the local dataset). Must not be null.
45 * @param their their version of the OSM primitive (i.e. the version known on the server). Must not be null.
46 * @throws IllegalArgumentException if key is null
47 * @throws IllegalArgumentException if my is null
48 * @throws IllegalArgumentException if their is null
49 */
50 public TagMergeItem(String key, OsmPrimitive my, OsmPrimitive their) {
51 CheckParameterUtil.ensureParameterNotNull(key, "key");
52 CheckParameterUtil.ensureParameterNotNull(my, "my");
53 CheckParameterUtil.ensureParameterNotNull(their, "their");
54 this.key = key;
55 myTagValue = my.get(key);
56 theirTagValue = their.get(key);
57 }
58
59 /**
60 * applies a merge decision to this merge item
61 *
62 * @param decision the merge decision. Must not be null.
63 * @throws IllegalArgumentException if decision is null
64 */
65 public void decide(MergeDecisionType decision) {
66 CheckParameterUtil.ensureParameterNotNull(decision, "decision");
67 this.mergeDecision = decision;
68 }
69
70 public String getKey() {
71 return key;
72 }
73
74 public String getMyTagValue() {
75 return myTagValue;
76 }
77
78 public String getTheirTagValue() {
79 return theirTagValue;
80 }
81
82 public MergeDecisionType getMergeDecision() {
83 return mergeDecision;
84 }
85
86 /**
87 * applies the current merge decisions to the tag set of an OSM primitive. The
88 * OSM primitive has the role of primitive in the local dataset ('my' primitive,
89 * not 'their' primitive)
90 *
91 * @param primitive the OSM primitive. Must not be null.
92 * @throws IllegalArgumentException if primitive is null
93 * @throws IllegalStateException if this merge item is undecided
94 */
95 public void applyToMyPrimitive(OsmPrimitive primitive) {
96 CheckParameterUtil.ensureParameterNotNull(primitive, "primitive");
97 if (mergeDecision == MergeDecisionType.UNDECIDED) {
98 throw new IllegalStateException(tr("Cannot apply undecided tag merge item."));
99 } else if (mergeDecision == MergeDecisionType.KEEP_THEIR) {
100 if (theirTagValue == null) {
101 primitive.remove(key);
102 } else {
103 primitive.put(key, theirTagValue);
104 }
105 } else if (mergeDecision == MergeDecisionType.KEEP_MINE) {
106 if (myTagValue == null) {
107 primitive.remove(key);
108 } else {
109 primitive.put(key, myTagValue);
110 }
111 }
112 }
113}
Note: See TracBrowser for help on using the repository browser.