1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Set;
|
---|
5 | import java.util.TreeSet;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * A simple class to keep helper functions for merging TIGER data
|
---|
9 | *
|
---|
10 | * @author daveh
|
---|
11 | * @since 529
|
---|
12 | */
|
---|
13 | public final class TigerUtils {
|
---|
14 |
|
---|
15 | private TigerUtils() {
|
---|
16 | // Hide default constructor for utils classes
|
---|
17 | }
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Determines if the given tag is a TIGER one
|
---|
21 | * @param tag The tag to check
|
---|
22 | * @return {@code true} if {@code tag} starts with {@code tiger:} namespace
|
---|
23 | */
|
---|
24 | public static boolean isTigerTag(String tag) {
|
---|
25 | if (tag.indexOf("tiger:") == -1)
|
---|
26 | return false;
|
---|
27 | return true;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public static boolean tagIsInt(String name) {
|
---|
31 | if (name.equals("tiger:tlid"))
|
---|
32 | return true;
|
---|
33 | return false;
|
---|
34 | }
|
---|
35 |
|
---|
36 | public static Object tagObj(String name) {
|
---|
37 | if (tagIsInt(name))
|
---|
38 | return Integer.valueOf(name);
|
---|
39 | return name;
|
---|
40 | }
|
---|
41 |
|
---|
42 | public static String combineTags(String name, Set<String> values) {
|
---|
43 | TreeSet<Object> resultSet = new TreeSet<Object>();
|
---|
44 | for (String value: values) {
|
---|
45 | String[] parts = value.split(":");
|
---|
46 | for (String part: parts) {
|
---|
47 | resultSet.add(tagObj(part));
|
---|
48 | }
|
---|
49 | // Do not produce useless changeset noise if a single value is used and does not contain redundant splitted parts (fix #7405)
|
---|
50 | if (values.size() == 1 && resultSet.size() == parts.length) {
|
---|
51 | return value;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | StringBuilder combined = new StringBuilder();
|
---|
55 | for (Object part : resultSet) {
|
---|
56 | if (combined.length() > 0) {
|
---|
57 | combined.append(":");
|
---|
58 | }
|
---|
59 | combined.append(part);
|
---|
60 | }
|
---|
61 | return combined.toString();
|
---|
62 | }
|
---|
63 |
|
---|
64 | public static String combineTags(String name, String t1, String t2) {
|
---|
65 | Set<String> set = new TreeSet<String>();
|
---|
66 | set.add(t1);
|
---|
67 | set.add(t2);
|
---|
68 | return TigerUtils.combineTags(name, set);
|
---|
69 | }
|
---|
70 | }
|
---|