Package io.servicetalk.utils.internal
Class DurationUtils
java.lang.Object
io.servicetalk.utils.internal.DurationUtils
Helper utilities for
Duration
.-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
Converts aDuration
to nanoseconds or if the resulting value would overflow a 64-bit signed integer then eitherLong.MIN_VALUE
orLong.MAX_VALUE
as appropriate.
-
Method Details
-
isPositive
Checks if the duration is positive, excluding zero.- Parameters:
duration
- theDuration
to validate- Returns:
true
if the passed duration is greater thanDuration.ZERO
,false
otherwise
-
ensurePositive
Ensures the duration is positive, excluding zero.- Parameters:
duration
- theDuration
to validatename
- name of theDuration
variable- Returns:
- the passed duration if all checks pass
- Throws:
NullPointerException
- if the passed duration isnull
IllegalArgumentException
- if the passed duration is not greater thanDuration.ZERO
-
ensureNonNegative
Ensures the duration is non-negative.- Parameters:
duration
- theDuration
to validatename
- name of theDuration
variable- Returns:
- the passed duration if all checks pass
- Throws:
NullPointerException
- if the passed duration isnull
IllegalArgumentException
- if the passed duration is not greater or equal toDuration.ZERO
-
isInfinite
Checks if the duration is considered "infinite". -
toNanos
Converts aDuration
to nanoseconds or if the resulting value would overflow a 64-bit signed integer then eitherLong.MIN_VALUE
orLong.MAX_VALUE
as appropriate.- Parameters:
duration
- the duration to convert- Returns:
- the converted nanoseconds value
-