1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Arrays;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Locale;
|
---|
8 |
|
---|
9 | public final class OsmUtils {
|
---|
10 |
|
---|
11 | private OsmUtils() {
|
---|
12 | // Hide default constructor for utils classes
|
---|
13 | }
|
---|
14 |
|
---|
15 | static final List<String> TRUE_VALUES = new ArrayList<String>(Arrays
|
---|
16 | .asList(new String[] { "true", "yes", "1", "on" }));
|
---|
17 | static final List<String> FALSE_VALUES = new ArrayList<String>(Arrays
|
---|
18 | .asList(new String[] { "false", "no", "0", "off" }));
|
---|
19 | static final List<String> REVERSE_VALUES = new ArrayList<String>(Arrays
|
---|
20 | .asList(new String[] { "reverse", "-1" }));
|
---|
21 |
|
---|
22 | public static final String trueval = "yes";
|
---|
23 | public static final String falseval = "no";
|
---|
24 | public static final String reverseval = "-1";
|
---|
25 |
|
---|
26 | public static Boolean getOsmBoolean(String value) {
|
---|
27 | if(value == null) return null;
|
---|
28 | String lowerValue = value.toLowerCase(Locale.ENGLISH);
|
---|
29 | if (TRUE_VALUES.contains(lowerValue)) return Boolean.TRUE;
|
---|
30 | if (FALSE_VALUES.contains(lowerValue)) return Boolean.FALSE;
|
---|
31 | return null;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public static String getNamedOsmBoolean(String value) {
|
---|
35 | Boolean res = getOsmBoolean(value);
|
---|
36 | return res == null ? value : (res ? trueval : falseval);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public static boolean isReversed(String value) {
|
---|
40 | return REVERSE_VALUES.contains(value);
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static boolean isTrue(String value) {
|
---|
44 | return TRUE_VALUES.contains(value);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public static boolean isFalse(String value) {
|
---|
48 | return FALSE_VALUES.contains(value);
|
---|
49 | }
|
---|
50 | }
|
---|