public final class TimeDuration extends Object implements Comparable<TimeDuration>
TimeUnit.
This is a value-based class.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
TimeDuration.Abbreviation
Abbreviations of
TimeUnit. |
| 限定符和类型 | 字段和说明 |
|---|---|
static TimeDuration |
ONE_DAY |
static TimeDuration |
ONE_MILLISECOND |
static TimeDuration |
ONE_MINUTE |
static TimeDuration |
ONE_SECOND |
static TimeDuration |
ZERO |
| 限定符和类型 | 方法和说明 |
|---|---|
TimeDuration |
add(long thatDuration,
TimeUnit thatUnit) |
TimeDuration |
add(TimeDuration that) |
<OUTPUT,THROWABLE extends Throwable> |
apply(CheckedBiFunction<Long,TimeUnit,OUTPUT,THROWABLE> function)
Apply the given function to the (duration, unit) of this object.
|
TimeDuration |
apply(LongUnaryOperator operator)
Apply the given operator to the duration value of this object.
|
int |
compareTo(TimeDuration that) |
boolean |
equals(Object obj) |
long |
getDuration() |
TimeUnit |
getUnit() |
int |
hashCode() |
static TimeUnit |
higherUnit(TimeUnit unit) |
boolean |
isNegative() |
boolean |
isNonPositive() |
static TimeUnit |
lowerUnit(TimeUnit unit) |
TimeDuration |
multiply(double multiplier) |
TimeDuration |
negate() |
static long |
parse(String timeString,
TimeUnit targetUnit)
The same as valueOf(timeString, targetUnit).toLong(targetUnit).
|
long |
roundUpNanos(long nanos)
Round up to the given nanos to nearest multiple (in nanoseconds) of this
TimeDuration. |
TimeDuration |
sleep()
The same as sleep(null).
|
TimeDuration |
sleep(Consumer<Object> log)
Performs a
TimeUnit.sleep(long) using this TimeDuration. |
TimeDuration |
subtract(TimeDuration that) |
TimeDuration |
to(TimeUnit targetUnit) |
int |
toIntExact(TimeUnit targetUnit)
The same as Math.toIntExact(toLong(targetUnit));
Similar to
toLong(TimeUnit), the returned value may be truncated. |
long |
toLong(TimeUnit targetUnit)
Convert this
TimeDuration to a long in the target unit. |
String |
toString() |
String |
toString(TimeUnit targetUnit,
int decimalPlaces) |
static TimeDuration |
valueOf(long duration,
TimeUnit unit) |
static TimeDuration |
valueOf(String timeString,
TimeUnit defaultUnit)
Parse the given time duration string.
|
public static final TimeDuration ZERO
public static final TimeDuration ONE_MILLISECOND
public static final TimeDuration ONE_SECOND
public static final TimeDuration ONE_MINUTE
public static final TimeDuration ONE_DAY
public static TimeUnit lowerUnit(TimeUnit unit)
TimeUnit. If the unit is already the lowest, return it.public static TimeUnit higherUnit(TimeUnit unit)
TimeUnit. If the unit is already the highest, return it.public static long parse(String timeString, TimeUnit targetUnit)
public static TimeDuration valueOf(String timeString, TimeUnit defaultUnit)
TimeDuration in the target unit.public static TimeDuration valueOf(long duration, TimeUnit unit)
TimeDuration representing the given duration and unit.public long getDuration()
public long toLong(TimeUnit targetUnit)
TimeDuration to a long in the target unit.
Note that the returned value may be truncated or saturated; see TimeUnit.convert(long, TimeUnit).*public int toIntExact(TimeUnit targetUnit)
toLong(TimeUnit), the returned value may be truncated.
However, the returned value is never saturated. The method throws ArithmeticException if it overflows.ArithmeticException - if it overflows.public TimeDuration to(TimeUnit targetUnit)
TimeDuration in the target unit.public TimeDuration add(TimeDuration that)
public TimeDuration add(long thatDuration, TimeUnit thatUnit)
public TimeDuration subtract(TimeDuration that)
public TimeDuration multiply(double multiplier)
public TimeDuration negate()
public long roundUpNanos(long nanos)
TimeDuration.public TimeDuration apply(LongUnaryOperator operator)
public <OUTPUT,THROWABLE extends Throwable> OUTPUT apply(CheckedBiFunction<Long,TimeUnit,OUTPUT,THROWABLE> function) throws THROWABLE extends Throwable
THROWABLE extends Throwablepublic boolean isNegative()
TimeDuration negative?public boolean isNonPositive()
TimeDuration less than or equal to zero?public TimeDuration sleep() throws InterruptedException
public TimeDuration sleep(Consumer<Object> log) throws InterruptedException
TimeUnit.sleep(long) using this TimeDuration.log - If not null, use it to print log messages.TimeDuration.InterruptedExceptionpublic int compareTo(TimeDuration that)
compareTo 在接口中 Comparable<TimeDuration>Copyright © 2017–2023 The Apache Software Foundation. All rights reserved.