DurationUtils¶
- public class org.apache.commons.lang3.time.DurationUtils[source]¶
Utilities for
Duration.- Since:
3.12.0
Constructors¶
Deprecated. Make private in 4.0. |
- @Deprecated public DurationUtils()[source]¶
Deprecated: TODO Make private in 4.0.
Make private in 4.0.
Methods¶
Accepts the function with the duration as a long milliseconds and int nanoseconds. |
|
Gets a Duration of unit stored in the system property at the given key. |
|
Gets a Duration of milliseconds stored in the system property at the given key. |
|
Deprecated. Gets the nanosecond part of a Duration converted to milliseconds. |
|
Gets the nanosecond part of a Duration converted to milliseconds. |
|
Gets a Duration of seconds stored in the system property at the given key. |
|
Tests whether the given Duration is positive (duration > 0). |
|
Runs the lambda and returns the duration of its execution. |
|
Runs the lambda and returns the duration of its execution. |
|
Computes the Duration between a start instant and now. |
|
Converts an amount and TimeUnit into a Duration. |
|
Converts a Duration to milliseconds bound to an |
|
Converts a Duration to milliseconds bound to a |
|
Returns the given non-null value or |
- @SuppressWarnings({"boxing"}) public static <T extends Throwable> void accept(FailableBiConsumer<Long, Integer, T> consumer, Duration duration) throws T[source]¶
Accepts the function with the duration as a long milliseconds and int nanoseconds.
- Type parameters:
<T> – The function exception.
- Parameters:
consumer – Accepting function.
duration – The duration to pick apart.
- Throws:
T – Thrown as described in the function signature.
- See also:
- public static Duration get(String key, TemporalUnit unit, long def)[source]¶
Gets a Duration of unit stored in the system property at the given key.
- Parameters:
key – The property name.
unit – The unit that the duration is measured in, not null.
def – The default value in the given unit.
- Returns:
A Duration of seconds.
- Since:
3.19.0
- public static Duration getMillis(String key, long def)[source]¶
Gets a Duration of milliseconds stored in the system property at the given key.
- Parameters:
key – The property name.
def – The default value in milliseconds.
- Returns:
A Duration of milliseconds.
- Since:
3.19.0
- @Deprecated public static int getNanosOfMiili(Duration duration)[source]¶
Deprecated: Use
#getNanosOfMilli(Duration).Gets the nanosecond part of a Duration converted to milliseconds.
Handy when calling an API that takes a long of milliseconds and an int of nanoseconds. For example,
Object#wait(long, int)andThread#sleep(long, int).Note that is this different from
Duration#getNano()because a duration are seconds and nanoseconds.- Parameters:
duration – The duration to query.
- Returns:
nanoseconds between 0 and 999,999.
- public static int getNanosOfMilli(Duration duration)[source]¶
Gets the nanosecond part of a Duration converted to milliseconds.
Handy when calling an API that takes a long of milliseconds and an int of nanoseconds. For example,
Object#wait(long, int)andThread#sleep(long, int).Note that is this different from
Duration#getNano()because a duration are seconds and nanoseconds.- Parameters:
duration – The duration to query.
- Returns:
nanoseconds between 0 and 999,999.
- Since:
3.13.0
- public static Duration getSeconds(String key, long def)[source]¶
Gets a Duration of seconds stored in the system property at the given key.
- Parameters:
key – The property name.
def – The default value in seconds.
- Returns:
A Duration of seconds.
- Since:
3.19.0
- public static boolean isPositive(Duration duration)[source]¶
Tests whether the given Duration is positive (duration > 0).
- Parameters:
duration – The value to test
- Returns:
whether the given Duration is positive (duration > 0).
- public static <E extends Throwable> Duration of(FailableConsumer<Instant, E> consumer) throws E[source]¶
Runs the lambda and returns the duration of its execution.
- Type parameters:
<E> – The type of exception throw by the lambda.
- Parameters:
consumer – What to execute.
- Returns:
The Duration of execution.
- Throws:
E – Thrown by the lambda.
- See also:
- Since:
3.13.0
- public static <E extends Throwable> Duration of(FailableRunnable<E> runnable) throws E[source]¶
Runs the lambda and returns the duration of its execution.
- Type parameters:
<E> – The type of exception throw by the lambda.
- Parameters:
runnable – What to execute.
- Returns:
The Duration of execution.
- Throws:
E – Thrown by the lambda.
- See also:
- Since:
3.13.0
- public static Duration since(Temporal startInclusive)[source]¶
Computes the Duration between a start instant and now.
- Parameters:
startInclusive – The start instant, inclusive, not null.
- Returns:
A
Duration, not null.- Since:
3.13.0
- public static Duration toDuration(long amount, TimeUnit timeUnit)[source]¶
Converts an amount and TimeUnit into a Duration.
- Parameters:
amount – The amount of the duration, measured in terms of the unit, positive or negative
timeUnit – The unit that the duration is measured in, must have an exact duration, not null
- Returns:
A Duration.
- public static int toMillisInt(Duration duration)[source]¶
Converts a Duration to milliseconds bound to an
int(instead of along).Handy for low-level APIs that take millisecond timeouts in ints rather than longs.
If the duration milliseconds are greater than
Integer#MAX_VALUE, then returnInteger#MAX_VALUE.If the duration milliseconds are lesser than
Integer#MIN_VALUE, then returnInteger#MIN_VALUE.
- Parameters:
duration – The duration to convert, not null.
- Returns:
int milliseconds.
- See also:
- public static long toMillisLong(Duration duration)[source]¶
Converts a Duration to milliseconds bound to a
longwithout throwingArithmeticException.If the duration milliseconds are greater than
Long#MAX_VALUE, then returnLong#MAX_VALUE.If the duration milliseconds are lesser than
Long#MIN_VALUE, then returnLong#MIN_VALUE.
- Parameters:
duration – The duration to convert, not null.
- Returns:
long milliseconds.
- See also:
- Since:
3.21.0
- public static Duration zeroIfNull(Duration duration)[source]¶
Returns the given non-null value or
Duration#ZEROif null.- Parameters:
duration – The duration to test.
- Returns:
The given duration or
Duration#ZERO.