2
* Copyright (C) 2008 Steve Ratcliffe
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
14
* Author: Steve Ratcliffe
15
* Create date: 07-Dec-2008
17
package uk.me.parabola.mkgmap.osmstyle.actions;
19
import uk.me.parabola.mkgmap.osmstyle.eval.UnitConversions;
22
* Convert a numeric quantity from one set of units to another.
24
* TODO: this will change a lot it is just here for backward compatibility
26
* @author Steve Ratcliffe
28
public class ConvertFilter extends ValueFilter {
29
private final double factor;
31
public ConvertFilter(String arg) {
32
factor = UnitConversions.convertFactor(arg);
35
public String doFilter(String value) {
36
if (value == null) return null;
39
double d = Double.parseDouble(value);
41
double res = d * factor;
42
res = Math.round(res);
43
return String.valueOf((int) res);
44
} catch (NumberFormatException e) {