Changeset 16771 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2020-07-15T18:58:09+02:00 (4 years ago)
- File:
-
- 1 edited
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
Note:
See TracChangeset
for help on using the changeset viewer.