public abstract class BasePeriod extends AbstractPeriod implements ReadablePeriod, Serializable
PeriodType
and an int[]
.
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.
BasePeriod subclasses may be mutable and not thread-safe.
Modifier | Constructor and Description |
---|---|
protected |
BasePeriod(int[] values,
PeriodType type)
Constructor used when we trust ourselves.
|
protected |
BasePeriod(int years,
int months,
int weeks,
int days,
int hours,
int minutes,
int seconds,
int millis,
PeriodType type)
Creates a period from a set of field values.
|
protected |
BasePeriod(long startInstant,
long endInstant,
PeriodType type,
Chronology chrono)
Creates a period from the given interval endpoints.
|
protected |
BasePeriod(long duration,
PeriodType type,
Chronology chrono)
Creates a period from the given millisecond duration, which is only really
suitable for durations less than one day.
|
protected |
BasePeriod(Object period,
PeriodType type,
Chronology chrono)
Creates a new period based on another using the
ConverterManager . |
protected |
BasePeriod(ReadableDuration duration,
ReadableInstant endInstant,
PeriodType type)
Creates a period from the given duration and end point.
|
protected |
BasePeriod(ReadableInstant startInstant,
ReadableDuration duration,
PeriodType type)
Creates a period from the given start point and duration.
|
protected |
BasePeriod(ReadableInstant startInstant,
ReadableInstant endInstant,
PeriodType type)
Creates a period from the given interval endpoints.
|
protected |
BasePeriod(ReadablePartial start,
ReadablePartial end,
PeriodType type)
Creates a period from the given duration and end point.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addField(DurationFieldType field,
int value)
Adds the value of a field in this period.
|
protected void |
addFieldInto(int[] values,
DurationFieldType field,
int value)
Adds the value of a field in this period.
|
protected void |
addPeriod(ReadablePeriod period)
Adds the fields from another period.
|
protected int[] |
addPeriodInto(int[] values,
ReadablePeriod period)
Adds the fields from another period.
|
protected PeriodType |
checkPeriodType(PeriodType type)
Validates a period type, converting nulls to a default value and
checking the type is suitable for this instance.
|
DurationFieldType |
getFieldType(int index)
Gets the field type at the specified index.
|
PeriodType |
getPeriodType()
Gets the period type.
|
int |
getValue(int index)
Gets the value at the specified index.
|
protected void |
mergePeriod(ReadablePeriod period)
Merges the fields from another period.
|
protected int[] |
mergePeriodInto(int[] values,
ReadablePeriod period)
Merges the fields from another period.
|
protected void |
setField(DurationFieldType field,
int value)
Sets the value of a field in this period.
|
protected void |
setFieldInto(int[] values,
DurationFieldType field,
int value)
Sets the value of a field in this period.
|
protected void |
setPeriod(int years,
int months,
int weeks,
int days,
int hours,
int minutes,
int seconds,
int millis)
Sets the eight standard the fields in one go.
|
protected void |
setPeriod(ReadablePeriod period)
Sets all the fields of this period from another.
|
protected void |
setValue(int index,
int value)
Sets the value of the field at the specifed index.
|
protected void |
setValues(int[] values)
Sets the values of all fields.
|
int |
size()
Gets the number of fields that this period supports.
|
Duration |
toDurationFrom(ReadableInstant startInstant)
Gets the total millisecond duration of this period relative to a start instant.
|
Duration |
toDurationTo(ReadableInstant endInstant)
Gets the total millisecond duration of this period relative to an
end instant.
|
equals, get, getFieldTypes, getValues, hashCode, indexOf, isSupported, toMutablePeriod, toPeriod, toString, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
equals, get, hashCode, isSupported, toMutablePeriod, toPeriod, toString
protected BasePeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis, PeriodType type)
years
- amount of years in this period, which must be zero if unsupportedmonths
- amount of months in this period, which must be zero if unsupportedweeks
- amount of weeks in this period, which must be zero if unsupporteddays
- amount of days in this period, which must be zero if unsupportedhours
- amount of hours in this period, which must be zero if unsupportedminutes
- amount of minutes in this period, which must be zero if unsupportedseconds
- amount of seconds in this period, which must be zero if unsupportedmillis
- amount of milliseconds in this period, which must be zero if unsupportedtype
- which set of fields this period supportsIllegalArgumentException
- if period type is invalidIllegalArgumentException
- if an unsupported field's value is non-zeroprotected BasePeriod(long startInstant, long endInstant, PeriodType type, Chronology chrono)
startInstant
- interval start, in millisecondsendInstant
- interval end, in millisecondstype
- which set of fields this period supports, null means standardchrono
- the chronology to use, null means ISO defaultIllegalArgumentException
- if period type is invalidprotected BasePeriod(ReadableInstant startInstant, ReadableInstant endInstant, PeriodType type)
startInstant
- interval start, null means nowendInstant
- interval end, null means nowtype
- which set of fields this period supports, null means standardIllegalArgumentException
- if period type is invalidprotected BasePeriod(ReadablePartial start, ReadablePartial end, PeriodType type)
The two partials must contain the same fields, thus you can
specify two LocalDate
objects, or two LocalTime
objects, but not one of each.
As these are Partial objects, time zones have no effect on the result.
The two partials must also both be contiguous - see
DateTimeUtils.isContiguous(ReadablePartial)
for a
definition. Both LocalDate
and LocalTime
are contiguous.
start
- the start of the period, must not be nullend
- the end of the period, must not be nulltype
- which set of fields this period supports, null means standardIllegalArgumentException
- if the partials are null or invalidprotected BasePeriod(ReadableInstant startInstant, ReadableDuration duration, PeriodType type)
startInstant
- the interval start, null means nowduration
- the duration of the interval, null means zero-lengthtype
- which set of fields this period supports, null means standardprotected BasePeriod(ReadableDuration duration, ReadableInstant endInstant, PeriodType type)
duration
- the duration of the interval, null means zero-lengthendInstant
- the interval end, null means nowtype
- which set of fields this period supports, null means standardprotected BasePeriod(long duration, PeriodType type, Chronology chrono)
Only fields that are precise will be used. Thus the largest precise field may have a large value.
duration
- the duration, in millisecondstype
- which set of fields this period supports, null means standardchrono
- the chronology to use, null means ISO defaultIllegalArgumentException
- if period type is invalidprotected BasePeriod(Object period, PeriodType type, Chronology chrono)
ConverterManager
.period
- the period to converttype
- which set of fields this period supports, null means use type from objectchrono
- the chronology to use, null means ISO defaultIllegalArgumentException
- if period is invalidIllegalArgumentException
- if an unsupported field's value is non-zeroprotected BasePeriod(int[] values, PeriodType type)
values
- the values to use, not null, not clonedtype
- which set of fields this period supports, not nullprotected PeriodType checkPeriodType(PeriodType type)
type
- the type to check, may be nullIllegalArgumentException
- if the period type is invalidpublic PeriodType getPeriodType()
getPeriodType
in interface ReadablePeriod
public int size()
size
in interface ReadablePeriod
public DurationFieldType getFieldType(int index)
getFieldType
in interface ReadablePeriod
index
- the index to retrieveIndexOutOfBoundsException
- if the index is invalidpublic int getValue(int index)
getValue
in interface ReadablePeriod
index
- the index to retrieveIndexOutOfBoundsException
- if the index is invalidpublic Duration toDurationFrom(ReadableInstant startInstant)
This method adds the period to the specified instant in order to calculate the duration.
An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.
startInstant
- the instant to add the period to, thus obtaining the durationArithmeticException
- if the millis exceeds the capacity of the durationpublic Duration toDurationTo(ReadableInstant endInstant)
This method subtracts the period from the specified instant in order to calculate the duration.
An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.
endInstant
- the instant to subtract the period from, thus obtaining the durationArithmeticException
- if the millis exceeds the capacity of the durationprotected void setPeriod(ReadablePeriod period)
period
- the period to copy from, not nullIllegalArgumentException
- if an unsupported field's value is non-zeroprotected void setPeriod(int years, int months, int weeks, int days, int hours, int minutes, int seconds, int millis)
years
- amount of years in this period, which must be zero if unsupportedmonths
- amount of months in this period, which must be zero if unsupportedweeks
- amount of weeks in this period, which must be zero if unsupporteddays
- amount of days in this period, which must be zero if unsupportedhours
- amount of hours in this period, which must be zero if unsupportedminutes
- amount of minutes in this period, which must be zero if unsupportedseconds
- amount of seconds in this period, which must be zero if unsupportedmillis
- amount of milliseconds in this period, which must be zero if unsupportedIllegalArgumentException
- if an unsupported field's value is non-zeroprotected void setField(DurationFieldType field, int value)
field
- the field to setvalue
- the value to setIllegalArgumentException
- if field is is null or not supported.protected void setFieldInto(int[] values, DurationFieldType field, int value)
values
- the array of values to updatefield
- the field to setvalue
- the value to setIllegalArgumentException
- if field is null or not supported.protected void addField(DurationFieldType field, int value)
field
- the field to setvalue
- the value to setIllegalArgumentException
- if field is is null or not supported.protected void addFieldInto(int[] values, DurationFieldType field, int value)
values
- the array of values to updatefield
- the field to setvalue
- the value to setIllegalArgumentException
- if field is is null or not supported.protected void mergePeriod(ReadablePeriod period)
period
- the period to add from, not nullIllegalArgumentException
- if an unsupported field's value is non-zeroprotected int[] mergePeriodInto(int[] values, ReadablePeriod period)
values
- the array of values to updateperiod
- the period to add from, not nullIllegalArgumentException
- if an unsupported field's value is non-zeroprotected void addPeriod(ReadablePeriod period)
period
- the period to add from, not nullIllegalArgumentException
- if an unsupported field's value is non-zeroprotected int[] addPeriodInto(int[] values, ReadablePeriod period)
values
- the array of values to updateperiod
- the period to add from, not nullIllegalArgumentException
- if an unsupported field's value is non-zeroprotected void setValue(int index, int value)
index
- the indexvalue
- the value to setIndexOutOfBoundsException
- if the index is invalidprotected void setValues(int[] values)
values
- the array of valuesCopyright © 2012 JBoss by Red Hat. All Rights Reserved.