public static long getMilliSeconds(String rawString, Unit defaultUnit) throws NumberFormatException { Matcher res = PATTERN.matcher(rawString); if (res.matches()) { if (res.group(1) != null && res.group(2) != null) { long time = Integer.parseInt(res.group(1).trim()); String unit = res.group(2); if (Strings.isNullOrEmpty(unit)) { return getMilliSeconds(time, defaultUnit); } return getMilliSeconds(time, Unit.parse(unit)); } else { // This should never Happen anyway throw an exception throw new NumberFormatException("The supplied String is not a supported format " + rawString); } } else { // The rawString not match our pattern. So its not supported throw new NumberFormatException("The supplied String is not a supported format " + rawString); } }
public static long getMilliSeconds(String rawString, Unit defaultUnit) throws NumberFormatException { Matcher res = PATTERN.matcher(rawString); if (res.matches()) { if (res.group(1) != null && res.group(2) != null) { long time = Integer.parseInt(res.group(1).trim()); String unit = res.group(2); if (Strings.isNullOrEmpty(unit)) { return getMilliSeconds(time, defaultUnit); } return getMilliSeconds(time, Unit.parse(unit)); } else { // This should never Happen anyway throw an exception throw new NumberFormatException("The supplied String is not a supported format " + rawString); } } else { // The rawString not match our pattern. So its not supported throw new NumberFormatException("The supplied String is not a supported format " + rawString); } }
/** * Helper method to get the milliseconds for the given amount and unit * * @param amount * The amount for use with the unit * @param unit * The unit * @return The time in milliseconds * @throws NumberFormatException * Get thrown if an illegal unit was used */ public static long getMilliSeconds(long amount, String unit) throws NumberFormatException { return getMilliSeconds(amount, Unit.parse(unit)); }
/** * Helper method to get the milliseconds for the given amount and unit * * @param amount * The amount for use with the unit * @param unit * The unit * @return The time in milliseconds * @throws NumberFormatException * Get thrown if an illegal unit was used */ public static long getMilliSeconds(long amount, String unit) throws NumberFormatException { return getMilliSeconds(amount, Unit.parse(unit)); }