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 longduration(package private) static intINT_UNDEFINEDstatic TimeValueMAX_VALUEA constant holding the maximum value aTimeValuecan have:Long.MAX_VALUEdays.static TimeValueNEG_ONE_MILLISECONDA negative one millisecondTimeValue.static TimeValueNEG_ONE_SECONDA negative one secondTimeValue.private java.util.concurrent.TimeUnittimeUnitstatic TimeValueZERO_MILLISECONDSA 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 intasBoundInt(long value)Returns the givenlongvalue as anintwhere long values out of int range are returned asInteger.MIN_VALUEandInteger.MAX_VALUE.intcompareTo(TimeValue other)longconvert(java.util.concurrent.TimeUnit targetTimeUnit)static <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)TimeValuedivide(long divisor)Returns a TimeValue whose value is(this / divisor).TimeValuedivide(long divisor, java.util.concurrent.TimeUnit targetTimeUnit)Returns a TimeValue whose value is(this / divisor).booleanequals(java.lang.Object obj)longgetDuration()java.util.concurrent.TimeUnitgetTimeUnit()inthashCode()static booleanisNonNegative(TimeValue timeValue)static booleanisPositive(TimeValue timeValue)private java.util.concurrent.TimeUnitmin(java.util.concurrent.TimeUnit other)TimeValuemin(TimeValue other)static TimeValueof(long duration, java.util.concurrent.TimeUnit timeUnit)Creates a TimeValue.static TimeValueof(java.time.Duration duration)Creates 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 TimeValueparse(java.lang.String value)Parses a TimeValue in the format<Long><SPACE><TimeUnit>, for example"1200 MILLISECONDS".private intscale()private intscale(java.util.concurrent.TimeUnit tUnit)Returns a made up scale for TimeUnits.voidsleep()voidtimedJoin(java.lang.Thread thread)voidtimedWait(java.lang.Object obj)(package private) static java.time.temporal.ChronoUnittoChronoUnit(java.util.concurrent.TimeUnit timeUnit)Converts aTimeUnitto the equivalentChronoUnit.longtoDays()java.time.DurationtoDuration()Converts this instance of to a Duration.longtoHours()longtoMicroseconds()longtoMilliseconds()inttoMillisecondsIntBound()longtoMinutes()longtoNanoseconds()longtoSeconds()inttoSecondsIntBound()java.lang.StringtoString()TimeouttoTimeout()
-
-
-
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 aTimeValuecan have:Long.MAX_VALUEdays.
-
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 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
public static <T extends TimeValue> T defaultsTo(T timeValue, T defaultValue)
Returns the giventimeValueif it is notnull, ifnullthen returns the givendefaultValue.- Parameters:
timeValue- may benulldefaultValue- may benull- Returns:
timeValueordefaultValue
-
defaultsToNegativeOneMillisecond
public static TimeValue defaultsToNegativeOneMillisecond(TimeValue timeValue)
- Parameters:
timeValue- may benull- Returns:
timeValueorNEG_ONE_SECOND
-
defaultsToNegativeOneSecond
public static TimeValue defaultsToNegativeOneSecond(TimeValue timeValue)
- Parameters:
timeValue- may benull- Returns:
timeValueorNEG_ONE_SECOND
-
defaultsToZeroMilliseconds
public static TimeValue defaultsToZeroMilliseconds(TimeValue timeValue)
- Parameters:
timeValue- may benull- Returns:
timeValueorZERO_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 aTimeUnitto 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:
equalsin 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- ifdivisoris 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- ifdivisoris zero.
-
getDuration
public long getDuration()
-
getTimeUnit
public java.util.concurrent.TimeUnit getTimeUnit()
-
hashCode
public int hashCode()
- Overrides:
hashCodein 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:
compareToin interfacejava.lang.Comparable<TimeValue>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toTimeout
public Timeout toTimeout()
-
-