Package io.servicetalk.utils.internal
Class DurationUtils
java.lang.Object
io.servicetalk.utils.internal.DurationUtils
Helper utilities for
Duration.-
Method Summary
Modifier and TypeMethodDescriptionstatic DurationensureNonNegative(Duration duration, String name) Ensures the duration is non-negative.static DurationensurePositive(Duration duration, String name) Ensures the duration is positive, excluding zero.static booleanisInfinite(Duration duration, Duration maxDuration) Checks if the duration is considered "infinite".static booleanisPositive(Duration duration) Checks if the duration is positive, excluding zero.static longConverts aDurationto nanoseconds or if the resulting value would overflow a 64-bit signed integer then eitherLong.MIN_VALUEorLong.MAX_VALUEas appropriate.
-
Method Details
-
isPositive
Checks if the duration is positive, excluding zero.- Parameters:
duration- theDurationto validate- Returns:
trueif the passed duration is greater thanDuration.ZERO,falseotherwise
-
ensurePositive
Ensures the duration is positive, excluding zero.- Parameters:
duration- theDurationto validatename- name of theDurationvariable- Returns:
- the passed duration if all checks pass
- Throws:
NullPointerException- if the passed duration isnullIllegalArgumentException- if the passed duration is not greater thanDuration.ZERO
-
ensureNonNegative
Ensures the duration is non-negative.- Parameters:
duration- theDurationto validatename- name of theDurationvariable- Returns:
- the passed duration if all checks pass
- Throws:
NullPointerException- if the passed duration isnullIllegalArgumentException- if the passed duration is not greater or equal toDuration.ZERO
-
isInfinite
Checks if the duration is considered "infinite". -
toNanos
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
-