Class TimeDuration

java.lang.Object
oracle.dbtools.plugin.api.conf.TimeDuration
All Implemented Interfaces:
Comparable<TimeDuration>, TemporalAmount

public class TimeDuration extends Object implements Comparable<TimeDuration>, 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 Details

    • TimeDuration

      public TimeDuration(long duration, TimeUnit unit)
      Instantiate TimeDuration instance
      Parameters:
      duration - The amount of the duration
      unit - The TimeUnit
  • Method Details

    • compareTo

      public int compareTo(TimeDuration o)
      Specified by:
      compareTo in interface Comparable<TimeDuration>
    • convertTo

      public long convertTo(TimeUnit timeUnit)
      Convert this TimeDuration into the specified TimeUnit duration
      Parameters:
      timeUnit - The TimeUnit 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(Object obj)
      Overrides:
      equals in class 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(Instant start, Instant end)
      Test if this duration has been exceeded
      Parameters:
      start - The starting Instant
      end - The ending Instant
      Returns:
      true if the elapsed time is greater than this duration
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toMillis

      public long toMillis()
      Convert this duration to milliseconds
      Returns:
      long value representing the duration in milliseconds
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • unit

      public TimeUnit unit()
      Return the TimeUnit of this duration
      Returns:
      TimeUnit value
    • disabled

      public static TimeDuration disabled()
      Obtain a TimeDuration 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(String text)
      Parse a textual representation of a 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.

      Parameters:
      text - The textual representation to parse
      Returns:
      The equivalent TimeDuration value
    • get

      public long get(TemporalUnit unit)
      Specified by:
      get in interface TemporalAmount
    • getUnits

      public List<TemporalUnit> getUnits()
      Specified by:
      getUnits in interface TemporalAmount
    • addTo

      public Temporal addTo(Temporal temporal)
      Specified by:
      addTo in interface TemporalAmount
    • subtractFrom

      public Temporal subtractFrom(Temporal temporal)
      Specified by:
      subtractFrom in interface TemporalAmount