public class TimeDuration extends Object implements Comparable<TimeDuration>
Constructor and Description |
---|
TimeDuration(long duration, TimeUnit unit)
Instantiate
TimeDuration instance |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(TimeDuration o) |
long |
convertTo(TimeUnit timeUnit)
Convert this TimeDuration into the specified
TimeUnit duration |
static TimeDuration |
disabled()
Obtain a
TimeDuration instance representing a disabled duration check |
long |
duration()
Return the raw duration amount
|
boolean |
enabled()
Indicate if the duration check is enabled or disabled.
|
boolean |
equals(Object obj) |
boolean |
exceeded(Instant start, Instant end)
Test if this duration has been exceeded
|
boolean |
exceeded(long start, long end)
Test if this duration has been exceeded
|
int |
hashCode() |
static TimeDuration |
parse(String text)
Parse a textual representation of a
TimeDuration |
long |
toMillis()
Convert this duration to milliseconds
|
String |
toString() |
TimeUnit |
unit()
Return the
TimeUnit of this duration |
public TimeDuration(long duration, TimeUnit unit)
TimeDuration
instanceduration
- The amount of the durationunit
- The TimeUnit
public int compareTo(TimeDuration o)
compareTo
in interface Comparable<TimeDuration>
public long convertTo(TimeUnit timeUnit)
TimeUnit
durationpublic boolean enabled()
public long duration()
public boolean exceeded(long start, long end)
start
- The starting timestamp (in epoch milliseconds)end
- The ending timestamp (in epoch milliseconds)public boolean exceeded(Instant start, Instant end)
public long toMillis()
public static TimeDuration disabled()
TimeDuration
instance representing a disabled duration checkTimeDuration
instance with a duration value of -1 and a TimeUnit of SECONDSpublic static TimeDuration parse(String text)
TimeDuration
The value is represented textually as an integer followed by one of: followed by one of "d", "h", "m", or "s", representing days, hours, minutes, or seconds respectively. Milliseconds, microseconds and nanoseconds are represented by "ms","us" and "ns" respectively.
If no unit is specified then the default unit of seconds is used.
text
- The textual representation to parseTimeDuration
value