Changeset 20243 in osm for applications/editors
- Timestamp:
- 2010-03-02T01:59:22+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxaxleload.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.AXLELOAD; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMaxaxleload extends RoadValueLimit { … … 7 9 super("maxaxleload", AXLELOAD, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseWeight(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxheight.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.HEIGHT; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMaxheight extends RoadValueLimit { … … 7 9 super("maxheight", HEIGHT, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseMeasure(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxlength.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.LENGTH; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMaxlength extends RoadValueLimit { … … 7 9 super("maxlength", LENGTH, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseMeasure(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxweight.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.WEIGHT; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMaxweight extends RoadValueLimit { … … 7 9 super("maxweight", WEIGHT, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseWeight(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMaxwidth.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.WIDTH; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMaxwidth extends RoadValueLimit { … … 7 9 super("maxwidth", WIDTH, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseMeasure(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadMinspeed.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.SPEED; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadMinspeed extends RoadValueLimit { … … 7 9 super("minspeed", SPEED, LimitType.MINIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseSpeed(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadValueLimit.java
r19216 r20243 34 34 } 35 35 36 protected abstract Float parse(String valueString); 37 36 38 public <N, W, R, M> Float evaluateW(W way, boolean forward, 37 39 AccessParameters accessParameters, DataSource<N, W, R, M> dataSource) { … … 49 51 String valueString = tags.getValue(keyName); 50 52 if (valueString != null) { 51 Float value = ValueStringParser.parseOsmDecimal(valueString, false);53 Float value = parse(valueString); 52 54 return value; 53 55 } else { -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/property/RoadWidth.java
r16520 r20243 2 2 3 3 import static org.openstreetmap.josm.plugins.graphview.core.property.VehiclePropertyTypes.WIDTH; 4 5 import org.openstreetmap.josm.plugins.graphview.core.util.ValueStringParser; 4 6 5 7 public class RoadWidth extends RoadValueLimit { … … 7 9 super("width", WIDTH, LimitType.MAXIMUM); 8 10 } 11 @Override 12 protected Float parse(String valueString) { 13 return ValueStringParser.parseMeasure(valueString); 14 } 9 15 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/core/util/ValueStringParser.java
r16520 r20243 71 71 /* try numeric speed (implied km/h) */ 72 72 73 Float maxspeed = parseOsmDecimal(value, false);74 if ( maxspeed != null) {75 return maxspeed;73 Float speed = parseOsmDecimal(value, false); 74 if (speed != null) { 75 return speed; 76 76 } 77 77 … … 102 102 } 103 103 104 private static final Pattern M_PATTERN = Pattern.compile("^([\\d\\.]+)\\s*m$"); 105 private static final Pattern KM_PATTERN = Pattern.compile("^([\\d\\.]+)\\s*km$"); 106 private static final Pattern MI_PATTERN = Pattern.compile("^([\\d\\.]+)\\s*mi$"); 107 private static final Pattern FEET_INCHES_PATTERN = Pattern.compile("^([\\d]+)'\\s*([\\d]+)\""); 108 109 private static final double M_PER_MI = 1609.344; 110 private static final double M_PER_INCH = 0.0254f; 111 112 /** 113 * parses a measure value given e.g. for the "width" or "length" key. 114 * 115 * @return measure in m; null if value had syntax errors 116 */ 117 public static final Float parseMeasure(String value) { 118 119 /* try numeric measure (implied m) */ 120 121 Float measure = parseOsmDecimal(value, false); 122 if (measure != null) { 123 return measure; 124 } 125 126 /* try m measure */ 127 128 Matcher mMatcher = M_PATTERN.matcher(value); 129 if (mMatcher.matches()) { 130 String mString = mMatcher.group(1); 131 return parseOsmDecimal(mString, false); 132 } 133 134 /* try km measure */ 135 136 Matcher kmMatcher = KM_PATTERN.matcher(value); 137 if (kmMatcher.matches()) { 138 String kmString = kmMatcher.group(1); 139 float km = parseOsmDecimal(kmString, false); 140 return 1000 * km; 141 } 142 143 /* try mi measure */ 144 145 Matcher miMatcher = MI_PATTERN.matcher(value); 146 if (miMatcher.matches()) { 147 String miString = miMatcher.group(1); 148 float mi = parseOsmDecimal(miString, false); 149 return (float)(M_PER_MI * mi); 150 } 151 152 /* try feet/inches measure */ 153 154 Matcher feetInchesMatcher = FEET_INCHES_PATTERN.matcher(value); 155 if (feetInchesMatcher.matches()) { 156 String feetString = feetInchesMatcher.group(1); 157 String inchesString = feetInchesMatcher.group(2); 158 try { 159 int feet = Integer.parseInt(feetString); 160 int inches = Integer.parseInt(inchesString); 161 if (feet >= 0 && inches >= 0 && inches < 12) { 162 return (float)(M_PER_INCH * (12 * feet + inches)); 163 } 164 } catch (NumberFormatException nfe) {} 165 } 166 167 /* all possibilities failed */ 168 169 return null; 170 } 171 172 private static final Pattern T_PATTERN = Pattern.compile("^([\\d\\.]+)\\s*t$"); 173 174 /** 175 * parses a weight value given e.g. for the "maxweight" or "maxaxleload" key. 176 * 177 * @return weight in t; null if value had syntax errors 178 */ 179 public static Float parseWeight(String value) { 180 181 /* try numeric weight (implied t) */ 182 183 Float weight = parseOsmDecimal(value, false); 184 if (weight != null) { 185 return weight; 186 } 187 188 /* try t weight */ 189 190 Matcher tMatcher = T_PATTERN.matcher(value); 191 if (tMatcher.matches()) { 192 String tString = tMatcher.group(1); 193 return parseOsmDecimal(tString, false); 194 } 195 196 /* all possibilities failed */ 197 198 return null; 199 200 } 201 104 202 private static final Pattern INCLINE_PATTERN = Pattern.compile("^(\\-?\\d+(?:\\.\\d+)?)\\s*%$"); 105 203 … … 119 217 return null; 120 218 } 219 121 220 } -
applications/editors/josm/plugins/graphview/src/org/openstreetmap/josm/plugins/graphview/plugin/preferences/VehiclePropertyStringParser.java
r16520 r20243 15 15 */ 16 16 public final class VehiclePropertyStringParser { 17 17 18 18 /** prevents instantiation */ 19 19 private VehiclePropertyStringParser() { } 20 20 21 21 /** 22 22 * Exception class for syntax errors in property value Strings, … … 29 29 } 30 30 } 31 31 32 32 public static final String ERROR_WEIGHT = 33 "Weights must be given as positive decimal numbers with out unit.";33 "Weights must be given as positive decimal numbers with unit \"t\" or without unit."; 34 34 public static final String ERROR_LENGTH = 35 "Lengths must be given as positive decimal numbers without unit."; 35 "Lengths must be given as positive decimal numbers with unit \"m\", \"km\", \"mi\"" + 36 " or without unit.\nAlternatively, the format FEET' INCHES\" can be used."; 36 37 public static final String ERROR_SPEED = 37 38 "Speeds should be given as numbers without unit or " … … 43 44 public static final String ERROR_SURFACE = 44 45 "Surface values must not contain any of the following characters: ',' '{' '}' '=' '|"; 45 46 46 47 private static final List<Character> FORBIDDEN_SURFACE_CHARS = 47 48 Arrays.asList(',', '{', '}', '=', '|'); 48 49 49 50 /** 50 51 * returns the value represented by the propertyValueString … … 62 63 VehiclePropertyType<V> propertyType, String propertyValueString) 63 64 throws PropertyValueSyntaxException { 64 65 65 66 assert propertyType != null && propertyValueString != null; 66 67 67 68 if (propertyType == VehiclePropertyTypes.AXLELOAD 68 69 || propertyType == VehiclePropertyTypes.WEIGHT) { 69 70 Float value = ValueStringParser.parse OsmDecimal(propertyValueString, false);70 71 Float value = ValueStringParser.parseWeight(propertyValueString); 71 72 if (value != null && propertyType.isValidValue(value)) { 72 73 @SuppressWarnings("unchecked") //V must be float because of propertyType condition … … 76 77 throw new PropertyValueSyntaxException(ERROR_WEIGHT); 77 78 } 78 79 79 80 } else if (propertyType == VehiclePropertyTypes.HEIGHT 80 81 || propertyType == VehiclePropertyTypes.LENGTH 81 82 || propertyType == VehiclePropertyTypes.WIDTH) { 82 83 Float value = ValueStringParser.parse OsmDecimal(propertyValueString, false);83 84 Float value = ValueStringParser.parseMeasure(propertyValueString); 84 85 if (value != null && propertyType.isValidValue(value)) { 85 86 @SuppressWarnings("unchecked") //V must be float because of propertyType condition … … 89 90 throw new PropertyValueSyntaxException(ERROR_LENGTH); 90 91 } 91 92 92 93 } else if (propertyType == VehiclePropertyTypes.SPEED) { 93 94 94 95 Float value = ValueStringParser.parseSpeed(propertyValueString); 95 96 if (value != null && propertyType.isValidValue(value)) { … … 100 101 throw new PropertyValueSyntaxException(ERROR_SPEED); 101 102 } 102 103 103 104 } else if (propertyType == VehiclePropertyTypes.MAX_INCLINE_DOWN 104 105 || propertyType == VehiclePropertyTypes.MAX_INCLINE_UP) { 105 106 106 107 Float value = ValueStringParser.parseIncline(propertyValueString); 107 108 if (value != null && propertyType.isValidValue(value)) { … … 112 113 throw new PropertyValueSyntaxException(ERROR_INCLINE); 113 114 } 114 115 115 116 } else if (propertyType == VehiclePropertyTypes.MAX_TRACKTYPE) { 116 117 117 118 try { 118 119 int value = Integer.parseInt(propertyValueString); … … 123 124 } 124 125 } catch (NumberFormatException e) {} 125 126 126 127 throw new PropertyValueSyntaxException(ERROR_TRACKTYPE); 127 128 128 129 } else if (propertyType == VehiclePropertyTypes.SURFACE_BLACKLIST) { 129 130 130 131 String[] surfaces = propertyValueString.split(";\\s*"); 131 132 Collection<String> surfaceBlacklist = new ArrayList<String>(surfaces.length); … … 138 139 surfaceBlacklist.add(surface); 139 140 } 140 141 141 142 @SuppressWarnings("unchecked") //V must be Collection because of propertyType condition 142 143 V result = (V)surfaceBlacklist; 143 144 return result; 144 145 145 146 } else { 146 147 throw new InvalidParameterException("unknown property type: " + propertyType); 147 148 } 148 149 149 150 } 150 151 151 152 }
Note:
See TracChangeset
for help on using the changeset viewer.