@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(Duration duration)
Creates a TimeValue from a Duration.
|
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() |
Duration |
toDuration()
Converts this instance of to a Duration.
|
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
.T
- The type of TimeValue
.timeValue
- may be null
defaultValue
- may be null
timeValue
or defaultValue
public static TimeValue defaultsToNegativeOneMillisecond(TimeValue timeValue)
timeValue
- may be null
timeValue
or NEG_ONE_SECOND
public static TimeValue defaultsToNegativeOneSecond(TimeValue timeValue)
timeValue
- may be null
timeValue
or NEG_ONE_SECOND
public static TimeValue defaultsToZeroMilliseconds(TimeValue timeValue)
timeValue
- may be null
timeValue
or ZERO_MILLISECONDS
public 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 duration.public static TimeValue of(Duration duration)
duration
- the time duration.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 / divisor
ArithmeticException
- 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 / divisor
ArithmeticException
- if divisor
is zero.public long getDuration()
public TimeUnit getTimeUnit()
public void sleep() throws InterruptedException
InterruptedException
public void timedJoin(Thread thread) throws InterruptedException
InterruptedException
public void timedWait(Object obj) throws InterruptedException
InterruptedException
public long toDays()
public Duration toDuration()
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.