@Immutable public class Duration extends Number implements Comparable<Duration>
Number
subclasses.Modifier and Type | Class and Description |
---|---|
class |
Duration.Components
The atomic components of this duration, broken down into whole hours, minutes and (fractional) seconds.
|
Constructor and Description |
---|
Duration(long nanos)
Create a duration given the number of nanoseconds.
|
Duration(long duration,
TimeUnit unit)
Create a duration and the time unit.
|
Modifier and Type | Method and Description |
---|---|
Duration |
add(Duration duration)
Add the supplied duration to this duration, and return the result.
|
Duration |
add(long duration,
TimeUnit unit)
Add the supplied duration to this duration, and return the result.
|
int |
compareTo(Duration that) |
double |
divide(Duration duration)
Divide the duration by another duration to calculate the ratio.
|
Duration |
divide(long denominator)
Divide the duration by the supplied number, and return the result.
|
double |
doubleValue() |
float |
floatValue() |
Duration.Components |
getComponents()
Return the duration components.
|
long |
getDuratinInNanoseconds()
Return the total duration in nanoseconds.
|
long |
getDuration(TimeUnit unit)
Get the duration value in the supplied unit of time.
|
BigDecimal |
getDurationInMicroseconds()
Return the total duration in microseconds, which may contain a fraction part for the sub-microsecond component.
|
BigDecimal |
getDurationInMilliseconds()
Return the total duration in microseconds, which may contain a fraction part for the sub-microsecond component.
|
BigDecimal |
getDurationInSeconds()
Return the total duration in microseconds, which may contain a fraction part for the sub-microsecond component.
|
int |
intValue() |
long |
longValue() |
Duration |
multiply(long scale)
Multiply the duration by the supplied scale factor, and return the result.
|
Duration |
subtract(Duration duration)
Subtract the supplied duration from this duration, and return the result.
|
Duration |
subtract(long duration,
TimeUnit unit)
Subtract the supplied duration from this duration, and return the result.
|
BigDecimal |
toBigDecimal() |
String |
toSimpleString()
Writes the duration in a form containing hours, minutes, and seconds, excluding the fractional part of the seconds.
|
String |
toString()
Writes the duration in a form containing hours, minutes, and seconds, including the fractional part of the seconds.
|
byteValue, shortValue
public Duration(long nanos)
nanos
- the number of nanoseconds in the durationpublic Duration(long duration, TimeUnit unit)
duration
- the duration in the supplied time unitsunit
- the time unitpublic double doubleValue()
doubleValue
in class Number
public float floatValue()
floatValue
in class Number
public BigDecimal toBigDecimal()
public Duration add(long duration, TimeUnit unit)
duration
- the duration to add to this objectunit
- the unit of the duration being added; may not be nullpublic Duration subtract(long duration, TimeUnit unit)
duration
- the duration to subtract from this objectunit
- the unit of the duration being subtracted; may not be nullpublic Duration add(Duration duration)
duration
- the duration to add to this objectpublic Duration subtract(Duration duration)
duration
- the duration to subtract from this objectpublic Duration multiply(long scale)
scale
- the factor by which the duration is to be scaled.public Duration divide(long denominator)
denominator
- the factor by which the duration is to be divided.public double divide(Duration duration)
duration
- the duration that this duration is to be divided by; may not be nullpublic int compareTo(Duration that)
compareTo
in interface Comparable<Duration>
public long getDuratinInNanoseconds()
public BigDecimal getDurationInMicroseconds()
public BigDecimal getDurationInMilliseconds()
public BigDecimal getDurationInSeconds()
public Duration.Components getComponents()
public long getDuration(TimeUnit unit)
unit
- the unit of time for the returned value; may not be nullpublic String toString()
HHH:MM:SS.mmm,mmm
, where
public String toSimpleString()
HHH:MM:SS
, where
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.