Top Description Fields Constructors Methods
org.apache.hc.core5.util

public Class TimeValue

extends Object
implements Comparable<TimeValue>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Known Direct Subclasses
org.apache.hc.core5.util.Timeout
Annotations
@Contract
threading:IMMUTABLE
Imports
java.text.ParseException, java.time.Duration, java.time.temporal.ChronoUnit, java.util.Locale, .Objects, java.util.concurrent.TimeUnit, org.apache.hc.core5.annotation.Contract, .ThreadingBehavior

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

Field Summary

Modifier and TypeField and Description
private final long
pack-priv static final int
public static final TimeValue
MAX_VALUE

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

public static final TimeValue
NEG_ONE_MILLISECOND

A negative one millisecond TimeValue.

public static final TimeValue
NEG_ONE_SECOND

A negative one second TimeValue.

private final TimeUnit
public static final TimeValue
ZERO_MILLISECONDS

A zero milliseconds TimeValue.

Constructor Summary

AccessConstructor and Description
pack-priv
TimeValue(final long duration, final TimeUnit timeUnit)

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

an int value bound within Integer#MIN_VALUE and Integer#MAX_VALUE.
asBoundInt
(final long
a long value to convert
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.

public int
compareTo(final TimeValue
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public long
convert(final TimeUnit targetTimeUnit)

public static <T extends TimeValue> T

Returns:

timeValue or defaultValue
defaultsTo
(final T
may be null
timeValue
,
final T
may be null
defaultValue
)

Returns the given timeValue if it is not null, if null then returns the given defaultValue.

public static TimeValue

Returns:

timeValue or NEG_ONE_SECOND
defaultsToNegativeOneMillisecond
(final TimeValue
may be null
timeValue
)

Returns the given timeValue if it is not null, if null then returns NEG_ONE_SECOND.

public static TimeValue

Returns:

timeValue or NEG_ONE_SECOND
defaultsToNegativeOneSecond
(final TimeValue
may be null
timeValue
)

Returns the given timeValue if it is not null, if null then returns NEG_ONE_SECOND.

public static TimeValue

Returns:

timeValue or ZERO_MILLISECONDS
defaultsToZeroMilliseconds
(final TimeValue
may be null
timeValue
)

Returns the given timeValue if it is not null, if null then returns ZERO_MILLISECONDS.

public TimeValue

Returns:

this / divisor
divide
(final long
value by which this TimeValue is to be divided.
divisor
)

Returns a TimeValue whose value is (this / divisor).

public TimeValue

Returns:

this / divisor
divide
(final long
value by which this TimeValue is to be divided.
divisor
,
final TimeUnit
the target TimeUnit
targetTimeUnit
)

Returns a TimeValue whose value is (this / divisor).

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public long
public TimeUnit
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public static boolean
isNonNegative(final TimeValue timeValue)

public static boolean
isPositive(final TimeValue timeValue)

public TimeValue
min(final TimeValue other)

private TimeUnit
min(final TimeUnit other)

public static TimeValue

Returns:

a Timeout.
of
(final long
the time duration in the given timeUnit.
duration
,
final TimeUnit
the time unit for the given duration.
timeUnit
)

Creates a TimeValue.

public static TimeValue

Returns:

a Timeout
of
(final Duration
the time duration.
duration
)

Creates a TimeValue from a Duration.

public static TimeValue
ofDays(final long days)

public static TimeValue
ofHours(final long hours)

public static TimeValue
ofMicroseconds(final long microseconds)

public static TimeValue
ofMilliseconds(final long millis)

public static TimeValue
ofMinutes(final long minutes)

public static TimeValue
ofNanoseconds(final long nanoseconds)

public static TimeValue
ofSeconds(final long seconds)

public static TimeValue

Returns:

a new TimeValue
parse
(final String
the TimeValue to parse
value
)

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

private int
private int

Returns:

a number from 1 to 7, where 1 is NANOSECONDS and 7 DAYS.
scale
(final TimeUnit
a TimeUnit
tUnit
)

Returns a made up scale for TimeUnits.

public void
public void
timedJoin(final Thread thread)

public void
timedWait(final Object obj)

pack-priv static ChronoUnit

Returns:

the converted equivalent ChronoUnit
toChronoUnit
(final TimeUnit timeUnit)

Converts a TimeUnit to the equivalent ChronoUnit.

public long
public Duration

Returns:

a Duration.
toDuration
()

Converts this instance of to a Duration.

public long
public long
public long
public int
public long
public long
public long
public int
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Timeout
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

durationback to summary
private final long duration
INT_UNDEFINEDback to summary
pack-priv static final int INT_UNDEFINED
MAX_VALUEback to summary
public static final TimeValue MAX_VALUE

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

NEG_ONE_MILLISECONDback to summary
public static final TimeValue NEG_ONE_MILLISECOND

A negative one millisecond TimeValue.

NEG_ONE_SECONDback to summary
public static final TimeValue NEG_ONE_SECOND

A negative one second TimeValue.

timeUnitback to summary
private final TimeUnit timeUnit
ZERO_MILLISECONDSback to summary
public static final TimeValue ZERO_MILLISECONDS

A zero milliseconds TimeValue.

Constructor Detail

TimeValueback to summary
pack-priv TimeValue(final long duration, final TimeUnit timeUnit)

Method Detail

asBoundIntback to summary
public static int asBoundInt(final 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:long

a long value to convert

Returns:int

an int value bound within Integer#MIN_VALUE and Integer#MAX_VALUE.

compareToback to summary
public int compareTo(final TimeValue other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:TimeValue

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
convertback to summary
public long convert(final TimeUnit targetTimeUnit)
defaultsToback to summary
public static <T extends TimeValue> T defaultsTo(final T timeValue, final T defaultValue)

Returns the given timeValue if it is not null, if null then returns the given defaultValue.

Parameters
timeValue:T

may be null

defaultValue:T

may be null

Returns:T

timeValue or defaultValue

defaultsToNegativeOneMillisecondback to summary
public static TimeValue defaultsToNegativeOneMillisecond(final TimeValue timeValue)

Returns the given timeValue if it is not null, if null then returns NEG_ONE_SECOND.

Parameters
timeValue:TimeValue

may be null

Returns:TimeValue

timeValue or NEG_ONE_SECOND

defaultsToNegativeOneSecondback to summary
public static TimeValue defaultsToNegativeOneSecond(final TimeValue timeValue)

Returns the given timeValue if it is not null, if null then returns NEG_ONE_SECOND.

Parameters
timeValue:TimeValue

may be null

Returns:TimeValue

timeValue or NEG_ONE_SECOND

defaultsToZeroMillisecondsback to summary
public static TimeValue defaultsToZeroMilliseconds(final TimeValue timeValue)

Returns the given timeValue if it is not null, if null then returns ZERO_MILLISECONDS.

Parameters
timeValue:TimeValue

may be null

Returns:TimeValue

timeValue or ZERO_MILLISECONDS

divideback to summary
public TimeValue divide(final long divisor)

Returns a TimeValue whose value is (this / divisor).

Parameters
divisor:long

value by which this TimeValue is to be divided.

Returns:TimeValue

this / divisor

Exceptions
ArithmeticException:
if divisor is zero.
divideback to summary
public TimeValue divide(final long divisor, final TimeUnit targetTimeUnit)

Returns a TimeValue whose value is (this / divisor).

Parameters
divisor:long

value by which this TimeValue is to be divided.

targetTimeUnit:TimeUnit

the target TimeUnit

Returns:TimeValue

this / divisor

Exceptions
ArithmeticException:
if divisor is zero.
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDurationback to summary
public long getDuration()
getTimeUnitback to summary
public TimeUnit getTimeUnit()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isNonNegativeback to summary
public static boolean isNonNegative(final TimeValue timeValue)
isPositiveback to summary
public static boolean isPositive(final TimeValue timeValue)
minback to summary
public TimeValue min(final TimeValue other)
minback to summary
private TimeUnit min(final TimeUnit other)
ofback to summary
public static TimeValue of(final long duration, final TimeUnit timeUnit)

Creates a TimeValue.

Parameters
duration:long

the time duration in the given timeUnit.

timeUnit:TimeUnit

the time unit for the given duration.

Returns:TimeValue

a Timeout.

ofback to summary
public static TimeValue of(final Duration duration)

Creates a TimeValue from a Duration.

Parameters
duration:Duration

the time duration.

Returns:TimeValue

a Timeout

Since
5.2
ofDaysback to summary
public static TimeValue ofDays(final long days)
ofHoursback to summary
public static TimeValue ofHours(final long hours)
ofMicrosecondsback to summary
public static TimeValue ofMicroseconds(final long microseconds)
ofMillisecondsback to summary
public static TimeValue ofMilliseconds(final long millis)
ofMinutesback to summary
public static TimeValue ofMinutes(final long minutes)
ofNanosecondsback to summary
public static TimeValue ofNanoseconds(final long nanoseconds)
ofSecondsback to summary
public static TimeValue ofSeconds(final long seconds)
parseback to summary
public static TimeValue parse(final 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:String

the TimeValue to parse

Returns:TimeValue

a new TimeValue

Exceptions
ParseException:
if the number cannot be parsed
scaleback to summary
private int scale()
scaleback to summary
private int scale(final TimeUnit tUnit)

Returns a made up scale for TimeUnits.

Parameters
tUnit:TimeUnit

a TimeUnit

Returns:int

a number from 1 to 7, where 1 is NANOSECONDS and 7 DAYS.

sleepback to summary
public void sleep() throws InterruptedException
timedJoinback to summary
public void timedJoin(final Thread thread) throws InterruptedException
timedWaitback to summary
public void timedWait(final Object obj) throws InterruptedException
toChronoUnitback to summary
pack-priv static ChronoUnit toChronoUnit(final TimeUnit timeUnit)

Converts a TimeUnit to the equivalent ChronoUnit.

Returns:ChronoUnit

the converted equivalent ChronoUnit

toDaysback to summary
public long toDays()
toDurationback to summary
public Duration toDuration()

Converts this instance of to a Duration.

Returns:Duration

a Duration.

Since
5.2
toHoursback to summary
public long toHours()
toMicrosecondsback to summary
public long toMicroseconds()
toMillisecondsback to summary
public long toMilliseconds()
toMillisecondsIntBoundback to summary
public int toMillisecondsIntBound()
toMinutesback to summary
public long toMinutes()
toNanosecondsback to summary
public long toNanoseconds()
toSecondsback to summary
public long toSeconds()
toSecondsIntBoundback to summary
public int toSecondsIntBound()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toTimeoutback to summary
public Timeout toTimeout()