@Contract(threading=IMMUTABLE) public class TimeValue extends Object implements Comparable<TimeValue>
long time and a TimeUnit.| Modifier and Type | Field and Description |
|---|---|
static TimeValue |
MAX_VALUE
A constant holding the maximum value a
TimeValue can have: Long.MAX_VALUE days. |
static TimeValue |
NEG_ONE_MILLISECOND
A negative one millisecond
TimeValue. |
static TimeValue |
NEG_ONE_SECOND
A negative one second
TimeValue. |
static TimeValue |
ZERO_MILLISECONDS
A zero milliseconds
TimeValue. |
| Modifier and Type | Method and Description |
|---|---|
static int |
asBoundInt(long value)
Returns the given
long value as an int where long values out of int range are returned as
Integer.MIN_VALUE and Integer.MAX_VALUE. |
int |
compareTo(TimeValue other) |
long |
convert(TimeUnit targetTimeUnit) |
static <T extends TimeValue> |
defaultsTo(T timeValue,
T defaultValue)
Returns the given
timeValue if it is not null, if null then returns the given
defaultValue. |
static TimeValue |
defaultsToNegativeOneMillisecond(TimeValue timeValue)
|
static TimeValue |
defaultsToNegativeOneSecond(TimeValue timeValue)
|
static TimeValue |
defaultsToZeroMilliseconds(TimeValue timeValue)
|
TimeValue |
divide(long divisor)
Returns a TimeValue whose value is
(this / divisor). |
TimeValue |
divide(long divisor,
TimeUnit targetTimeUnit)
Returns a TimeValue whose value is
(this / divisor). |
boolean |
equals(Object obj) |
long |
getDuration() |
TimeUnit |
getTimeUnit() |
int |
hashCode() |
static boolean |
isNonNegative(TimeValue timeValue) |
static boolean |
isPositive(TimeValue timeValue) |
TimeValue |
min(TimeValue other) |
static TimeValue |
of(long duration,
TimeUnit timeUnit)
Creates a TimeValue.
|
static TimeValue |
ofDays(long days) |
static TimeValue |
ofHours(long hours) |
static TimeValue |
ofMicroseconds(long microseconds) |
static TimeValue |
ofMilliseconds(long millis) |
static TimeValue |
ofMinutes(long minutes) |
static TimeValue |
ofNanoseconds(long nanoseconds) |
static TimeValue |
ofSeconds(long seconds) |
static TimeValue |
parse(String value)
Parses a TimeValue in the format
<Long><SPACE><TimeUnit>, for example "1200 MILLISECONDS". |
void |
sleep() |
void |
timedJoin(Thread thread) |
void |
timedWait(Object obj) |
long |
toDays() |
long |
toHours() |
long |
toMicroseconds() |
long |
toMilliseconds() |
int |
toMillisecondsIntBound() |
long |
toMinutes() |
long |
toNanoseconds() |
long |
toSeconds() |
int |
toSecondsIntBound() |
String |
toString() |
Timeout |
toTimeout() |
public static final TimeValue MAX_VALUE
TimeValue can have: Long.MAX_VALUE days.public static final TimeValue NEG_ONE_MILLISECOND
TimeValue.public static int asBoundInt(long value)
long value as an int where long values out of int range are returned as
Integer.MIN_VALUE and Integer.MAX_VALUE.
For example: TimeValue.asBoundInt(Long.MAX_VALUE) returns Integer.MAX_VALUE.
value - a long value to convertInteger.MIN_VALUE and Integer.MAX_VALUE.public static <T extends TimeValue> T defaultsTo(T timeValue, T defaultValue)
timeValue if it is not null, if null then returns the given
defaultValue.timeValue - may be nulldefaultValue - may be nulltimeValue or defaultValuepublic static TimeValue defaultsToNegativeOneMillisecond(TimeValue timeValue)
timeValue - may be nulltimeValue or NEG_ONE_SECONDpublic static TimeValue defaultsToNegativeOneSecond(TimeValue timeValue)
timeValue - may be nulltimeValue or NEG_ONE_SECONDpublic static TimeValue defaultsToZeroMilliseconds(TimeValue timeValue)
timeValue - may be nulltimeValue or ZERO_MILLISECONDSpublic static boolean isNonNegative(TimeValue timeValue)
public static boolean isPositive(TimeValue timeValue)
public static TimeValue of(long duration, TimeUnit timeUnit)
duration - the time duration in the given timeUnit.timeUnit - the time unit for the given durarion.public static TimeValue ofDays(long days)
public static TimeValue ofHours(long hours)
public static TimeValue ofMicroseconds(long microseconds)
public static TimeValue ofMilliseconds(long millis)
public static TimeValue ofMinutes(long minutes)
public static TimeValue ofNanoseconds(long nanoseconds)
public static TimeValue ofSeconds(long seconds)
public static TimeValue parse(String value) throws ParseException
<Long><SPACE><TimeUnit>, for example "1200 MILLISECONDS".
Parses:
"1200 MILLISECONDS"." 1200 MILLISECONDS ", spaces are ignored."1 MINUTE", singular units.value - the TimeValue to parseParseException - if the number cannot be parsedpublic long convert(TimeUnit targetTimeUnit)
public TimeValue divide(long divisor)
(this / divisor).divisor - value by which this TimeValue is to be divided.this / divisorArithmeticException - if divisor is zero.public TimeValue divide(long divisor, TimeUnit targetTimeUnit)
(this / divisor).divisor - value by which this TimeValue is to be divided.targetTimeUnit - the target TimeUnitthis / divisorArithmeticException - if divisor is zero.public long getDuration()
public TimeUnit getTimeUnit()
public void sleep()
throws InterruptedException
InterruptedExceptionpublic void timedJoin(Thread thread) throws InterruptedException
InterruptedExceptionpublic void timedWait(Object obj) throws InterruptedException
InterruptedExceptionpublic long toDays()
public long toHours()
public long toMicroseconds()
public long toMilliseconds()
public int toMillisecondsIntBound()
public long toMinutes()
public long toNanoseconds()
public long toSeconds()
public int toSecondsIntBound()
public int compareTo(TimeValue other)
compareTo in interface Comparable<TimeValue>public Timeout toTimeout()
Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.