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

Last change on this file since 6093 was 6093, checked in by akks, 11 years ago

see #8902 - collection size ==/!= 0 -> isEmpty()/!isEmpty() (patch by shinigami)

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