Package io.servicetalk.utils.internal
Class DurationUtils
- java.lang.Object
-
- io.servicetalk.utils.internal.DurationUtils
-
public final class DurationUtils extends java.lang.ObjectHelper utilities forDuration.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.time.DurationensurePositive(java.time.Duration duration, java.lang.String name)Ensures the duration is positive, excluding zero.static booleanisInfinite(java.time.Duration duration, java.time.Duration maxDuration)Checks if the duration is considered "infinite".static booleanisPositive(java.time.Duration duration)Checks if the duration is positive, excluding zero.static longtoNanos(java.time.Duration duration)Converts aDurationto nanoseconds or if the resulting value would overflow a 64-bit signed integer then eitherLong.MIN_VALUEorLong.MAX_VALUEas appropriate.
-
-
-
Method Detail
-
isPositive
public static boolean isPositive(java.time.Duration duration)
Checks if the duration is positive, excluding zero.- Parameters:
duration- theDurationto validate- Returns:
trueif the passed duration is greater thanDuration.ZERO,falseotherwise
-
ensurePositive
public static java.time.Duration ensurePositive(java.time.Duration duration, java.lang.String name)Ensures the duration is positive, excluding zero.- Parameters:
duration- theDurationto validatename- name of theDurationvariable- Returns:
- the passed duration if all checks pass
- Throws:
java.lang.NullPointerException- if the passed duration isnulljava.lang.IllegalArgumentException- if the passed duration is not greater thanDuration.ZERO
-
isInfinite
public static boolean isInfinite(@Nullable java.time.Duration duration, java.time.Duration maxDuration)Checks if the duration is considered "infinite".- Parameters:
duration- theDurationto validatemaxDuration- the maxDurationlimit- Returns:
trueif the passed duration isnullor exceeds themaxDuration,falseotherwise
-
toNanos
public static long toNanos(java.time.Duration duration)
Converts aDurationto nanoseconds or if the resulting value would overflow a 64-bit signed integer then eitherLong.MIN_VALUEorLong.MAX_VALUEas appropriate.- Parameters:
duration- the duration to convert- Returns:
- the converted nanoseconds value
-
-