### Question:
DataFlagEncoder extends AbstractFlagEncoder { public static double stringToTons(String value) { value = value.toLowerCase().replaceAll(" ", "").replaceAll("(tons|ton)", "t"); value = value.replace("mgw", "").trim(); double factor = 1; if (value.endsWith("t")) { value = value.substring(0, value.length() - 1); } else if (value.endsWith("lbs")) { value = value.substring(0, value.length() - 3); factor = 0.00045359237; } return Double.parseDouble(value) * factor; } DataFlagEncoder();  DataFlagEncoder(PMap properties);  DataFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts); @Override int defineWayBits(int index, int shift); @Override long handleRelationTags(ReaderRelation relation, long oldRelationFlags); @Override long acceptWay(ReaderWay way); AccessValue getAccessValue(long flags); @Override long handleWayTags(ReaderWay way, long allowed, long relationFlags); static double stringToTons(String value); static double stringToMeter(String value); int getSpatialId(long flags); long setSpatialId(long flags, int id); @Override long reverseFlags(long flags); int getHighway(EdgeIteratorState edge); String getHighwayAsString(EdgeIteratorState edge); int getSurface(EdgeIteratorState edge); String getSurfaceAsString(EdgeIteratorState edge); int getTransportMode(EdgeIteratorState edge); boolean isTransportModeTunnel(EdgeIteratorState edge); boolean isTransportModeBridge(EdgeIteratorState edge); boolean isTransportModeFord(long flags); String getTransportModeAsString(EdgeIteratorState edge); double[] getTransportModeMap(Map<String, Double> map); boolean isRoundabout(EdgeIteratorState edge); int getAccessType(String accessStr); final boolean isForward(EdgeIteratorState edge, int accessType); @Override final boolean isForward(long flags); final boolean isBackward(EdgeIteratorState edge, int accessType); @Override final boolean isBackward(long flags); double getMaxspeed(EdgeIteratorState edge, int accessType, boolean reverse); double getHeight(EdgeIteratorState edge); double getWeight(EdgeIteratorState edge); double getWidth(EdgeIteratorState edge); @Override long flagsDefault(boolean forward, boolean backward); @Override long setAccess(long flags, boolean forward, boolean backward); @Override long setSpeed(long flags, double speed); @Override double getSpeed(long flags); @Override long setReverseSpeed(long flags, double speed); @Override double getReverseSpeed(long flags); @Override long setProperties(double speed, boolean forward, boolean backward); @Override double getMaxSpeed(); double getMaxPossibleSpeed(); @Override boolean supports(Class<?> feature); DataFlagEncoder setStoreHeight(boolean storeHeight); boolean isStoreHeight(); DataFlagEncoder setStoreWeight(boolean storeWeight); boolean isStoreWeight(); DataFlagEncoder setStoreWidth(boolean storeWidth); boolean isStoreWidth(); DataFlagEncoder setSpatialRuleLookup(SpatialRuleLookup spatialRuleLookup); @Override InstructionAnnotation getAnnotation(long flags, Translation tr); @Override int getVersion(); @Override String toString(); WeightingConfig createWeightingConfig(PMap pMap);  }### Answer:
@Test public void stringToTons() { assertEquals(1.5, DataFlagEncoder.stringToTons("1.5"), DELTA); assertEquals(1.5, DataFlagEncoder.stringToTons("1.5 t"), DELTA); assertEquals(1.5, DataFlagEncoder.stringToTons("1.5 t"), DELTA); assertEquals(1.5, DataFlagEncoder.stringToTons("1.5 tons"), DELTA); assertEquals(1.5, DataFlagEncoder.stringToTons("1.5 ton"), DELTA); assertEquals(1.5, DataFlagEncoder.stringToTons("3306.9 lbs"), DELTA); assertEquals(3, DataFlagEncoder.stringToTons("3 T"), DELTA); assertEquals(3, DataFlagEncoder.stringToTons("3ton"), DELTA); assertEquals(6, DataFlagEncoder.stringToTons("6t mgw"), DELTA); }
@Test(expected = NumberFormatException.class) public void stringToTonsException() { DataFlagEncoder.stringToTons("weight limit 1.5t"); }