|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.time.base.BaseSingleFieldPeriod
public abstract class BaseSingleFieldPeriod
BaseSingleFieldPeriod is an abstract implementation of ReadablePeriod that manages a single duration field, such as days or minutes.
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.
Constructor Summary | |
---|---|
protected |
BaseSingleFieldPeriod(int period)
Creates a new instance representing the specified period. |
Method Summary | |
---|---|
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(BaseSingleFieldPeriod 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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.joda.time.ReadablePeriod |
---|
toString |
Constructor Detail |
---|
protected BaseSingleFieldPeriod(int period)
period
- the period to representMethod Detail |
---|
protected 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 null
IllegalArgumentException
- 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 null
IllegalArgumentException
- 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 period
IllegalArgumentException
- 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 zero
IndexOutOfBoundsException
- 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 zero
IndexOutOfBoundsException
- 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 zero
public boolean isSupported(DurationFieldType type)
isSupported
in interface ReadablePeriod
type
- the type to check, may be null which returns false
public 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 against
public int hashCode()
hashCode
in interface ReadablePeriod
hashCode
in class Object
public int compareTo(BaseSingleFieldPeriod other)
compareTo
in interface Comparable<BaseSingleFieldPeriod>
other
- the other period, must not be null
NullPointerException
- if the other period is null
ClassCastException
- if the other period is of a different type
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |