public final class DurationUtils
extends Object
Duration.| Modifier and Type | Method and Description |
|---|---|
static Duration |
ensureNonNegative(Duration duration,
String name)
Ensures the duration is non-negative.
|
static Duration |
ensurePositive(Duration duration,
String name)
Ensures the duration is positive, excluding zero.
|
static boolean |
isInfinite(Duration duration,
Duration maxDuration)
Checks if the duration is considered "infinite".
|
static boolean |
isPositive(Duration duration)
Checks if the duration is positive, excluding zero.
|
static long |
toNanos(Duration duration)
Converts a
Duration to nanoseconds or if the resulting value would overflow a 64-bit signed integer then
either Long.MIN_VALUE or Long.MAX_VALUE as appropriate. |
public static boolean isPositive(Duration duration)
duration - the Duration to validatetrue if the passed duration is greater than Duration.ZERO, false otherwisepublic static Duration ensurePositive(Duration duration,
String name)
duration - the Duration to validatename - name of the Duration variableNullPointerException - if the passed duration is nullIllegalArgumentException - if the passed duration is not greater than Duration.ZEROpublic static Duration ensureNonNegative(Duration duration,
String name)
duration - the Duration to validatename - name of the Duration variableNullPointerException - if the passed duration is nullIllegalArgumentException - if the passed duration is not greater or equal to Duration.ZEROpublic static boolean isInfinite(@Nullable
Duration duration,
Duration maxDuration)
duration - the Duration to validatemaxDuration - the max Duration limittrue if the passed duration is null or exceeds the maxDuration, false
otherwisepublic static long toNanos(Duration duration)
Duration to nanoseconds or if the resulting value would overflow a 64-bit signed integer then
either Long.MIN_VALUE or Long.MAX_VALUE as appropriate.duration - the duration to convert