This class is used by applications seeking to handle dates in non-ISO calendar systems. For example, the Japanese, Minguo, Thai Buddhist and others.
Implementation Specification
This class is immutable nad thread-safe.
Modifier and Type | Field and Description |
---|---|
private final Chronology | chrono
The chronology. |
pack-priv final int | days
The number of days. |
pack-priv final int | months
The number of months. |
private static final long | serialVersionUID
Serialization version. |
private static final List | SUPPORTED_UNITS
The set of supported units. |
pack-priv final int | years
The number of years. |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
public Temporal | addTo(Temporal
the temporal object to adjust, not null temporal)Implements java. Adds this period to the specified temporal object. |
public boolean | equals(Object
the object to check, null returns false obj)Overrides java. Implements java. Checks if this period is equal to another period, including the chronology. |
public long | get(TemporalUnit
the unit)TemporalUnit for which to return the valueImplements java. Gets the value of the requested unit. |
public Chronology | getChronology()
Implements java. Gets the chronology that defines the meaning of the supported units. |
public List | getUnits()
Implements java. Gets the set of units supported by this period. |
public int | hashCode()
Overrides java. Implements java. A hash code for this period. |
public boolean | isNegative()
Overrides default java. Checks if any of the supported units of this period are negative. |
public boolean | isZero()
Overrides default java. Checks if all the supported units of this period are zero. |
public ChronoPeriod | minus(TemporalAmount
the period to subtract, not null amountToSubtract)Implements java. Returns a copy of this period with the specified period subtracted. |
private long | |
public ChronoPeriod | multipliedBy(int
the scalar to multiply by, not null scalar)Implements java. Returns a new instance with each amount in this period in this period multiplied by the specified scalar. |
public ChronoPeriod | normalized()
Implements java. Returns a copy of this period with the amounts of each unit normalized. |
public ChronoPeriod | plus(TemporalAmount
the period to add, not null amountToAdd)Implements java. Returns a copy of this period with the specified period added. |
pack-priv static ChronoPeriodImpl | |
private void | |
public Temporal | subtractFrom(Temporal
the temporal object to adjust, not null temporal)Implements java. Subtracts this period from the specified temporal object. |
public String | toString()
Overrides java. Implements java. Outputs this period as a |
private ChronoPeriodImpl | Returns: the period, not nullthe temporal amount to convert, not null amount)Obtains an instance of |
private void | |
pack-priv void | |
protected Object | Returns: the instance ofSer , not nullWrites the Chronology using a dedicated serialized form. |
chrono | back to summary |
---|---|
private final Chronology chrono The chronology.
|
days | back to summary |
---|---|
pack-priv final int days The number of days. |
months | back to summary |
---|---|
pack-priv final int months The number of months. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Serialization version. |
SUPPORTED_UNITS | back to summary |
---|---|
private static final List<TemporalUnit> SUPPORTED_UNITS The set of supported units. |
years | back to summary |
---|---|
pack-priv final int years The number of years. |
ChronoPeriodImpl | back to summary |
---|---|
pack-priv ChronoPeriodImpl(Chronology chrono, int years, int months, int days) Creates an instance. |
addTo | back to summary |
---|---|
public Temporal addTo(Temporal temporal) Implements java. Doc from java. Adds this period to the specified temporal object. This returns a temporal object of the same observable type as the input with this period added.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisPeriod.addTo(dateTime); dateTime = dateTime.plus(thisPeriod); The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units added. This instance is immutable and unaffected by this method call. |
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Implements java. Doc from java. Checks if this period is equal to another period, including the chronology. Compares this period with another ensuring that the type, each amount and the chronology are the same. Note that this means that a period of "15 Months" is not equal to a period of "1 Year and 3 Months". |
get | back to summary |
---|---|
public long get(TemporalUnit unit) Implements java. Doc from java. Gets the value of the requested unit.
The supported units are chronology specific.
They will typically be
|
getChronology | back to summary |
---|---|
public Chronology getChronology() Implements java. Doc from java. Gets the chronology that defines the meaning of the supported units.
The period is defined by the chronology.
It controls the supported units and restricts addition/subtraction
to
|
getUnits | back to summary |
---|---|
public List Implements java. Doc from java. Gets the set of units supported by this period.
The supported units are chronology specific.
They will typically be
This set can be used in conjunction with
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Implements java. Doc from java. A hash code for this period.
|
isNegative | back to summary |
---|---|
public boolean isNegative() Overrides default java. Doc from java. Checks if any of the supported units of this period are negative.
|
isZero | back to summary |
---|---|
public boolean isZero() Overrides default java. Doc from java. Checks if all the supported units of this period are zero.
|
minus | back to summary |
---|---|
public ChronoPeriod minus(TemporalAmount amountToSubtract) Implements java. Doc from java. Returns a copy of this period with the specified period subtracted.
If the specified amount is a This instance is immutable and unaffected by this method call.
|
monthRange | back to summary |
---|---|
private long monthRange() Calculates the range of months.
|
multipliedBy | back to summary |
---|---|
public ChronoPeriod multipliedBy(int scalar) Implements java. Doc from java. Returns a new instance with each amount in this period in this period multiplied by the specified scalar. This returns a period with each supported unit individually multiplied. For example, a period of "2 years, -3 months and 4 days" multiplied by 3 will return "6 years, -9 months and 12 days". No normalization is performed.
|
normalized | back to summary |
---|---|
public ChronoPeriod normalized() Implements java. Doc from java. Returns a copy of this period with the amounts of each unit normalized. The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, such that "15 months" would be normalized to "1 year and 3 months". This instance is immutable and unaffected by this method call.
|
plus | back to summary |
---|---|
public ChronoPeriod plus(TemporalAmount amountToAdd) Implements java. Doc from java. Returns a copy of this period with the specified period added.
If the specified amount is a This instance is immutable and unaffected by this method call.
|
readExternal | back to summary |
---|---|
pack-priv static ChronoPeriodImpl readExternal(DataInput in) throws IOException |
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ObjectStreamException Defend against malicious streams.
|
subtractFrom | back to summary |
---|---|
public Temporal subtractFrom(Temporal temporal) Implements java. Doc from java. Subtracts this period from the specified temporal object. This returns a temporal object of the same observable type as the input with this period subtracted.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisPeriod.subtractFrom(dateTime); dateTime = dateTime.minus(thisPeriod); The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units subtracted. This instance is immutable and unaffected by this method call. |
toString | back to summary |
---|---|
public String toString() Overrides java. Implements java. Doc from java. Outputs this period as a The output will include the period amounts and chronology. |
validateAmount | back to summary |
---|---|
private ChronoPeriodImpl validateAmount(TemporalAmount amount) Obtains an instance of
|
validateChrono | back to summary |
---|---|
private void validateChrono(TemporalAccessor temporal) Validates that the temporal has the correct chronology. |
writeExternal | back to summary |
---|---|
pack-priv void writeExternal(DataOutput out) throws IOException |
writeReplace | back to summary |
---|---|
protected Object writeReplace() Writes the Chronology using a dedicated serialized form. out.writeByte(12); // identifies this as a ChronoPeriodImpl out.writeUTF(getId()); // the chronology out.writeInt(years); out.writeInt(months); out.writeInt(days); |