@Test public void testConvertToTime() throws ParseException { final Object[][] testParameters = new Object[][] {{"1µs", 1L}, {"1.1µs", 1L}, {"1microseconds", 1L}, {"1ms", 1000L}, {"1.1ms", 1100L}, {"1milliseconds", 1000L}, {"1.1s", 1100000L}, {"1s", 1000000L}, {"1sec", 1000000L}, {"1seconds", 1000000L}, {"1m", 60000000L}, {"1.1m", 66000000L}, {"1min", 60000000L}, {"1minutes", 60000000L}, {"1h", 3600000000L}, {"1.1h", 3960000000L}, {"1hr", 3600000000L}, {"1hours", 3600000000L}}; try { ParsingUtils.convertToTime("Not"); } catch (ParseException e) { assertEquals("Not", e.getMessage()); assertEquals(0, e.getErrorOffset()); } for (final Object[] testParameter : testParameters) { long expected = (Long) testParameter[1]; String val = (String) testParameter[0]; assertEquals(expected, ParsingUtils.convertToTime(val)); } }
public static long convertToTime(final String val) throws ParseException { if (null == val) { return 0; } final String lowerVal = val.toLowerCase(); for (final ScaleUnit unit : INTERVALS) { final String units = unit.units; if (lowerVal.endsWith(units)) { final String digits = lowerVal.substring(0, lowerVal.length() - units.length()).trim(); final Double microSeconds = Double.parseDouble(digits) * unit.scale; return microSeconds.longValue(); } } throw new ParseException(val, 0); }
ParsingUtils { public static long convertToTime(final String val) throws ParseException { if (null == val) { return 0; } final String lowerVal = val.toLowerCase(); for (final ScaleUnit unit : INTERVALS) { final String units = unit.units; if (lowerVal.endsWith(units)) { final String digits = lowerVal.substring(0, lowerVal.length() - units.length()).trim(); final Double microSeconds = Double.parseDouble(digits) * unit.scale; return microSeconds.longValue(); } } throw new ParseException(val, 0); } }
ParsingUtils { public static long convertToTime(final String val) throws ParseException { if (null == val) { return 0; } final String lowerVal = val.toLowerCase(); for (final ScaleUnit unit : INTERVALS) { final String units = unit.units; if (lowerVal.endsWith(units)) { final String digits = lowerVal.substring(0, lowerVal.length() - units.length()).trim(); final Double microSeconds = Double.parseDouble(digits) * unit.scale; return microSeconds.longValue(); } } throw new ParseException(val, 0); }  }
ParsingUtils { public static long convertToTime(final String val) throws ParseException { if (null == val) { return 0; } final String lowerVal = val.toLowerCase(); for (final ScaleUnit unit : INTERVALS) { final String units = unit.units; if (lowerVal.endsWith(units)) { final String digits = lowerVal.substring(0, lowerVal.length() - units.length()).trim(); final Double microSeconds = Double.parseDouble(digits) * unit.scale; return microSeconds.longValue(); } } throw new ParseException(val, 0); }  static boolean convertToBoolean(final String str, final boolean defaultValueIsTrue); static boolean convertToBoolean(final String val); static int convertToInt(final String val); static int convertToInt(final String val, final int defaultValue); static long convertToLong(final String val); static long convertToLong(final String val, final int defaultValue); static long convertToLong(final String val, final long defaultValue); static double convertToDouble(final String val); static double convertToDouble(final String val, final double defaultValue); static long convertToCapacity(
      final String str,
      final long defaultValue); static long convertToTime(final String val); static long parse(
      final String val,
      final TimeUnit unit); }
ParsingUtils { public static long convertToTime(final String val) throws ParseException { if (null == val) { return 0; } final String lowerVal = val.toLowerCase(); for (final ScaleUnit unit : INTERVALS) { final String units = unit.units; if (lowerVal.endsWith(units)) { final String digits = lowerVal.substring(0, lowerVal.length() - units.length()).trim(); final Double microSeconds = Double.parseDouble(digits) * unit.scale; return microSeconds.longValue(); } } throw new ParseException(val, 0); }  static boolean convertToBoolean(final String str, final boolean defaultValueIsTrue); static boolean convertToBoolean(final String val); static int convertToInt(final String val); static int convertToInt(final String val, final int defaultValue); static long convertToLong(final String val); static long convertToLong(final String val, final int defaultValue); static long convertToLong(final String val, final long defaultValue); static double convertToDouble(final String val); static double convertToDouble(final String val, final double defaultValue); static long convertToCapacity(
      final String str,
      final long defaultValue); static long convertToTime(final String val); static long parse(
      final String val,
      final TimeUnit unit); static final List<ScaleUnit> INTERVALS; }