@Immutable public final class ElapsedTime extends Object implements Serializable, Comparable<ElapsedTime>
Implements elapsed time using the same time unit as DateTime
: an
integer number of 100 nanoseconds.
An elapsed time is immutable and never negative.
Modifier and Type | Field and Description |
---|---|
static ElapsedTime |
EMPTY
Empty.
|
static ElapsedTime |
HOUR
One hour.
|
static ElapsedTime |
INFINITY
Infinity.
|
static String |
INFINITY_STRING
Infinity string representation.
|
static ElapsedTime |
INVALID
Invalid elsped time representation.
|
static ElapsedTime |
MICRO
One microsecond.
|
static ElapsedTime |
MILLI
One millisecond.
|
static ElapsedTime |
MINUTE
One minute.
|
static ElapsedTime |
SECOND
One second.
|
Modifier and Type | Method and Description |
---|---|
ElapsedTime |
add(ElapsedTime other)
Adds an other elapsed time to this.
|
int |
compareTo(ElapsedTime other) |
boolean |
equals(Object other) |
ElapsedTime |
floor(ElapsedTime whole)
Floors the scaled internal (raw) representation of this.
|
ElapsedTime |
floor(long whole)
Floors the scaled internal (raw) representation of this.
|
static ElapsedTime |
fromDataInput(DataInput source)
Reads in an external representation of an elapsed time.
|
static ElapsedTime |
fromDuration(Duration duration)
Returns an elapsed time from a duration.
|
static ElapsedTime |
fromMillis(long millis)
Returns an elapsed time from a number of milliseconds.
|
static ElapsedTime |
fromNanos(long nanos)
Returns an elapsed time from a number of nanoseconds.
|
static ElapsedTime |
fromRaw(long raw)
Returns an elapsed time from an internal (raw) representation.
|
static ElapsedTime |
fromSeconds(double seconds)
Returns an elapsed time from a number of seconds.
|
static Optional<ElapsedTime> |
fromString(Optional<String> string)
Returns an elapsed time from an optional string representation.
|
static ElapsedTime |
fromString(String elapsedString)
Returns an elapsed time from a valid string representation.
|
int |
hashCode() |
boolean |
isEmpty()
Asks if this is an empty interval.
|
boolean |
isInfinity()
Asks if this is infinity.
|
boolean |
isInvalid()
Asks if this is the invalid elapsed time.
|
static ElapsedTime |
max(Collection<ElapsedTime> elapsedTimes)
Returns the maximum ElapsedTime instance.
|
static ElapsedTime |
max(ElapsedTime... elapsedTimes)
Returns the maximum ElapsedTime instance.
|
ElapsedTime |
max(Optional<ElapsedTime> other)
Returns the maximum between this and an other.
|
static ElapsedTime |
min(Collection<ElapsedTime> elapsedTimes)
Returns the minimum ElapsedTime instance.
|
static ElapsedTime |
min(ElapsedTime... elapsedTimes)
Returns the minimum ElapsedTime instance.
|
ElapsedTime |
min(Optional<ElapsedTime> other)
Returns the minimum between this and an other.
|
ElapsedTime |
mul(double factor)
Multiplies this by a factor.
|
ElapsedTime |
mul(long factor)
Multiplies this by a factor.
|
double |
ratio(ElapsedTime divisor)
Returns the ratio of this to an other elapsed time.
|
static Optional<ElapsedTime> |
readExternal(ObjectInput source)
Reads in an external representation of an elapsed time.
|
double |
scaled(ElapsedTime whole)
Returns the scaled internal (raw) representation of this.
|
double |
scaled(long whole)
Returns the scaled internal (raw) representation of this.
|
ElapsedTime |
sub(ElapsedTime other)
Substracts an other elapsed time from this.
|
void |
toDataOutput(DataOutput destination)
Sends to a data output.
|
Duration |
toDuration()
Returns a duration.
|
String |
toDurationString()
Returns this as a duration string.
|
long |
toMillis()
Returns this in millis.
|
long |
toRaw()
Returns the internal (raw) representation of this.
|
double |
toSeconds()
Returns this in seconds.
|
String |
toString() |
static void |
writeExternal(Optional<ElapsedTime> elapsedTime,
ObjectOutput destination)
Writes out an external representation of an elapsed time.
|
public static final ElapsedTime EMPTY
public static final ElapsedTime HOUR
public static final ElapsedTime INFINITY
public static final String INFINITY_STRING
public static final ElapsedTime INVALID
public static final ElapsedTime MICRO
public static final ElapsedTime MILLI
public static final ElapsedTime MINUTE
public static final ElapsedTime SECOND
@Nonnull @CheckReturnValue public static ElapsedTime fromDataInput(@Nonnull DataInput source) throws IOException
source
- The source.IOException
- When an I/O error occurs.@Nonnull @CheckReturnValue public static ElapsedTime fromDuration(Duration duration)
duration
- The duration.@Nonnull @CheckReturnValue public static ElapsedTime fromMillis(long millis)
millis
- The number of milliseconds.@Nonnull @CheckReturnValue public static ElapsedTime fromNanos(long nanos)
nanos
- The number of nanoseconds.@Nonnull @CheckReturnValue public static ElapsedTime fromRaw(long raw)
raw
- The internal (raw) representation.@Nonnull @CheckReturnValue public static ElapsedTime fromSeconds(double seconds)
seconds
- The number of seconds.@Nonnull @CheckReturnValue public static Optional<ElapsedTime> fromString(@Nonnull Optional<String> string)
A null or empty string will return null.
string
- The optional string representation.@Nonnull @CheckReturnValue public static ElapsedTime fromString(@Nonnull String elapsedString)
elapsedString
- The string representation.@Nonnull @CheckReturnValue public static ElapsedTime max(@Nonnull Collection<ElapsedTime> elapsedTimes)
Note: a null value is considered infinite.
elapsedTimes
- The ElapsedTime instances.@Nonnull @CheckReturnValue public static ElapsedTime max(@Nonnull ElapsedTime... elapsedTimes)
Note: a null value is considered infinite.
elapsedTimes
- The ElapsedTime instances.@Nonnull @CheckReturnValue public static ElapsedTime min(@Nonnull Collection<ElapsedTime> elapsedTimes)
Note: a null value is considered infinite.
elapsedTimes
- The ElapsedTime instances.@Nonnull @CheckReturnValue public static ElapsedTime min(@Nonnull ElapsedTime... elapsedTimes)
Note: a null value is considered infinite.
elapsedTimes
- The ElapsedTime instances.@Nonnull @CheckReturnValue public static Optional<ElapsedTime> readExternal(@Nonnull ObjectInput source) throws IOException
This is a helper method for
Externalizable
objects containing an
ElapsedTime.
source
- The source.IOException
- When an I/O error occurs.public static void writeExternal(@Nonnull Optional<ElapsedTime> elapsedTime, @Nonnull ObjectOutput destination) throws IOException
This is a helper method for
Externalizable
objects containing an
ElapsedTime.
elapsedTime
- The elapsed time (may be empty).destination
- The destination.IOException
- When an I/O error occurs.@Nonnull @CheckReturnValue public ElapsedTime add(@Nonnull ElapsedTime other)
other
- The other elapsed time.public int compareTo(@Nonnull ElapsedTime other)
compareTo
in interface Comparable<ElapsedTime>
public boolean equals(Object other)
equals
in class Object
@Nonnull @CheckReturnValue public ElapsedTime floor(@Nonnull ElapsedTime whole)
whole
- An elapsed time representing a whole value.@Nonnull @CheckReturnValue public ElapsedTime floor(long whole)
whole
- The number of 100 nanoseconds representing a whole value.public int hashCode()
hashCode
in class Object
@CheckReturnValue public boolean isEmpty()
@CheckReturnValue public boolean isInfinity()
@CheckReturnValue public boolean isInvalid()
@Nonnull @CheckReturnValue public ElapsedTime max(@Nonnull Optional<ElapsedTime> other)
Note: an empty value is considered infinite.
other
- The other.@Nonnull @CheckReturnValue public ElapsedTime min(@Nonnull Optional<ElapsedTime> other)
Note: an empty value is considered infinite.
other
- The other.@Nonnull @CheckReturnValue public ElapsedTime mul(double factor)
factor
- The factor.@Nonnull @CheckReturnValue public ElapsedTime mul(long factor)
factor
- The factor.@CheckReturnValue public double ratio(@Nonnull ElapsedTime divisor)
divisor
- The other elapsed time.@CheckReturnValue public double scaled(@Nonnull ElapsedTime whole)
whole
- An elapsed time representing a whole value.@CheckReturnValue public double scaled(long whole)
whole
- The number of 100 nanoseconds representing a whole value.@Nonnull @CheckReturnValue public ElapsedTime sub(@Nonnull ElapsedTime other)
Subtracting from infinity always results in infinity.
Subtracting infinity from non infinity always results in none.
The substraction results in the absolute value of the time difference.
other
- The other elapsed time.public void toDataOutput(@Nonnull DataOutput destination) throws IOException
destination
- The destination.IOException
- On I/O exception.@Nonnull @CheckReturnValue public Duration toDuration()
@Nonnull @CheckReturnValue public String toDurationString()
@Nonnegative @CheckReturnValue public long toMillis()
@Nonnegative @CheckReturnValue public long toRaw()
@Nonnegative @CheckReturnValue public double toSeconds()
public String toString()
toString
in class Object
Copyright © 2003-2019 Serge Brisson. All Rights Reserved.