protected long convertDurationString(String duration) {
		final Matcher m = DURATION_STRING_PATTERN.matcher(duration);
		if (!m.matches()) {
			throw new IllegalArgumentException("Invalid duration string format");
		}

		final long sourceDuration = Long.parseLong(m.group(1));
		final String sourceUnitString = m.group(2);
		final TimeUnit sourceUnit;
		if ("ns".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.NANOSECONDS;
		}
		else if ("us".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.MICROSECONDS;
		}
		else if ("ms".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.MILLISECONDS;
		}
		else if ("s".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.SECONDS;
		}
		else if ("m".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.MINUTES;
		}
		else if ("h".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.HOURS;
		}
		else if ("d".equalsIgnoreCase(sourceUnitString)) {
			sourceUnit = TimeUnit.DAYS;
		}
		else {
			sourceUnit = TimeUnit.MILLISECONDS;
		}

		return sourceUnit.toNanos(sourceDuration);
	}
protected long convertDurationString ( String duration ) { final Matcher m = DURATION_STRING_PATTERN . matcher ( duration ) ; if ( ! m . matches ( ) ) { throw new IllegalArgumentException ( "Invalid duration string format" ) ; } final long sourceDuration = Long . parseLong ( m . group ( 1 ) ) ; final String sourceUnitString = m . group ( 2 ) ; final TimeUnit sourceUnit ; if ( "ns" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . NANOSECONDS ; } else if ( "us" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . MICROSECONDS ; } else if ( "ms" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . MILLISECONDS ; } else if ( "s" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . SECONDS ; } else if ( "m" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . MINUTES ; } else if ( "h" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . HOURS ; } else if ( "d" . equalsIgnoreCase ( sourceUnitString ) ) { sourceUnit = TimeUnit . DAYS ; } else { sourceUnit = TimeUnit . MILLISECONDS ; } return sourceUnit . toNanos ( sourceDuration ) ; }
Parses and converts to nanoseconds a string representing
a duration, ie: 500ms, 30s, 5m, 1h, etc
@param duration a string representing a duration
@return the duration in nanoseconds