Changeset 16771 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrector.java
r16438 r16771 28 28 import org.openstreetmap.josm.data.osm.Tagged; 29 29 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.tools.Logging; 30 31 import org.openstreetmap.josm.tools.UserCancelException; 31 32 … … 202 203 203 204 /** 204 * Inverts sign of a numeric value. 205 * Inverts sign of a numeric value and converts decimal number to use decimal point. 206 * Also removes sign from null value. 205 207 * @param value numeric value 206 208 * @return opposite numeric value 207 209 */ 208 210 public static String invertNumber(String value) { 209 Pattern pattern = Pattern.compile("^([+-]?)(\\d .*)$", Pattern.CASE_INSENSITIVE);211 Pattern pattern = Pattern.compile("^([+-]?)(\\d*[,.]?\\d*)(.*)$", Pattern.CASE_INSENSITIVE); 210 212 Matcher matcher = pattern.matcher(value); 211 213 if (!matcher.matches()) return value; 212 214 String sign = matcher.group(1); 213 String rest = matcher.group(2); 215 String number = matcher.group(2); 216 String symbol = matcher.group(3); 214 217 sign = "-".equals(sign) ? "" : "-"; 215 return sign + rest; 218 219 if (!number.isEmpty()) { 220 String fixedNum = number.replace(",", "."); 221 try { 222 double parsed = Double.parseDouble(fixedNum); 223 if (parsed != 0) { 224 return sign + fixedNum + symbol; 225 } else { 226 return fixedNum + symbol; 227 } 228 } catch (NumberFormatException e) { 229 Logging.trace(e); 230 return value; 231 } 232 } 233 234 return value; 216 235 } 217 236 -
trunk/test/unit/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrectorTest.java
r16182 r16771 59 59 assertSwitch(new Tag(k, "something"), new Tag(k, "something")); 60 60 } 61 // numbered incline (see #19508) 62 assertSwitch(new Tag("incline", "+0%"), new Tag("incline", "0%")); 63 assertSwitch(new Tag("incline", ".1%"), new Tag("incline", "-.1%")); 64 assertSwitch(new Tag("incline", "-10.0%"), new Tag("incline", "10.0%")); 65 assertSwitch(new Tag("incline", "0,6°"), new Tag("incline", "-0.6°")); 61 66 // direction=forward/backward/... 62 67 assertSwitch(new Tag("direction", "forward"), new Tag("direction", "backward")); … … 100 105 101 106 private void assertSwitch(Tag oldTag, Tag newTag) { 102 Assert.assertEquals( ReverseWayTagCorrector.TagSwitcher.apply(oldTag), newTag);107 Assert.assertEquals(newTag, ReverseWayTagCorrector.TagSwitcher.apply(oldTag)); 103 108 } 104 109
Note:
See TracChangeset
for help on using the changeset viewer.