Class ChronoPeriodImpl
- java.lang.Object
-
- org.threeten.bp.chrono.ChronoPeriod
-
- org.threeten.bp.chrono.ChronoPeriodImpl
-
- All Implemented Interfaces:
java.io.Serializable,TemporalAmount
final class ChronoPeriodImpl extends ChronoPeriod implements java.io.Serializable
An implementation ofChronoPeriod.
-
-
Field Summary
Fields Modifier and Type Field Description private Chronologychronologyprivate intdaysprivate intmonthsprivate static longserialVersionUIDSerialization version.private intyears
-
Constructor Summary
Constructors Constructor Description ChronoPeriodImpl(Chronology chronology, int years, int months, int days)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TemporaladdTo(Temporal temporal)Adds this period to the specified temporal object.booleanequals(java.lang.Object obj)Checks if this period is equal to another period, including the chronology.longget(TemporalUnit unit)Gets the value of the requested unit.ChronologygetChronology()Gets the chronology that defines the meaning of the supported units.java.util.List<TemporalUnit>getUnits()Gets the set of units supported by this period.inthashCode()A hash code for this period.ChronoPeriodminus(TemporalAmount amountToSubtract)Returns a copy of this period with the specified period subtracted.ChronoPeriodmultipliedBy(int scalar)Returns a new instance with each amount in this period in this period multiplied by the specified scalar.ChronoPeriodnormalized()Returns a copy of this period with the amounts of each unit normalized.ChronoPeriodplus(TemporalAmount amountToAdd)Returns a copy of this period with the specified period added.TemporalsubtractFrom(Temporal temporal)Subtracts this period from the specified temporal object.java.lang.StringtoString()Outputs this period as aString.-
Methods inherited from class org.threeten.bp.chrono.ChronoPeriod
between, isNegative, isZero, negated
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization version.- See Also:
- Constant Field Values
-
chronology
private final Chronology chronology
-
years
private final int years
-
months
private final int months
-
days
private final int days
-
-
Constructor Detail
-
ChronoPeriodImpl
public ChronoPeriodImpl(Chronology chronology, int years, int months, int days)
-
-
Method Detail
-
get
public long get(TemporalUnit unit)
Description copied from class:ChronoPeriodGets the value of the requested unit.The supported units are chronology specific. They will typically be
YEARS,MONTHSandDAYS. Requesting an unsupported unit will throw an exception.- Specified by:
getin interfaceTemporalAmount- Specified by:
getin classChronoPeriod- Parameters:
unit- theTemporalUnitfor which to return the value- Returns:
- the long value of the unit
-
getUnits
public java.util.List<TemporalUnit> getUnits()
Description copied from class:ChronoPeriodGets the set of units supported by this period.The supported units are chronology specific. They will typically be
YEARS,MONTHSandDAYS. They are returned in order from largest to smallest.This set can be used in conjunction with
ChronoPeriod.get(TemporalUnit)to access the entire state of the period.- Specified by:
getUnitsin interfaceTemporalAmount- Specified by:
getUnitsin classChronoPeriod- Returns:
- a list containing the supported units, not null
-
getChronology
public Chronology getChronology()
Description copied from class:ChronoPeriodGets 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
ChronoLocalDateinstances of the same chronology.- Specified by:
getChronologyin classChronoPeriod- Returns:
- the chronology defining the period, not null
-
plus
public ChronoPeriod plus(TemporalAmount amountToAdd)
Description copied from class:ChronoPeriodReturns a copy of this period with the specified period added.If the specified amount is a
ChronoPeriodthen it must have the same chronology as this period. Implementations may choose to accept or reject otherTemporalAmountimplementations.This instance is immutable and unaffected by this method call.
- Specified by:
plusin classChronoPeriod- Parameters:
amountToAdd- the period to add, not null- Returns:
- a
ChronoPeriodbased on this period with the requested period added, not null
-
minus
public ChronoPeriod minus(TemporalAmount amountToSubtract)
Description copied from class:ChronoPeriodReturns a copy of this period with the specified period subtracted.If the specified amount is a
ChronoPeriodthen it must have the same chronology as this period. Implementations may choose to accept or reject otherTemporalAmountimplementations.This instance is immutable and unaffected by this method call.
- Specified by:
minusin classChronoPeriod- Parameters:
amountToSubtract- the period to subtract, not null- Returns:
- a
ChronoPeriodbased on this period with the requested period subtracted, not null
-
multipliedBy
public ChronoPeriod multipliedBy(int scalar)
Description copied from class:ChronoPeriodReturns 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.
- Specified by:
multipliedByin classChronoPeriod- Parameters:
scalar- the scalar to multiply by, not null- Returns:
- a
ChronoPeriodbased on this period with the amounts multiplied by the scalar, not null
-
normalized
public ChronoPeriod normalized()
Description copied from class:ChronoPeriodReturns 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.
- Specified by:
normalizedin classChronoPeriod- Returns:
- a
ChronoPeriodbased on this period with the amounts of each unit normalized, not null
-
addTo
public Temporal addTo(Temporal temporal)
Description copied from class:ChronoPeriodAdds 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
Temporal.plus(TemporalAmount).// 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.
- Specified by:
addToin interfaceTemporalAmount- Specified by:
addToin classChronoPeriod- Parameters:
temporal- the temporal object to adjust, not null- Returns:
- an object of the same type with the adjustment made, not null
-
subtractFrom
public Temporal subtractFrom(Temporal temporal)
Description copied from class:ChronoPeriodSubtracts 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
Temporal.minus(TemporalAmount).// 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.
- Specified by:
subtractFromin interfaceTemporalAmount- Specified by:
subtractFromin classChronoPeriod- Parameters:
temporal- the temporal object to adjust, not null- Returns:
- an object of the same type with the adjustment made, not null
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:ChronoPeriodChecks 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".
- Specified by:
equalsin classChronoPeriod- Parameters:
obj- the object to check, null returns false- Returns:
- true if this is equal to the other period
-
hashCode
public int hashCode()
Description copied from class:ChronoPeriodA hash code for this period.- Specified by:
hashCodein classChronoPeriod- Returns:
- a suitable hash code
-
toString
public java.lang.String toString()
Description copied from class:ChronoPeriodOutputs this period as aString.The output will include the period amounts and chronology.
- Specified by:
toStringin classChronoPeriod- Returns:
- a string representation of this period, not null
-
-