source: josm/trunk/src/org/openstreetmap/josm/data/osm/TigerUtils.java@ 7509

Last change on this file since 7509 was 7509, checked in by stoecker, 10 years ago

remove tabs

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Set;
5import 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 */
13public 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(String name, Set<String> values) {
48 TreeSet<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
69 public static String combineTags(String name, String t1, String t2) {
70 Set<String> set = new TreeSet<>();
71 set.add(t1);
72 set.add(t2);
73 return TigerUtils.combineTags(name, set);
74 }
75}
Note: See TracBrowser for help on using the repository browser.