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 | /**
|
---|
31 | * Determines if the given key denotes an integer value.
|
---|
32 | * @param name The key to determine
|
---|
33 | * @return {@code true} if the given key denotes an integer value
|
---|
34 | */
|
---|
35 | public static boolean tagIsInt(String name) {
|
---|
36 | if ("tiger:tlid".equals(name))
|
---|
37 | return true;
|
---|
38 | return false;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static Object tagObj(String name) {
|
---|
42 | if (tagIsInt(name))
|
---|
43 | return Integer.valueOf(name);
|
---|
44 | return name;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public static String combineTags(Set<String> values) {
|
---|
48 | Set<Object> resultSet = new TreeSet<>();
|
---|
49 | for (String value: values) {
|
---|
50 | String[] parts = value.split(":");
|
---|
51 | for (String part: parts) {
|
---|
52 | resultSet.add(tagObj(part));
|
---|
53 | }
|
---|
54 | // Do not produce useless changeset noise if a single value is used and does not contain redundant splitted parts (fix #7405)
|
---|
55 | if (values.size() == 1 && resultSet.size() == parts.length) {
|
---|
56 | return value;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | StringBuilder combined = new StringBuilder();
|
---|
60 | for (Object part : resultSet) {
|
---|
61 | if (combined.length() > 0) {
|
---|
62 | combined.append(':');
|
---|
63 | }
|
---|
64 | combined.append(part);
|
---|
65 | }
|
---|
66 | return combined.toString();
|
---|
67 | }
|
---|
68 | }
|
---|