public class TimeDuration extends Time
| Modifier and Type | Class and Description |
|---|---|
static interface |
TimeDuration.Check
Interface defining a check to be performed.
|
| Modifier and Type | Field and Description |
|---|---|
static TimeDuration |
INFINITY
Time duration instance representing the infinity.
|
static TimeDuration |
ZERO
Time duration instance representing the zero.
|
HOURS_IN_DAY, MINUTES_IN_DAY, MINUTES_IN_HOUR, SECONDS_IN_DAY, SECONDS_IN_HOUR, SECONDS_IN_MINUTE, time, unit| Modifier and Type | Method and Description |
|---|---|
static TimeDuration |
days(long days)
Creates and returns an object representing the specified number of days.
|
TimeDuration |
daysTime()
Converts this duration in days.
|
static TimeDuration |
fromUnit(long time,
TimeUnit unit)
Creates and returns an object representing the specified time value in the specified time
unit.
|
static TimeDuration |
hours(long hours)
Creates and returns an object representing the specified number of hours.
|
TimeDuration |
hoursTime()
Converts this duration in hours.
|
boolean |
isInfinity()
Checks if this duration represents the infinity.
|
void |
join(Thread target)
Performs a
Thread.join() using this duration as timeout. |
static TimeDuration |
micros(long micros)
Creates and returns an object representing the specified number of microseconds.
|
TimeDuration |
microsTime()
Converts this duration in microseconds.
|
static TimeDuration |
millis(long millis)
Creates and returns an object representing the specified number of milliseconds.
|
TimeDuration |
millisTime()
Converts this duration in milliseconds.
|
TimeDuration |
minus(Time time)
Returns a new instance whose time value is decremented by the specified one.
Note that the unit of the returned time will match the one with the highest precision. Note also that, if the resulting time is negative, the value will be clipped to 0. |
static TimeDuration |
minutes(long minutes)
Creates and returns an object representing the specified number of minutes.
|
TimeDuration |
minutesTime()
Converts this duration in minutes.
|
static TimeDuration |
nanos(long nanos)
Creates and returns an object representing the specified number of nanoseconds.
|
TimeDuration |
nanosTime()
Converts this duration in nanoseconds.
|
TimeDuration |
plus(Time time)
Returns a new instance whose time value is incremented by the specified one.
Note that the unit of the returned time will match the one with the highest precision. Note also that, if the resulting time is negative, the value will be clipped to 0. |
static TimeDuration |
seconds(long seconds)
Creates and returns an object representing the specified number of seconds.
|
TimeDuration |
secondsTime()
Converts this duration in seconds.
|
void |
sleep()
Performs a
Thread.sleep(long, int) using this duration as timeout. |
void |
sleepAtLeast()
Performs a
Thread.sleep(long, int) using this duration as timeout, ensuring
that the sleep time is respected even if spurious wake ups happen in the while. |
boolean |
sleepSinceMillis(long milliTime)
Performs a
Thread.sleep(long, int) as if started from the specified system
time in milliseconds, by using this duration as timeout. |
boolean |
sleepSinceNanos(long nanoTime)
Performs a
Thread.sleep(long, int) as if started from the specified high
precision system time in nanoseconds, by using this duration as timeout. |
static TimeDuration |
timeSinceMillis(long milliTime)
Creates and returns an object representing the time range between now and a time in the past.
|
static TimeDuration |
timeSinceNanos(long nanoTime)
Creates and returns an object representing the time range between now and a time in the past.
|
static TimeDuration |
timeUntilMillis(long milliTime)
Creates and returns an object representing the time range between now and a time in the
future.
If the specified is in the past, a ZERO duration will be returned. |
static TimeDuration |
timeUntilNanos(long nanoTime)
Creates and returns an object representing the time range between now and a time in the
future.
If the specified is in the past, a ZERO duration will be returned. |
void |
wait(Object target)
Performs an
Object.wait() using this duration as timeout. |
boolean |
waitSinceMillis(Object target,
long milliTime)
Performs an
Object.wait() as if started from the specified system time in
milliseconds, by using this duration as timeout. |
boolean |
waitSinceNanos(Object target,
long nanoTime)
Performs an
Object.wait() as if started from the specified high precision
system time in nanoseconds, by using this duration as timeout. |
boolean |
waitTrue(Object target,
TimeDuration.Check check)
Waits for the specified check to be true by performing an
Object.wait() and
using this duration as timeout. |
public static final TimeDuration INFINITY
public static final TimeDuration ZERO
@NotNull public static TimeDuration days(long days)
days - the number of days.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration fromUnit(long time, @NotNull TimeUnit unit)
time - the time value.unit - the time unit.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration hours(long hours)
hours - the number of hoursIllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration micros(long micros)
micros - the number of microseconds.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration millis(long millis)
millis - the number of milliseconds.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration minutes(long minutes)
minutes - the number of minutes.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration nanos(long nanos)
nanos - the number of nanoseconds.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration seconds(long seconds)
seconds - the number of seconds.IllegalArgumentException - if the specified duration is negative.@NotNull public static TimeDuration timeSinceMillis(long milliTime)
ZERO duration will be returned.milliTime - the system time in milliseconds.System.currentTimeMillis()@NotNull public static TimeDuration timeSinceNanos(long nanoTime)
ZERO duration will be returned.nanoTime - the high precision system time in nanoseconds.System.nanoTime()@NotNull public static TimeDuration timeUntilMillis(long milliTime)
ZERO duration will be returned.milliTime - the system time in milliseconds.System.currentTimeMillis()@NotNull public static TimeDuration timeUntilNanos(long nanoTime)
ZERO duration will be returned.nanoTime - the high precision system time in nanoseconds.System.nanoTime()@NotNull public TimeDuration daysTime()
@NotNull public TimeDuration hoursTime()
@NotNull public TimeDuration microsTime()
microsTime in class Time@NotNull public TimeDuration millisTime()
millisTime in class Time@NotNull public TimeDuration minus(@NotNull Time time)
@NotNull public TimeDuration minutesTime()
minutesTime in class Time@NotNull public TimeDuration nanosTime()
@NotNull public TimeDuration plus(@NotNull Time time)
@NotNull public TimeDuration secondsTime()
secondsTime in class Timepublic boolean isInfinity()
public void join(@NotNull
Thread target)
throws InterruptedException
Thread.join() using this duration as timeout.target - the target thread.InterruptedException - if the current thread is interrupted.public void sleep()
throws InterruptedException
Thread.sleep(long, int) using this duration as timeout.InterruptedException - if the current thread is interrupted.public void sleepAtLeast()
throws InterruptedException
Thread.sleep(long, int) using this duration as timeout, ensuring
that the sleep time is respected even if spurious wake ups happen in the while.InterruptedException - if the current thread is interrupted.public boolean sleepSinceMillis(long milliTime)
throws InterruptedException
Thread.sleep(long, int) as if started from the specified system
time in milliseconds, by using this duration as timeout.milliTime - the starting system time in milliseconds.IllegalStateException - if this duration overflows the maximum sleep time.InterruptedException - if the current thread is interrupted.System.currentTimeMillis()public boolean sleepSinceNanos(long nanoTime)
throws InterruptedException
Thread.sleep(long, int) as if started from the specified high
precision system time in nanoseconds, by using this duration as timeout.nanoTime - the starting system time in nanoseconds.IllegalStateException - if this duration overflows the maximum sleep time.InterruptedException - if the current thread is interrupted.System.nanoTime()public void wait(@NotNull
Object target)
throws InterruptedException
Object.wait() using this duration as timeout.target - the target object.InterruptedException - if the current thread is interrupted.public boolean waitSinceMillis(@NotNull
Object target,
long milliTime)
throws InterruptedException
Object.wait() as if started from the specified system time in
milliseconds, by using this duration as timeout.target - the target object.milliTime - the starting system time in milliseconds.InterruptedException - if the current thread is interrupted.System.currentTimeMillis()public boolean waitSinceNanos(@NotNull
Object target,
long nanoTime)
throws InterruptedException
Object.wait() as if started from the specified high precision
system time in nanoseconds, by using this duration as timeout.target - the target object.nanoTime - the starting system time in nanoseconds.InterruptedException - if the current thread is interrupted.System.nanoTime()public boolean waitTrue(@NotNull
Object target,
@NotNull
TimeDuration.Check check)
throws InterruptedException
Object.wait() and
using this duration as timeout.target - the target object.check - the check to verify.InterruptedException - if the current thread is interrupted.