org.apache.hc.core5.util

## Class TimeValue

- java.lang.Object
- - org.apache.hc.core5.util.TimeValue

- All Implemented Interfaces:
    Comparable<TimeValue>
  Direct Known Subclasses:
    Timeout

      @Contract(threading=IMMUTABLE)
      public class TimeValue
      extends Object
      implements Comparable<TimeValue>

  Represents a time value as a `long` time and a `TimeUnit`.
  Since:
    5.0

- - ### Field Summary

    Fields
    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`.

  - ### Method Summary

    Methods
    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> T` | `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)` Returns the given `timeValue` if it is not `null`, if `null` then returns `NEG_ONE_SECOND`.
    `static TimeValue` | `defaultsToNegativeOneSecond(TimeValue timeValue)` Returns the given `timeValue` if it is not `null`, if `null` then returns `NEG_ONE_SECOND`.
    `static TimeValue` | `defaultsToZeroMilliseconds(TimeValue timeValue)` Returns the given `timeValue` if it is not `null`, if `null` then returns `ZERO_MILLISECONDS`.
    `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(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()`
    `long` | `toHours()`
    `long` | `toMicroseconds()`
    `long` | `toMilliseconds()`
    `int` | `toMillisecondsIntBound()`
    `long` | `toMinutes()`
    `long` | `toNanoseconds()`
    `long` | `toSeconds()`
    `int` | `toSecondsIntBound()`
    `String` | `toString()`
    `Timeout` | `toTimeout()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MAX_VALUE

          public static final TimeValue MAX_VALUE

      A constant holding the maximum value a `TimeValue` can have: `Long.MAX_VALUE` days.

    - #### NEG_ONE_MILLISECOND

          public static final TimeValue NEG_ONE_MILLISECOND

      A negative one millisecond `TimeValue`.

    - #### NEG_ONE_SECOND

          public static final TimeValue NEG_ONE_SECOND

      A negative one second `TimeValue`.

    - #### ZERO_MILLISECONDS

          public static final TimeValue ZERO_MILLISECONDS

      A zero milliseconds `TimeValue`.

  - ### Method Detail

    - #### asBoundInt

          public 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`.

      For example: `TimeValue.asBoundInt(Long.MAX_VALUE)` returns `Integer.MAX_VALUE`.

      Parameters:
        `value` - a long value to convert
      Returns:
        an int value bound within `Integer.MIN_VALUE` and `Integer.MAX_VALUE`.

    - #### defaultsTo

          public static <T extends TimeValue> T defaultsTo(T timeValue,
                                           T defaultValue)

      Returns the given `timeValue` if it is not `null`, if `null` then returns the given `defaultValue`.
      Parameters:
        `timeValue` - may be `null`
        `defaultValue` - may be `null`
      Returns:
        `timeValue` or `defaultValue`

    - #### defaultsToNegativeOneMillisecond

          public static TimeValue defaultsToNegativeOneMillisecond(TimeValue timeValue)

      Returns the given `timeValue` if it is not `null`, if `null` then returns `NEG_ONE_SECOND`.
      Parameters:
        `timeValue` - may be `null`
      Returns:
        `timeValue` or `NEG_ONE_SECOND`

    - #### defaultsToNegativeOneSecond

          public static TimeValue defaultsToNegativeOneSecond(TimeValue timeValue)

      Returns the given `timeValue` if it is not `null`, if `null` then returns `NEG_ONE_SECOND`.
      Parameters:
        `timeValue` - may be `null`
      Returns:
        `timeValue` or `NEG_ONE_SECOND`

    - #### defaultsToZeroMilliseconds

          public static TimeValue defaultsToZeroMilliseconds(TimeValue timeValue)

      Returns the given `timeValue` if it is not `null`, if `null` then returns `ZERO_MILLISECONDS`.
      Parameters:
        `timeValue` - may be `null`
      Returns:
        `timeValue` or `ZERO_MILLISECONDS`

    - #### isNonNegative

          public static boolean isNonNegative(TimeValue timeValue)

    - #### isPositive

          public static boolean isPositive(TimeValue timeValue)

    - #### of

          public static TimeValue of(long duration,
                     TimeUnit timeUnit)

      Creates a TimeValue.
      Parameters:
        `duration` - the time duration in the given `timeUnit`.
        `timeUnit` - the time unit for the given duration.
      Returns:
        a Timeout

    - #### ofDays

          public static TimeValue ofDays(long days)

    - #### ofHours

          public static TimeValue ofHours(long hours)

    - #### ofMicroseconds

          public static TimeValue ofMicroseconds(long microseconds)

    - #### ofMilliseconds

          public static TimeValue ofMilliseconds(long millis)

    - #### ofMinutes

          public static TimeValue ofMinutes(long minutes)

    - #### ofNanoseconds

          public static TimeValue ofNanoseconds(long nanoseconds)

    - #### ofSeconds

          public static TimeValue ofSeconds(long seconds)

    - #### parse

          public static TimeValue parse(String value)
                                 throws ParseException

      Parses a TimeValue in the format `<Long><SPACE><TimeUnit>`, for example `"1200 MILLISECONDS"`.

      Parses:

      - `"1200 MILLISECONDS"`.
      - `" 1200 MILLISECONDS "`, spaces are ignored.
      - `"1 MINUTE"`, singular units.
      Parameters:
        `value` - the TimeValue to parse
      Returns:
        a new TimeValue
      Throws:
        `ParseException` - if the number cannot be parsed

    - #### convert

          public long convert(TimeUnit targetTimeUnit)

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### divide

          public TimeValue divide(long divisor)

      Returns a TimeValue whose value is `(this / divisor)`.
      Parameters:
        `divisor` - value by which this TimeValue is to be divided.
      Returns:
        `this / divisor`
      Throws:
        `ArithmeticException` - if `divisor` is zero.

    - #### divide

          public TimeValue divide(long divisor,
                         TimeUnit targetTimeUnit)

      Returns a TimeValue whose value is `(this / divisor)`.
      Parameters:
        `divisor` - value by which this TimeValue is to be divided.
        `targetTimeUnit` - the target TimeUnit
      Returns:
        `this / divisor`
      Throws:
        `ArithmeticException` - if `divisor` is zero.

    - #### getDuration

          public long getDuration()

    - #### getTimeUnit

          public TimeUnit getTimeUnit()

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### min

          public TimeValue min(TimeValue other)

    - #### sleep

          public void sleep()
                     throws InterruptedException

      Throws:
        `InterruptedException`

    - #### timedJoin

          public void timedJoin(Thread thread)
                         throws InterruptedException

      Throws:
        `InterruptedException`

    - #### timedWait

          public void timedWait(Object obj)
                         throws InterruptedException

      Throws:
        `InterruptedException`

    - #### toDays

          public long toDays()

    - #### toHours

          public long toHours()

    - #### toMicroseconds

          public long toMicroseconds()

    - #### toMilliseconds

          public long toMilliseconds()

    - #### toMillisecondsIntBound

          public int toMillisecondsIntBound()

    - #### toMinutes

          public long toMinutes()

    - #### toNanoseconds

          public long toNanoseconds()

    - #### toSeconds

          public long toSeconds()

    - #### toSecondsIntBound

          public int toSecondsIntBound()

    - #### compareTo

          public int compareTo(TimeValue other)

      Specified by:
        `compareTo` in interface `Comparable<TimeValue>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toTimeout

          public Timeout toTimeout()

Copyright © 2005–2022 The Apache Software Foundation. All rights reserved.