Package org.apache.hc.core5.util
Class TimeValue
- java.lang.Object
-
- org.apache.hc.core5.util.TimeValue
-
-
Field Summary
Fields Modifier and Type Field Description private long
duration
(package private) static int
INT_UNDEFINED
static TimeValue
MAX_VALUE
A constant holding the maximum value aTimeValue
can have:Long.MAX_VALUE
days.static TimeValue
NEG_ONE_MILLISECOND
A negative one millisecondTimeValue
.static TimeValue
NEG_ONE_SECOND
A negative one secondTimeValue
.private java.util.concurrent.TimeUnit
timeUnit
static TimeValue
ZERO_MILLISECONDS
A zero millisecondsTimeValue
.
-
Constructor Summary
Constructors Constructor Description TimeValue(long duration, java.util.concurrent.TimeUnit timeUnit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
.int
compareTo(TimeValue other)
long
convert(java.util.concurrent.TimeUnit targetTimeUnit)
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)
TimeValue
divide(long divisor)
Returns a TimeValue whose value is(this / divisor)
.TimeValue
divide(long divisor, java.util.concurrent.TimeUnit targetTimeUnit)
Returns a TimeValue whose value is(this / divisor)
.boolean
equals(java.lang.Object obj)
long
getDuration()
java.util.concurrent.TimeUnit
getTimeUnit()
int
hashCode()
static boolean
isNonNegative(TimeValue timeValue)
static boolean
isPositive(TimeValue timeValue)
private java.util.concurrent.TimeUnit
min(java.util.concurrent.TimeUnit other)
TimeValue
min(TimeValue other)
static TimeValue
of(long duration, java.util.concurrent.TimeUnit timeUnit)
Creates a TimeValue.static TimeValue
of(java.time.Duration duration)
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
parse(java.lang.String value)
Parses a TimeValue in the format<Long><SPACE><TimeUnit>
, for example"1200 MILLISECONDS"
.private int
scale()
private int
scale(java.util.concurrent.TimeUnit tUnit)
Returns a made up scale for TimeUnits.void
sleep()
void
timedJoin(java.lang.Thread thread)
void
timedWait(java.lang.Object obj)
(package private) static java.time.temporal.ChronoUnit
toChronoUnit(java.util.concurrent.TimeUnit timeUnit)
Converts aTimeUnit
to the equivalentChronoUnit
.long
toDays()
java.time.Duration
toDuration()
Converts this instance of to a Duration.long
toHours()
long
toMicroseconds()
long
toMilliseconds()
int
toMillisecondsIntBound()
long
toMinutes()
long
toNanoseconds()
long
toSeconds()
int
toSecondsIntBound()
java.lang.String
toString()
Timeout
toTimeout()
-
-
-
Field Detail
-
INT_UNDEFINED
static final int INT_UNDEFINED
- See Also:
- Constant Field Values
-
MAX_VALUE
public static final TimeValue MAX_VALUE
A constant holding the maximum value aTimeValue
can have:Long.MAX_VALUE
days.
-
NEG_ONE_MILLISECOND
public static final TimeValue NEG_ONE_MILLISECOND
A negative one millisecondTimeValue
.
-
duration
private final long duration
-
timeUnit
private final java.util.concurrent.TimeUnit timeUnit
-
-
Method Detail
-
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
public static <T extends TimeValue> T defaultsTo(T timeValue, T defaultValue)
Returns the giventimeValue
if it is notnull
, ifnull
then returns the givendefaultValue
.- Parameters:
timeValue
- may benull
defaultValue
- may benull
- Returns:
timeValue
ordefaultValue
-
defaultsToNegativeOneMillisecond
public static TimeValue defaultsToNegativeOneMillisecond(TimeValue timeValue)
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orNEG_ONE_SECOND
-
defaultsToNegativeOneSecond
public static TimeValue defaultsToNegativeOneSecond(TimeValue timeValue)
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orNEG_ONE_SECOND
-
defaultsToZeroMilliseconds
public static TimeValue defaultsToZeroMilliseconds(TimeValue timeValue)
- Parameters:
timeValue
- may benull
- Returns:
timeValue
orZERO_MILLISECONDS
-
isNonNegative
public static boolean isNonNegative(TimeValue timeValue)
-
isPositive
public static boolean isPositive(TimeValue timeValue)
-
of
public static TimeValue of(long duration, java.util.concurrent.TimeUnit timeUnit)
Creates a TimeValue.- Parameters:
duration
- the time duration in the giventimeUnit
.timeUnit
- the time unit for the given duration.- Returns:
- a Timeout.
-
of
public static TimeValue of(java.time.Duration duration)
Creates a TimeValue from a Duration.- Parameters:
duration
- the time duration.- Returns:
- a Timeout
- Since:
- 5.2
-
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)
-
toChronoUnit
static java.time.temporal.ChronoUnit toChronoUnit(java.util.concurrent.TimeUnit timeUnit)
Converts aTimeUnit
to the equivalentChronoUnit
.- Returns:
- the converted equivalent ChronoUnit
-
parse
public static TimeValue parse(java.lang.String value) throws java.text.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:
java.text.ParseException
- if the number cannot be parsed
-
convert
public long convert(java.util.concurrent.TimeUnit targetTimeUnit)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.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:
java.lang.ArithmeticException
- ifdivisor
is zero.
-
divide
public TimeValue divide(long divisor, java.util.concurrent.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:
java.lang.ArithmeticException
- ifdivisor
is zero.
-
getDuration
public long getDuration()
-
getTimeUnit
public java.util.concurrent.TimeUnit getTimeUnit()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
min
private java.util.concurrent.TimeUnit min(java.util.concurrent.TimeUnit other)
-
scale
private int scale()
-
scale
private int scale(java.util.concurrent.TimeUnit tUnit)
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
public void sleep() throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
timedJoin
public void timedJoin(java.lang.Thread thread) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
timedWait
public void timedWait(java.lang.Object obj) throws java.lang.InterruptedException
- Throws:
java.lang.InterruptedException
-
toDays
public long toDays()
-
toDuration
public java.time.Duration 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
public int compareTo(TimeValue other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<TimeValue>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toTimeout
public Timeout toTimeout()
-
-