Package io.servicetalk.utils.internal
Class DurationUtils
- java.lang.Object
-
- io.servicetalk.utils.internal.DurationUtils
-
public final class DurationUtils extends java.lang.Object
Helper utilities forDuration
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.time.Duration
ensurePositive(java.time.Duration duration, java.lang.String name)
Ensures the duration is positive, excluding zero.static boolean
isInfinite(java.time.Duration duration, java.time.Duration maxDuration)
Checks if the duration is considered "infinite".static boolean
isPositive(java.time.Duration duration)
Checks if the duration is positive, excluding zero.static long
toNanos(java.time.Duration duration)
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 Detail
-
isPositive
public static boolean isPositive(java.time.Duration duration)
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
public static java.time.Duration ensurePositive(java.time.Duration duration, java.lang.String name)
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:
java.lang.NullPointerException
- if the passed duration isnull
java.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
- theDuration
to validatemaxDuration
- the maxDuration
limit- Returns:
true
if the passed duration isnull
or exceeds themaxDuration
,false
otherwise
-
toNanos
public static long toNanos(java.time.Duration duration)
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
-
-