public abstract class AbstractDuration extends Object implements ReadableDuration
This class should generally not be used directly by API users. The
ReadableDuration
interface should be used when different
kinds of durations are to be referenced.
AbstractDuration subclasses may be mutable and not thread-safe.
Modifier | Constructor and Description |
---|---|
protected |
AbstractDuration()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object obj)
Compares this duration with the specified duration based on length.
|
boolean |
equals(Object duration)
Compares this object with the specified object for equality based
on the millisecond length.
|
int |
hashCode()
Gets a hash code for the duration that is compatible with the
equals method.
|
boolean |
isEqual(ReadableDuration duration)
Is the length of this duration equal to the duration passed in.
|
boolean |
isLongerThan(ReadableDuration duration)
Is the length of this duration longer than the duration passed in.
|
boolean |
isShorterThan(ReadableDuration duration)
Is the length of this duration shorter than the duration passed in.
|
Duration |
toDuration()
Get this duration as an immutable
Duration object. |
Period |
toPeriod()
Converts this duration to a Period instance using the standard period type
and the ISO chronology.
|
String |
toString()
Gets the value as a String in the ISO8601 duration format including
only seconds and milliseconds.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getMillis
public Duration toDuration()
Duration
object.toDuration
in interface ReadableDuration
public Period toPeriod()
Only precise fields in the period type will be used. Thus, only the hour, minute, second and millisecond fields on the period will be used. The year, month, week and day fields will not be populated.
If the duration is small, less than one day, then this method will perform as you might expect and split the fields evenly. If the duration is larger than one day then all the remaining duration will be stored in the largest available field, hours in this case.
For example, a duration effectively equal to (365 + 60 + 5) days will be converted to ((365 + 60 + 5) * 24) hours by this constructor.
For more control over the conversion process, you must pair the duration with
an instant, see Period.Period(ReadableInstant,ReadableDuration)
.
toPeriod
in interface ReadableDuration
public int compareTo(Object obj)
compareTo
in interface Comparable
compareTo
in interface ReadableDuration
obj
- a duration to check againstNullPointerException
- if the object is nullClassCastException
- if the given object is not supportedpublic boolean isEqual(ReadableDuration duration)
isEqual
in interface ReadableDuration
duration
- another duration to compare to, null means zero millisecondspublic boolean isLongerThan(ReadableDuration duration)
isLongerThan
in interface ReadableDuration
duration
- another duration to compare to, null means zero millisecondspublic boolean isShorterThan(ReadableDuration duration)
isShorterThan
in interface ReadableDuration
duration
- another duration to compare to, null means zero millisecondspublic boolean equals(Object duration)
equals
in interface ReadableDuration
equals
in class Object
duration
- a readable duration to check againstpublic int hashCode()
hashCode
in interface ReadableDuration
hashCode
in class Object
public String toString()
For example, "PT72.345S" represents 1 minute, 12 seconds and 345 milliseconds.
For more control over the output, see
PeriodFormatterBuilder
.
toString
in interface ReadableDuration
toString
in class Object
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.