@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "duration is null") public void testValueOfRejectsNull() { Duration.valueOf(null); }
@JsonCreator public static Duration valueOf(String duration) throws IllegalArgumentException { requireNonNull(duration, "duration is null"); Preconditions.checkArgument(!duration.isEmpty(), "duration is empty"); Matcher matcher = PATTERN.matcher(duration); if (!matcher.matches()) { throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); } double value = Double.parseDouble(matcher.group(1)); String unitString = matcher.group(2); TimeUnit timeUnit = valueOfTimeUnit(unitString); return new Duration(value, timeUnit); }
Duration implements Comparable<Duration> { @JsonCreator public static Duration valueOf(String duration) throws IllegalArgumentException { requireNonNull(duration, "duration is null"); Preconditions.checkArgument(!duration.isEmpty(), "duration is empty"); Matcher matcher = PATTERN.matcher(duration); if (!matcher.matches()) { throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); } double value = Double.parseDouble(matcher.group(1)); String unitString = matcher.group(2); TimeUnit timeUnit = valueOfTimeUnit(unitString); return new Duration(value, timeUnit); } }
Duration implements Comparable<Duration> { @JsonCreator public static Duration valueOf(String duration) throws IllegalArgumentException { requireNonNull(duration, "duration is null"); Preconditions.checkArgument(!duration.isEmpty(), "duration is empty"); Matcher matcher = PATTERN.matcher(duration); if (!matcher.matches()) { throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); } double value = Double.parseDouble(matcher.group(1)); String unitString = matcher.group(2); TimeUnit timeUnit = valueOfTimeUnit(unitString); return new Duration(value, timeUnit); } Duration(double value, TimeUnit unit); }
Duration implements Comparable<Duration> { @JsonCreator public static Duration valueOf(String duration) throws IllegalArgumentException { requireNonNull(duration, "duration is null"); Preconditions.checkArgument(!duration.isEmpty(), "duration is empty"); Matcher matcher = PATTERN.matcher(duration); if (!matcher.matches()) { throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); } double value = Double.parseDouble(matcher.group(1)); String unitString = matcher.group(2); TimeUnit timeUnit = valueOfTimeUnit(unitString); return new Duration(value, timeUnit); } Duration(double value, TimeUnit unit); static Duration nanosSince(long start); static Duration succinctNanos(long nanos); static Duration succinctDuration(double value, TimeUnit unit); long toMillis(); double getValue(); TimeUnit getUnit(); double getValue(TimeUnit timeUnit); long roundTo(TimeUnit timeUnit); Duration convertToMostSuccinctTimeUnit(); @JsonValue @Override String toString(); String toString(TimeUnit timeUnit); @JsonCreator static Duration valueOf(String duration); @Override int compareTo(Duration o); @Override boolean equals(Object o); @Override int hashCode(); static TimeUnit valueOfTimeUnit(String timeUnitString); static String timeUnitToString(TimeUnit timeUnit); }
Duration implements Comparable<Duration> { @JsonCreator public static Duration valueOf(String duration) throws IllegalArgumentException { requireNonNull(duration, "duration is null"); Preconditions.checkArgument(!duration.isEmpty(), "duration is empty"); Matcher matcher = PATTERN.matcher(duration); if (!matcher.matches()) { throw new IllegalArgumentException("duration is not a valid data duration string: " + duration); } double value = Double.parseDouble(matcher.group(1)); String unitString = matcher.group(2); TimeUnit timeUnit = valueOfTimeUnit(unitString); return new Duration(value, timeUnit); } Duration(double value, TimeUnit unit); static Duration nanosSince(long start); static Duration succinctNanos(long nanos); static Duration succinctDuration(double value, TimeUnit unit); long toMillis(); double getValue(); TimeUnit getUnit(); double getValue(TimeUnit timeUnit); long roundTo(TimeUnit timeUnit); Duration convertToMostSuccinctTimeUnit(); @JsonValue @Override String toString(); String toString(TimeUnit timeUnit); @JsonCreator static Duration valueOf(String duration); @Override int compareTo(Duration o); @Override boolean equals(Object o); @Override int hashCode(); static TimeUnit valueOfTimeUnit(String timeUnitString); static String timeUnitToString(TimeUnit timeUnit);  }