APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.net.http.common

public final Class Deadline

extends Object
implements Comparable<Deadline>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.time.DateTimeException, .Duration, .Instant, java.time.temporal.ChronoUnit, .TemporalUnit, .UnsupportedTemporalTypeException

An instantaneous point on the time-line.

This class is immutable and thread-safe.

Operations that add or subtract durations to a Deadline, whether represented as a Duration or as a long time increment (such as seconds or nanoseconds) do not throw on numeric overflow if the resulting Deadline would exceed MAX or be less than MIN. Instead, MAX or MIN is returned, respectively. Similarly, methods that return a duration as a long will either return Long#MAX_VALUE or Long#MIN_VALUE if the returned quantity would exceed the capacity of a long.

Field Summary

Modifier and TypeField and Description
private final Instant
public static final Deadline
public static final Deadline

Constructor Summary

AccessConstructor and Description
private
Deadline(Instant deadline)

Method Summary

Modifier and TypeMethod and Description
pack-priv Instant
public static Duration

Returns:

a Duration, not null
between
(Deadline
the start deadline, inclusive, not null
startInclusive
,
Deadline
the end deadline, exclusive, not null
endExclusive
)

Obtains a Duration representing the duration between two deadlines.

public int
compareTo(Deadline o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if this deadline is after the specified deadline
isAfter
(Deadline
the other deadline to compare to, not null
otherDeadline
)

Checks if this deadline is after the specified deadline.

public boolean

Returns:

true if this deadline is before the specified deadine
isBefore
(Deadline
the other deadine to compare to, not null
otherDeadline
)

Checks if this deadline is before the specified deadline.

public Deadline

Returns:

a deadline with the specified amount subtracted from this deadline
minus
(Duration
the amount to subtract, not null
duration
)

Returns a deadline with the specified amount subtracted from this deadline.

pack-priv static Deadline
of(Instant instant)

public Deadline

Returns:

a deadline with the specified amount added to this deadline
plus
(long
the amount of the unit to add to the result, may be negative
amountToAdd
,
TemporalUnit
the unit of the amount to add, not null
unit
)

Returns a deadline with the specified amount added to this deadline.

public Deadline

Returns:

a deadline with the specified duration added to this deadline
plus
(Duration
the duration to add, not null
duration
)

Returns a deadline with the specified duration added to this deadline.

public Deadline

Returns:

a deadline with the specified duration in milliseconds added to this deadline
plusMillis
(long
the milliseconds to add, positive or negative
millisToAdd
)

Returns a deadline with the specified duration in milliseconds added to this deadline.

public Deadline

Returns:

a deadline with the specified duration in nanoseconds added
plusNanos
(long
the nanoseconds to add, positive or negative
nanosToAdd
)

Returns a deadline with the specified duration in nanoseconds added.

public Deadline

Returns:

a deadline with the specified duration in seconds added to this deadline
plusSeconds
(long
the seconds to add, positive or negative
secondsToAdd
)

Returns a deadline with the specified duration in seconds added to this deadline.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Deadline

Returns:

a Deadline based on this deadline with the time truncated, not null
truncatedTo
(ChronoUnit
the unit to truncate to, not null
unit
)

Returns a copy of this Deadline truncated to the specified unit.

public long

Returns:

the amount of time between this deadline and the end deadline
until
(Deadline
the end deadline, exclusive
endExclusive
,
TemporalUnit
the unit to measure the amount in, not null
unit
)

Calculates the amount of time until another deadline in terms of the specified unit.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

deadlineback to summary
private final Instant deadline
MAXback to summary
public static final Deadline MAX
MINback to summary
public static final Deadline MIN

Constructor Detail

Deadlineback to summary
private Deadline(Instant deadline)

Method Detail

asInstantback to summary
pack-priv Instant asInstant()
betweenback to summary
public static Duration between(Deadline startInclusive, Deadline endExclusive)

Obtains a Duration representing the duration between two deadlines.

The result of this method can be a negative period if the end is before the start.

Parameters
startInclusive:Deadline

the start deadline, inclusive, not null

endExclusive:Deadline

the end deadline, exclusive, not null

Returns:Duration

a Duration, not null

compareToback to summary
public int compareTo(Deadline o)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

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.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this 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.
Annotations
@Override
isAfterback to summary
public boolean isAfter(Deadline otherDeadline)

Checks if this deadline is after the specified deadline.

The comparison is based on the time-line position of the deadlines.

Parameters
otherDeadline:Deadline

the other deadline to compare to, not null

Returns:boolean

true if this deadline is after the specified deadline

Exceptions
NullPointerException:
if otherDeadline is null
isBeforeback to summary
public boolean isBefore(Deadline otherDeadline)

Checks if this deadline is before the specified deadline.

The comparison is based on the time-line position of the deadlines.

Parameters
otherDeadline:Deadline

the other deadine to compare to, not null

Returns:boolean

true if this deadline is before the specified deadine

Exceptions
NullPointerException:
if otherDeadline is null
minusback to summary
public Deadline minus(Duration duration)

Returns a deadline with the specified amount subtracted from this deadline.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MIN if the provided duration is positive, Deadline#MAX otherwise.

Parameters
duration:Duration

the amount to subtract, not null

Returns:Deadline

a deadline with the specified amount subtracted from this deadline

ofback to summary
pack-priv static Deadline of(Instant instant)
plusback to summary
public Deadline plus(long amountToAdd, TemporalUnit unit)

Returns a deadline with the specified amount added to this deadline.

This returns a Deadline, based on this one, with the amount in terms of the unit added. If it is not possible to add the amount, because the unit is not supported or for some other reason, an exception is thrown.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MAX if the provided amount is positive, Deadline#MIN otherwise.

Parameters
amountToAdd:long

the amount of the unit to add to the result, may be negative

unit:TemporalUnit

the unit of the amount to add, not null

Returns:Deadline

a deadline with the specified amount added to this deadline

Exceptions
UnsupportedTemporalTypeException:
if the unit is not supported
See Also
Instant#plus(long, TemporalUnit)
plusback to summary
public Deadline plus(Duration duration)

Returns a deadline with the specified duration added to this deadline.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MAX if the provided duration is positive, Deadline#MIN otherwise.

Parameters
duration:Duration

the duration to add, not null

Returns:Deadline

a deadline with the specified duration added to this deadline

plusMillisback to summary
public Deadline plusMillis(long millisToAdd)

Returns a deadline with the specified duration in milliseconds added to this deadline.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MAX if the provided duration is positive, Deadline#MIN otherwise.

Parameters
millisToAdd:long

the milliseconds to add, positive or negative

Returns:Deadline

a deadline with the specified duration in milliseconds added to this deadline

plusNanosback to summary
public Deadline plusNanos(long nanosToAdd)

Returns a deadline with the specified duration in nanoseconds added.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MAX if the provided duration is positive, Deadline#MIN otherwise.

Parameters
nanosToAdd:long

the nanoseconds to add, positive or negative

Returns:Deadline

a deadline with the specified duration in nanoseconds added

plusSecondsback to summary
public Deadline plusSeconds(long secondsToAdd)

Returns a deadline with the specified duration in seconds added to this deadline.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Deadline#MAX if the provided duration is positive, Deadline#MIN otherwise.

Parameters
secondsToAdd:long

the seconds to add, positive or negative

Returns:Deadline

a deadline with the specified duration in seconds added to this deadline

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
truncatedToback to summary
public Deadline truncatedTo(ChronoUnit unit)

Returns a copy of this Deadline truncated to the specified unit.

Truncating the deadline returns a copy of the original with fields smaller than the specified unit set to zero. The fields are calculated on the basis of using a UTC offset as seen in Instant.toString. For example, truncating with the MINUTES unit will round down to the nearest minute, setting the seconds and nanoseconds to zero.

The unit must have a duration that divides into the length of a standard day without remainder. This includes all supplied time units on ChronoUnit and DAYS. Other units throw an exception.

This instance is immutable and unaffected by this method call.

Parameters
unit:ChronoUnit

the unit to truncate to, not null

Returns:Deadline

a Deadline based on this deadline with the time truncated, not null

Exceptions
DateTimeException:
if the unit is invalid for truncation
UnsupportedTemporalTypeException:
if the unit is not supported
untilback to summary
public long until(Deadline endExclusive, TemporalUnit unit)

Calculates the amount of time until another deadline in terms of the specified unit.

This calculates the amount of time between two Deadline objects in terms of a single TemporalUnit. The start and end points are this and the specified deadline. The result will be negative if the end is before the start. The calculation returns a whole number, representing the number of complete units between the two deadlines.

This instance is immutable and unaffected by this method call.

On numeric overflows, this method will return Long#MAX_VALUE if the current deadline is before the provided end deadline, Long#MIN_VALUE otherwise.

Parameters
endExclusive:Deadline

the end deadline, exclusive

unit:TemporalUnit

the unit to measure the amount in, not null

Returns:long

the amount of time between this deadline and the end deadline

Exceptions
UnsupportedTemporalTypeException:
if the unit is not supported