source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtil.java@ 7005

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

see #8465 - use diamond operator where applicable

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.tags;
3
4import java.util.ArrayList;
5import java.util.Collection;
6
7import org.openstreetmap.josm.data.osm.OsmPrimitive;
8import org.openstreetmap.josm.data.osm.Tag;
9import org.openstreetmap.josm.data.osm.TagCollection;
10import org.openstreetmap.josm.data.osm.TigerUtils;
11
12/**
13 * Collection of utility methods for tag conflict resolution
14 *
15 */
16public final class TagConflictResolutionUtil {
17
18 /** no constructor, just static utility methods */
19 private TagConflictResolutionUtil() {}
20
21 /**
22 * Normalizes the tags in the tag collection <code>tc</code> before resolving tag conflicts.
23 *
24 * Removes irrelevant tags like "created_by".
25 *
26 * For tags which are not present on at least one of the merged nodes, the empty value ""
27 * is added to the list of values for this tag, but only if there are at least two
28 * primitives with tags, and at least one tagged primitive do not have this tag.
29 *
30 * @param tc the tag collection
31 * @param merged the collection of merged primitives
32 */
33 public static void normalizeTagCollectionBeforeEditing(TagCollection tc, Collection<? extends OsmPrimitive> merged) {
34 // remove irrelevant tags
35 //
36 for(String key : OsmPrimitive.getDiscardableKeys()) {
37 tc.removeByKey(key);
38 }
39
40 Collection<OsmPrimitive> taggedPrimitives = new ArrayList<>();
41 for (OsmPrimitive p: merged) {
42 if (p.isTagged()) {
43 taggedPrimitives.add(p);
44 }
45 }
46 if (taggedPrimitives.size() <= 1)
47 return;
48
49 for (String key: tc.getKeys()) {
50 // make sure the empty value is in the tag set if a tag is not present
51 // on all merged nodes
52 //
53 for (OsmPrimitive p: taggedPrimitives) {
54 if (p.get(key) == null) {
55 tc.add(new Tag(key, "")); // add a tag with key and empty value
56 }
57 }
58 }
59 }
60
61 /**
62 * Combines tags from TIGER data
63 *
64 * @param tc the tag collection
65 */
66 public static void combineTigerTags(TagCollection tc) {
67 for (String key: tc.getKeys()) {
68 if (TigerUtils.isTigerTag(key)) {
69 tc.setUniqueForKey(key, TigerUtils.combineTags(key, tc.getValues(key)));
70 }
71 }
72 }
73
74 /**
75 * Completes tags in the tag collection <code>tc</code> with the empty value
76 * for each tag. If the empty value is present the tag conflict resolution dialog
77 * will offer an option for removing the tag and not only options for selecting
78 * one of the current values of the tag.
79 *
80 * @param tc the tag collection
81 */
82 public static void completeTagCollectionForEditing(TagCollection tc) {
83 for (String key: tc.getKeys()) {
84 // make sure the empty value is in the tag set such that we can delete the tag
85 // in the conflict dialog if necessary
86 //
87 tc.add(new Tag(key,""));
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.