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

public Class Deadline

extends Object
Class Inheritance
Imports
java.text.ParseException, java.time.Instant, .ZoneOffset, java.time.format.DateTimeFormatter, .DateTimeFormatterBuilder, java.util.concurrent.TimeUnit

A deadline based on a UNIX time, the elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.
Since
5.0

Field Summary

Modifier and TypeField and Description
public static final String
DATE_FORMAT

The format used for parsing and formatting dates.

private static final DateTimeFormatter
private volatile boolean
private static final long
INTERNAL_MAX_VALUE

A special internal value that marks a deadline as the longest possible.

private static final long
INTERNAL_MIN_VALUE

A special internal value that marks a deadline as the shortest possible.

private volatile long
public static Deadline
MAX_VALUE

The maximum (longest-lived) deadline.

public static Deadline
MIN_VALUE

The minimum (shortest-lived) deadline.

private final long

Constructor Summary

AccessConstructor and Description
private
Deadline(final long
UNIX time in milliseconds.
deadlineMillis
)

Constructs a new instance with the given UNIX time in milliseconds.

Method Summary

Modifier and TypeMethod and Description
public static Deadline

Returns:

a deadline representing the current time plus the given time value.
calculate
(final long
A time in UNIX milliseconds, usually the current time.
timeMillis
,
final TimeValue
time value to add to timeMillis.
timeValue
)

Calculates a deadline with a given time in milliseconds plus a given time value.

public static Deadline

Returns:

a deadline representing the current time plus the given time value.
calculate
(final TimeValue
time value to add to timeMillis.
timeValue
)

Calculates a deadline from now plus a given time value.

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 String

Returns:

a formatted string.
format
(final TimeUnit
the time unit to show how much over the deadline we are.
overdueTimeUnit
)

Formats this deadline.

public String

Returns:

a formatted string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.
formatTarget
()

Formats the deadline value as a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

public Deadline
public static Deadline

Returns:

a new deadline.
fromUnixMilliseconds
(final long
a UNIX time in milliseconds.
value
)

Creates a deadline from a UNIX time in milliseconds.

pack-priv long

Returns:

the last time we checked the current time.
getLastCheck
()

Package private for testing.

public long

Returns:

the UNIX time deadline value.
getValue
()

Gets the UNIX time deadline value.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

whether this deadline occurs before the given time in milliseconds.
isBefore
(final long
the time to compare.
millis
)

Returns whether this deadline occurs before the given time in milliseconds.

public boolean

Returns:

whether the deadline has expired.
isExpired
()

Returns whether the deadline has expired.

public boolean

Returns:

whether this deadline is the maximum deadline.
isMax
()

Returns whether this deadline is the maximum deadline.

public boolean

Returns:

whether this deadline is the minimum deadline.
isMin
()

Returns whether this deadline is the minimum deadline.

public boolean

Returns:

whether this deadline has not expired.
isNotExpired
()

Returns whether this deadline has not expired.

public Deadline

Returns:

the smaller of this and other.
min
(final Deadline
another deadline.
other
)

Returns the smaller of this and another Deadline.

public static Deadline

Returns:

a deadline from a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.
parse
(final String
a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.
source
)

Creates a deadline from a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

public long

Returns:

the different in milliseconds between the deadline and now.
remaining
()

Returns the difference in milliseconds between the deadline and now.

public TimeValue

Returns:

Returns the different as a TimeValue between the deadline and now.
remainingTimeValue
()

Returns the difference as a TimeValue between the deadline and now.

private void
public String
toString()

Overrides java.lang.Object.toString.

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

Field Detail

DATE_FORMATback to summary
public static final String DATE_FORMAT

The format used for parsing and formatting dates.

DATE_TIME_FORMATTERback to summary
private static final DateTimeFormatter DATE_TIME_FORMATTER
frozenback to summary
private volatile boolean frozen
INTERNAL_MAX_VALUEback to summary
private static final long INTERNAL_MAX_VALUE

A special internal value that marks a deadline as the longest possible.

INTERNAL_MIN_VALUEback to summary
private static final long INTERNAL_MIN_VALUE

A special internal value that marks a deadline as the shortest possible.

lastCheckback to summary
private volatile long lastCheck
MAX_VALUEback to summary
public static Deadline MAX_VALUE

The maximum (longest-lived) deadline.

MIN_VALUEback to summary
public static Deadline MIN_VALUE

The minimum (shortest-lived) deadline.

valueback to summary
private final long value

Constructor Detail

Deadlineback to summary
private Deadline(final long deadlineMillis)

Constructs a new instance with the given UNIX time in milliseconds.

Parameters
deadlineMillis:long

UNIX time in milliseconds.

Method Detail

calculateback to summary
public static Deadline calculate(final long timeMillis, final TimeValue timeValue)

Calculates a deadline with a given time in milliseconds plus a given time value. Non-positive time values represent an indefinite timeout without a deadline.

Parameters
timeMillis:long

A time in UNIX milliseconds, usually the current time.

timeValue:TimeValue

time value to add to timeMillis.

Returns:Deadline

a deadline representing the current time plus the given time value.

calculateback to summary
public static Deadline calculate(final TimeValue timeValue)

Calculates a deadline from now plus a given time value. Non-positive time values represent an indefinite timeout without a deadline.

Parameters
timeValue:TimeValue

time value to add to timeMillis.

Returns:Deadline

a deadline representing the current time plus the given time value.

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
formatback to summary
public String format(final TimeUnit overdueTimeUnit)

Formats this deadline.

Parameters
overdueTimeUnit:TimeUnit

the time unit to show how much over the deadline we are.

Returns:String

a formatted string.

formatTargetback to summary
public String formatTarget()

Formats the deadline value as a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

Returns:String

a formatted string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

freezeback to summary
public Deadline freeze()
fromUnixMillisecondsback to summary
public static Deadline fromUnixMilliseconds(final long value)

Creates a deadline from a UNIX time in milliseconds.

Parameters
value:long

a UNIX time in milliseconds.

Returns:Deadline

a new deadline.

getLastCheckback to summary
pack-priv long getLastCheck()

Package private for testing.

Returns:long

the last time we checked the current time.

getValueback to summary
public long getValue()

Gets the UNIX time deadline value.

Returns:long

the UNIX time deadline value.

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
isBeforeback to summary
public boolean isBefore(final long millis)

Returns whether this deadline occurs before the given time in milliseconds.

Parameters
millis:long

the time to compare.

Returns:boolean

whether this deadline occurs before the given time in milliseconds.

isExpiredback to summary
public boolean isExpired()

Returns whether the deadline has expired.

Returns:boolean

whether the deadline has expired.

isMaxback to summary
public boolean isMax()

Returns whether this deadline is the maximum deadline.

Returns:boolean

whether this deadline is the maximum deadline.

isMinback to summary
public boolean isMin()

Returns whether this deadline is the minimum deadline.

Returns:boolean

whether this deadline is the minimum deadline.

isNotExpiredback to summary
public boolean isNotExpired()

Returns whether this deadline has not expired.

Returns:boolean

whether this deadline has not expired.

minback to summary
public Deadline min(final Deadline other)

Returns the smaller of this and another Deadline.

Parameters
other:Deadline

another deadline.

Returns:Deadline

the smaller of this and other.

parseback to summary
public static Deadline parse(final String source) throws ParseException

Creates a deadline from a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

Parameters
source:String

a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

Returns:Deadline

a deadline from a string in the format yyyy-MM-dd\'T\'HH:mm:ss.SSSZ.

Exceptions
ParseException:
if the specified source string cannot be parsed.
remainingback to summary
public long remaining()

Returns the difference in milliseconds between the deadline and now.

Returns:long

the different in milliseconds between the deadline and now.

remainingTimeValueback to summary
public TimeValue remainingTimeValue()

Returns the difference as a TimeValue between the deadline and now.

Returns:TimeValue

Returns the different as a TimeValue between the deadline and now.

setLastCheckback to summary
private void setLastCheck()
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