Package 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
FieldsModifier and TypeFieldDescriptionprivate final long
(package private) static final int
static final TimeValue
A constant holding the maximum value aTimeValue
can have:Long.MAX_VALUE
days.static final TimeValue
A negative one millisecondTimeValue
.static final TimeValue
A negative one secondTimeValue
.private final TimeUnit
static final TimeValue
A zero millisecondsTimeValue
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
asBoundInt
(long value) Returns the givenlong
value as anint
where long values out of int range are returned asInteger.MIN_VALUE
andInteger.MAX_VALUE
.int
long
static <T extends TimeValue>
TdefaultsTo
(T timeValue, T defaultValue) Returns the giventimeValue
if it is notnull
, ifnull
then returns the givendefaultValue
.static TimeValue
defaultsToNegativeOneMillisecond
(TimeValue timeValue) static TimeValue
defaultsToNegativeOneSecond
(TimeValue timeValue) static TimeValue
defaultsToZeroMilliseconds
(TimeValue timeValue) divide
(long divisor) Returns a TimeValue whose value is(this / divisor)
.Returns a TimeValue whose value is(this / divisor)
.boolean
long
int
hashCode()
static boolean
isNonNegative
(TimeValue timeValue) static boolean
isPositive
(TimeValue timeValue) private TimeUnit
static TimeValue
Creates a TimeValue.static TimeValue
Creates a TimeValue from a Duration.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
Parses a TimeValue in the format<Long><SPACE><TimeUnit>
, for example"1200 MILLISECONDS"
.private int
scale()
private int
Returns a made up scale for TimeUnits.void
sleep()
void
void
(package private) static ChronoUnit
toChronoUnit
(TimeUnit timeUnit) Converts aTimeUnit
to the equivalentChronoUnit
.long
toDays()
Converts this instance of to a Duration.long
toHours()
long
long
int
long
long
long
int
toString()
-
Field Details
-
INT_UNDEFINED
static final int INT_UNDEFINED- See Also:
-
MAX_VALUE
A constant holding the maximum value aTimeValue
can have:Long.MAX_VALUE
days. -
NEG_ONE_MILLISECOND
A negative one millisecondTimeValue
. -
NEG_ONE_SECOND
A negative one secondTimeValue
. -
ZERO_MILLISECONDS
A zero millisecondsTimeValue
. -
duration
private final long duration -
timeUnit
-
-
Constructor Details
-
TimeValue
TimeValue(long duration, TimeUnit timeUnit)
-
-
Method Details
-
asBoundInt
public static int asBoundInt(long value) Returns the givenlong
value as anint
where long values out of int range are returned asInteger.MIN_VALUE
andInteger.MAX_VALUE
.For example:
TimeValue.asBoundInt(Long.MAX_VALUE)
returnsInteger.MAX_VALUE
.- Parameters:
value
- a long value to convert- Returns:
- an int value bound within
Integer.MIN_VALUE
andInteger.MAX_VALUE
.
-
defaultsTo
Returns the giventimeValue
if it is notnull
, ifnull
then returns the givendefaultValue
.- Parameters:
timeValue
- may benull
defaultValue
- may benull
- Returns:
timeValue
ordefaultValue
-
defaultsToNegativeOneMillisecond
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orNEG_ONE_SECOND
-
defaultsToNegativeOneSecond
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orNEG_ONE_SECOND
-
defaultsToZeroMilliseconds
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orZERO_MILLISECONDS
-
isNonNegative
-
isPositive
-
of
Creates a TimeValue.- Parameters:
duration
- the time duration in the giventimeUnit
.timeUnit
- the time unit for the given duration.- Returns:
- a Timeout.
-
of
Creates a TimeValue from a Duration.- Parameters:
duration
- the time duration.- Returns:
- a Timeout
- Since:
- 5.2
-
ofDays
-
ofHours
-
ofMicroseconds
-
ofMilliseconds
-
ofMinutes
-
ofNanoseconds
-
ofSeconds
-
toChronoUnit
Converts aTimeUnit
to the equivalentChronoUnit
.- Returns:
- the converted equivalent ChronoUnit
-
parse
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
-
equals
-
divide
Returns a TimeValue whose value is(this / divisor)
.- Parameters:
divisor
- value by which this TimeValue is to be divided.- Returns:
this / divisor
- Throws:
ArithmeticException
- ifdivisor
is zero.
-
divide
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
- ifdivisor
is zero.
-
getDuration
public long getDuration() -
getTimeUnit
-
hashCode
public int hashCode() -
min
-
min
-
scale
private int scale() -
scale
Returns a made up scale for TimeUnits.- Parameters:
tUnit
- a TimeUnit- Returns:
- a number from 1 to 7, where 1 is NANOSECONDS and 7 DAYS.
-
sleep
- Throws:
InterruptedException
-
timedJoin
- Throws:
InterruptedException
-
timedWait
- Throws:
InterruptedException
-
toDays
public long toDays() -
toDuration
Converts this instance of to a Duration.- Returns:
- a Duration.
- Since:
- 5.2
-
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
- Specified by:
compareTo
in interfaceComparable<TimeValue>
-
toString
-
toTimeout
-