Package oracle.dbtools.plugin.api.conf
Class TimeDuration
- java.lang.Object
-
- oracle.dbtools.plugin.api.conf.TimeDuration
-
- All Implemented Interfaces:
java.lang.Comparable<TimeDuration>
,java.time.temporal.TemporalAmount
public class TimeDuration extends java.lang.Object implements java.lang.Comparable<TimeDuration>, java.time.temporal.TemporalAmount
Represents a specification of a time duration. The value is represented textually as an integer 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.- Author:
- cdivilly
-
-
Constructor Summary
Constructors Constructor Description TimeDuration(long duration, java.util.concurrent.TimeUnit unit)
InstantiateTimeDuration
instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.time.temporal.Temporal
addTo(java.time.temporal.Temporal temporal)
int
compareTo(TimeDuration o)
long
convertTo(java.util.concurrent.TimeUnit timeUnit)
Convert this TimeDuration into the specifiedTimeUnit
durationstatic TimeDuration
disabled()
Obtain aTimeDuration
instance representing a disabled duration checklong
duration()
Return the raw duration amountboolean
enabled()
Indicate if the duration check is enabled or disabled.boolean
equals(java.lang.Object obj)
boolean
exceeded(long start, long end)
Test if this duration has been exceededboolean
exceeded(java.time.Instant start, java.time.Instant end)
Test if this duration has been exceededlong
get(java.time.temporal.TemporalUnit unit)
java.util.List<java.time.temporal.TemporalUnit>
getUnits()
int
hashCode()
static TimeDuration
parse(java.lang.String text)
Parse a textual representation of aTimeDuration
java.time.temporal.Temporal
subtractFrom(java.time.temporal.Temporal temporal)
long
toMillis()
Convert this duration to millisecondsjava.lang.String
toString()
java.util.concurrent.TimeUnit
unit()
Return theTimeUnit
of this duration
-
-
-
Constructor Detail
-
TimeDuration
public TimeDuration(long duration, java.util.concurrent.TimeUnit unit)
InstantiateTimeDuration
instance- Parameters:
duration
- The amount of the durationunit
- TheTimeUnit
-
-
Method Detail
-
compareTo
public int compareTo(TimeDuration o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<TimeDuration>
-
convertTo
public long convertTo(java.util.concurrent.TimeUnit timeUnit)
Convert this TimeDuration into the specifiedTimeUnit
duration- Parameters:
timeUnit
- TheTimeUnit
to convert this duration to- Returns:
- long value representing the duration in the specified
TimeUnit
-
enabled
public boolean enabled()
Indicate if the duration check is enabled or disabled. If a TimeDuration is initialized with a negative duration value then the duration check is disabled- Returns:
- true if this duration is enabled, false otherwise
- Since:
- 19.3.0
-
duration
public long duration()
Return the raw duration amount- Returns:
- long value indicating the size of the duration
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
exceeded
public boolean exceeded(long start, long end)
Test if this duration has been exceeded- Parameters:
start
- The starting timestamp (in epoch milliseconds)end
- The ending timestamp (in epoch milliseconds)- Returns:
- true if the elapsed time is greater than this duration
-
exceeded
public boolean exceeded(java.time.Instant start, java.time.Instant end)
Test if this duration has been exceeded- Parameters:
start
- The startingInstant
end
- The endingInstant
- Returns:
- true if the elapsed time is greater than this duration
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toMillis
public long toMillis()
Convert this duration to milliseconds- Returns:
- long value representing the duration in milliseconds
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
unit
public java.util.concurrent.TimeUnit unit()
Return theTimeUnit
of this duration- Returns:
TimeUnit
value
-
disabled
public static TimeDuration disabled()
Obtain aTimeDuration
instance representing a disabled duration check- Returns:
TimeDuration
instance with a duration value of -1 and a TimeUnit of SECONDS
-
parse
public static TimeDuration parse(java.lang.String text)
Parse a textual representation of aTimeDuration
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.
- Parameters:
text
- The textual representation to parse- Returns:
- The equivalent
TimeDuration
value
-
get
public long get(java.time.temporal.TemporalUnit unit)
- Specified by:
get
in interfacejava.time.temporal.TemporalAmount
-
getUnits
public java.util.List<java.time.temporal.TemporalUnit> getUnits()
- Specified by:
getUnits
in interfacejava.time.temporal.TemporalAmount
-
addTo
public java.time.temporal.Temporal addTo(java.time.temporal.Temporal temporal)
- Specified by:
addTo
in interfacejava.time.temporal.TemporalAmount
-
subtractFrom
public java.time.temporal.Temporal subtractFrom(java.time.temporal.Temporal temporal)
- Specified by:
subtractFrom
in interfacejava.time.temporal.TemporalAmount
-
-