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 intstatic final TimeValueA constant holding the maximum value aTimeValuecan have:Long.MAX_VALUEdays.static final TimeValueA negative one millisecondTimeValue.static final TimeValueA negative one secondTimeValue.private final TimeUnitstatic final TimeValueA zero millisecondsTimeValue. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intasBoundInt(long value) Returns the givenlongvalue as anintwhere long values out of int range are returned asInteger.MIN_VALUEandInteger.MAX_VALUE.intlongstatic <T extends TimeValue>
TdefaultsTo(T timeValue, T defaultValue) Returns the giventimeValueif it is notnull, ifnullthen returns the givendefaultValue.static TimeValuedefaultsToNegativeOneMillisecond(TimeValue timeValue) static TimeValuedefaultsToNegativeOneSecond(TimeValue timeValue) static TimeValuedefaultsToZeroMilliseconds(TimeValue timeValue) divide(long divisor) Returns a TimeValue whose value is(this / divisor).Returns a TimeValue whose value is(this / divisor).booleanlonginthashCode()static booleanisNonNegative(TimeValue timeValue) static booleanisPositive(TimeValue timeValue) private TimeUnitstatic TimeValueCreates a TimeValue.static TimeValueCreates a TimeValue from a Duration.static TimeValueofDays(long days) static TimeValueofHours(long hours) static TimeValueofMicroseconds(long microseconds) static TimeValueofMilliseconds(long millis) static TimeValueofMinutes(long minutes) static TimeValueofNanoseconds(long nanoseconds) static TimeValueofSeconds(long seconds) static TimeValueParses a TimeValue in the format<Long><SPACE><TimeUnit>, for example"1200 MILLISECONDS".private intscale()private intReturns a made up scale for TimeUnits.voidsleep()voidvoid(package private) static ChronoUnittoChronoUnit(TimeUnit timeUnit) Converts aTimeUnitto the equivalentChronoUnit.longtoDays()Converts this instance of to a Duration.longtoHours()longlongintlonglonglonginttoString()
-
Field Details
-
INT_UNDEFINED
static final int INT_UNDEFINED- See Also:
-
MAX_VALUE
A constant holding the maximum value aTimeValuecan have:Long.MAX_VALUEdays. -
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 givenlongvalue as anintwhere long values out of int range are returned asInteger.MIN_VALUEandInteger.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_VALUEandInteger.MAX_VALUE.
-
defaultsTo
Returns the giventimeValueif it is notnull, ifnullthen returns the givendefaultValue.- Parameters:
timeValue- may benulldefaultValue- may benull- Returns:
timeValueordefaultValue
-
defaultsToNegativeOneMillisecond
- Parameters:
timeValue- may benull- Returns:
timeValueorNEG_ONE_SECOND
-
defaultsToNegativeOneSecond
- Parameters:
timeValue- may benull- Returns:
timeValueorNEG_ONE_SECOND
-
defaultsToZeroMilliseconds
- Parameters:
timeValue- may benull- Returns:
timeValueorZERO_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 aTimeUnitto 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- ifdivisoris 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- ifdivisoris 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:
compareToin interfaceComparable<TimeValue>
-
toString
-
toTimeout
-