Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r15692 r15950 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import java.util.Arrays;5 4 import java.util.Collection; 6 import java.util.HashSet;7 5 import java.util.Locale; 8 6 import java.util.Map; 9 import java.util.Set;10 7 import java.util.regex.Pattern; 11 8 import java.util.stream.Stream; … … 19 16 */ 20 17 public final class OsmUtils { 21 22 private static final Set<String> TRUE_VALUES = new HashSet<>(Arrays23 .asList("true", "yes", "1", "on"));24 private static final Set<String> FALSE_VALUES = new HashSet<>(Arrays25 .asList("false", "no", "0", "off"));26 private static final Set<String> REVERSE_VALUES = new HashSet<>(Arrays27 .asList("reverse", "-1"));28 18 29 19 /** … … 70 60 if (value == null) return null; 71 61 String lowerValue = value.toLowerCase(Locale.ENGLISH); 72 if ( TRUE_VALUES.contains(lowerValue)) return Boolean.TRUE;73 if ( FALSE_VALUES.contains(lowerValue)) return Boolean.FALSE;62 if (isTrue(lowerValue)) return Boolean.TRUE; 63 if (isFalse(lowerValue)) return Boolean.FALSE; 74 64 return null; 75 65 } … … 93 83 */ 94 84 public static boolean isReversed(String value) { 95 return REVERSE_VALUES.contains(value); 85 switch (value) { 86 case "reverse": 87 case "-1": 88 return true; 89 default: 90 return false; 91 } 96 92 } 97 93 … … 102 98 */ 103 99 public static boolean isTrue(String value) { 104 return TRUE_VALUES.contains(value); 100 switch (value) { 101 case "true": 102 case "yes": 103 case "1": 104 case "on": 105 return true; 106 default: 107 return false; 108 } 105 109 } 106 110 … … 111 115 */ 112 116 public static boolean isFalse(String value) { 113 return FALSE_VALUES.contains(value); 117 switch (value) { 118 case "false": 119 case "no": 120 case "0": 121 case "off": 122 return true; 123 default: 124 return false; 125 } 114 126 } 115 127 -
trunk/test/unit/org/openstreetmap/josm/data/osm/OsmUtilsTest.java
r15671 r15950 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNull; 5 7 import static org.junit.Assert.assertTrue; 6 8 … … 14 16 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 15 17 18 /** 19 * Unit tests for class {@link OsmUtils}. 20 */ 16 21 public class OsmUtilsTest { 17 22 … … 23 28 public JOSMTestRules test = new JOSMTestRules(); 24 29 30 /** 31 * Unit test of {@link OsmUtils#createPrimitive} 32 */ 25 33 @Test 26 public void testCreatePrimitive() throws Exception{34 public void testCreatePrimitive() { 27 35 final OsmPrimitive p = OsmUtils.createPrimitive("way name=Foo railway=rail"); 28 36 assertTrue(p instanceof Way); … … 32 40 } 33 41 42 /** 43 * Unit test of {@link OsmUtils#createPrimitive} 44 */ 34 45 @Test 35 public void testArea() throws Exception{46 public void testArea() { 36 47 final OsmPrimitive p = OsmUtils.createPrimitive("area name=Foo railway=rail"); 37 48 assertEquals(OsmPrimitiveType.WAY, p.getType()); 38 assert True(p.getKeys().equals(OsmUtils.createPrimitive("way name=Foo railway=rail").getKeys()));49 assertEquals(p.getKeys(), OsmUtils.createPrimitive("way name=Foo railway=rail").getKeys()); 39 50 } 40 51 52 /** 53 * Unit test of {@link OsmUtils#createPrimitive} 54 */ 41 55 @Test(expected = IllegalArgumentException.class) 42 public void testCreatePrimitiveFail() throws Exception{56 public void testCreatePrimitiveFail() { 43 57 OsmUtils.createPrimitive("noway name=Foo"); 44 58 } 45 59 60 /** 61 * Unit test of {@link OsmUtils#splitMultipleValues} 62 */ 46 63 @Test 47 64 public void testSplitMultipleValues() { … … 52 69 OsmUtils.splitMultipleValues("Tu-Fr 08:00-18:00;Mo 09:00-18:00;Sa 09:00-12:00;closed Aug").collect(Collectors.toList())); 53 70 } 71 72 /** 73 * Unit test of {@link OsmUtils#isTrue}, {@link OsmUtils#isFalse}, {@link OsmUtils#getOsmBoolean} 74 */ 75 @Test 76 public void testTrueFalse() { 77 assertTrue(OsmUtils.isTrue("yes")); 78 assertFalse(OsmUtils.isFalse("yes")); 79 assertEquals(Boolean.TRUE, OsmUtils.getOsmBoolean("yes")); 80 assertTrue(OsmUtils.isFalse("no")); 81 assertFalse(OsmUtils.isTrue("no")); 82 assertEquals(Boolean.FALSE, OsmUtils.getOsmBoolean("no")); 83 assertNull(OsmUtils.getOsmBoolean("foobar")); 84 } 54 85 }
Note:
See TracChangeset
for help on using the changeset viewer.