public abstract class BaseSingleFieldPeriod extends Object implements ReadablePeriod, Comparable, Serializable
This class should generally not be used directly by API users.
The ReadablePeriod
interface should be used when different
kinds of period objects are to be referenced.
BaseSingleFieldPeriod subclasses may be mutable and not thread-safe.
Modifier | Constructor and Description |
---|---|
protected |
BaseSingleFieldPeriod(int period)
Creates a new instance representing the specified period.
|
Modifier and Type | Method and Description |
---|---|
protected static int |
between(ReadableInstant start,
ReadableInstant end,
DurationFieldType field)
Calculates the number of whole units between the two specified datetimes.
|
protected static int |
between(ReadablePartial start,
ReadablePartial end,
ReadablePeriod zeroInstance)
Calculates the number of whole units between the two specified partial datetimes.
|
int |
compareTo(Object other)
Compares this period to another object of the same class.
|
boolean |
equals(Object period)
Compares this object with the specified object for equality based on the
value of each field.
|
int |
get(DurationFieldType type)
Gets the value of a duration field represented by this period.
|
abstract DurationFieldType |
getFieldType()
Gets the single duration field type.
|
DurationFieldType |
getFieldType(int index)
Gets the field type at the specified index.
|
abstract PeriodType |
getPeriodType()
Gets the period type which matches the duration field type.
|
protected int |
getValue()
Gets the amount of this period.
|
int |
getValue(int index)
Gets the value at the specified index.
|
int |
hashCode()
Gets a hash code for the period as defined by ReadablePeriod.
|
boolean |
isSupported(DurationFieldType type)
Checks whether the duration field specified is supported by this period.
|
protected void |
setValue(int value)
Sets the amount of this period.
|
int |
size()
Gets the number of fields that this period supports, which is one.
|
protected static int |
standardPeriodIn(ReadablePeriod period,
long millisPerUnit)
Creates a new instance representing the number of complete standard length units
in the specified period.
|
MutablePeriod |
toMutablePeriod()
Get this object as a
MutablePeriod . |
Period |
toPeriod()
Get this period as an immutable
Period object. |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
toString
protected BaseSingleFieldPeriod(int period)
period
- the period to representprotected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field)
start
- the start instant, validated to not be nullend
- the end instant, validated to not be nullfield
- the field type to use, must not be nullIllegalArgumentException
- if the instants are null or invalidprotected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance)
The two partials must contain the same fields, for example you can specify
two LocalDate
objects.
start
- the start partial date, validated to not be nullend
- the end partial date, validated to not be nullzeroInstance
- the zero instance constant, must not be nullIllegalArgumentException
- if the partials are null or invalidprotected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit)
This factory method converts all fields from the period to hours using standardised durations for each field. Only those fields which have a precise duration in the ISO UTC chronology can be converted.
period
- the period to get the number of hours from, must not be nullmillisPerUnit
- the number of milliseconds in one standard unit of this periodIllegalArgumentException
- if the period contains imprecise duration valuesprotected int getValue()
protected void setValue(int value)
value
- the period valuepublic abstract DurationFieldType getFieldType()
public abstract PeriodType getPeriodType()
getPeriodType
in interface ReadablePeriod
public int size()
size
in interface ReadablePeriod
public DurationFieldType getFieldType(int index)
The only index supported by this period is zero which returns the field type of this class.
getFieldType
in interface ReadablePeriod
index
- the index to retrieve, which must be zeroIndexOutOfBoundsException
- if the index is invalidpublic int getValue(int index)
The only index supported by this period is zero.
getValue
in interface ReadablePeriod
index
- the index to retrieve, which must be zeroIndexOutOfBoundsException
- if the index is invalidpublic int get(DurationFieldType type)
If the field type specified does not match the type used by this class then zero is returned.
get
in interface ReadablePeriod
type
- the field type to query, null returns zeropublic boolean isSupported(DurationFieldType type)
isSupported
in interface ReadablePeriod
type
- the type to check, may be null which returns falsepublic Period toPeriod()
Period
object.
The period will use PeriodType.standard()
.toPeriod
in interface ReadablePeriod
Period
representing the same number of dayspublic MutablePeriod toMutablePeriod()
MutablePeriod
.
This will always return a new MutablePeriod
with the same fields.
The period will use PeriodType.standard()
.
toMutablePeriod
in interface ReadablePeriod
public boolean equals(Object period)
PeriodType
can return true.equals
in interface ReadablePeriod
equals
in class Object
period
- a readable period to check againstpublic int hashCode()
hashCode
in interface ReadablePeriod
hashCode
in class Object
public int compareTo(Object other)
compareTo
in interface Comparable
other
- the other period, must not be nullNullPointerException
- if the other period is nullClassCastException
- if the other period is of a different typeCopyright © 2012 JBoss by Red Hat. All Rights Reserved.