001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004import java.util.ArrayList;
005import java.util.Arrays;
006import java.util.List;
007import java.util.Locale;
008
009public final class OsmUtils {
010    
011    private OsmUtils() {
012        // Hide default constructor for utils classes
013    }
014
015    static List<String> TRUE_VALUES = new ArrayList<String>(Arrays
016            .asList(new String[] { "true", "yes", "1", "on" }));
017    static List<String> FALSE_VALUES = new ArrayList<String>(Arrays
018            .asList(new String[] { "false", "no", "0", "off" }));
019    static List<String> REVERSE_VALUES = new ArrayList<String>(Arrays
020            .asList(new String[] { "reverse", "-1" }));
021
022    public static final String trueval = "yes";
023    public static final String falseval = "no";
024    public static final String reverseval = "-1";
025
026    public static Boolean getOsmBoolean(String value) {
027        if(value == null) return null;
028        String lowerValue = value.toLowerCase(Locale.ENGLISH);
029        if (TRUE_VALUES.contains(lowerValue)) return Boolean.TRUE;
030        if (FALSE_VALUES.contains(lowerValue)) return Boolean.FALSE;
031        return null;
032    }
033
034    public static String getNamedOsmBoolean(String value) {
035        Boolean res = getOsmBoolean(value);
036        return res == null ? value : (res ? trueval : falseval);
037    }
038
039    public static boolean isReversed(String value) {
040        return REVERSE_VALUES.contains(value);
041    }
042
043    public static boolean isTrue(String value) {
044        return TRUE_VALUES.contains(value);
045    }
046
047    public static boolean isFalse(String value) {
048        return FALSE_VALUES.contains(value);
049    }
050}