Changeset 15671 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r14486 r15671 8 8 import java.util.Map; 9 9 import java.util.Set; 10 import java.util.regex.Pattern; 11 import java.util.stream.Stream; 10 12 11 13 import org.openstreetmap.josm.data.coor.LatLon; … … 207 209 return ds == null || !ds.isLocked(); 208 210 } 211 212 /** 213 * Splits a tag value by <a href="https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator">semi-colon value separator</a>. 214 * Spaces around the ; are ignored. 215 * 216 * @param value the value to separate 217 * @return the separated values as Stream 218 * @since xxx 219 */ 220 public static Stream<String> splitMultipleValues(String value) { 221 return Pattern.compile("\\s*;\\s*").splitAsStream(value); 222 } 209 223 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ConditionFactory.java
r15245 r15671 4 4 import java.lang.reflect.Method; 5 5 import java.text.MessageFormat; 6 import java.util.Arrays;7 6 import java.util.EnumSet; 8 7 import java.util.Map; … … 173 172 /** The reference is treated as a list separated by ';'. Spaces around the ; are ignored. 174 173 * The value needs to be equal one of the list elements. */ 175 ONE_OF((test, prototype) -> Arrays.asList(test.split("\\s*;\\s*")).contains(prototype)),174 ONE_OF((test, prototype) -> OsmUtils.splitMultipleValues(test).anyMatch(prototype::equals)), 176 175 /** The value needs to begin with the reference string. */ 177 176 BEGINS_WITH(String::startsWith), -
trunk/test/unit/org/openstreetmap/josm/data/osm/OsmUtilsTest.java
r10945 r15671 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertTrue; 6 7 import java.util.Arrays; 8 import java.util.stream.Collectors; 6 9 7 10 import org.junit.Rule; … … 40 43 OsmUtils.createPrimitive("noway name=Foo"); 41 44 } 45 46 @Test 47 public void testSplitMultipleValues() { 48 // examples from https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator 49 assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500;B550").collect(Collectors.toList())); 50 assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500 ; B550").collect(Collectors.toList())); 51 assertEquals(Arrays.asList("Tu-Fr 08:00-18:00", "Mo 09:00-18:00", "Sa 09:00-12:00", "closed Aug"), 52 OsmUtils.splitMultipleValues("Tu-Fr 08:00-18:00;Mo 09:00-18:00;Sa 09:00-12:00;closed Aug").collect(Collectors.toList())); 53 } 42 54 }
Note:
See TracChangeset
for help on using the changeset viewer.