Interface PeriodProvider
- All Known Implementing Classes:
Period
,PeriodField
,PeriodFields
PeriodProvider is a simple interface that provides uniform access to any object that can provide access to a period.
The implementation of PeriodProvider
may be mutable.
The result of toPeriodFields()
, however, is immutable.
When implementing an API that accepts a PeriodProvider
as a parameter,
it is important to convert the input to a PeriodFields
once and once only.
It is recommended that this is done at the top of the method before other processing.
This is necessary to handle the case where the implementation of the provider is
mutable and changes in value between two calls to toPeriodFields()
.
The recommended way to convert a DateProvider to a LocalDate is using
PeriodFields.of(PeriodProvider)
as this method provides additional null checking.
PeriodProvider makes no guarantees about the thread-safety or immutability of implementations.
-
Method Summary
Modifier and TypeMethodDescriptionReturns an instance ofPeriodFields
initialized from the state of this object.
-
Method Details
-
toPeriodFields
PeriodFields toPeriodFields()Returns an instance ofPeriodFields
initialized from the state of this object.This method will take the period represented by this object and return an equivalent
PeriodFields
. The amount stored for a unit in the result may be zero. If this object is already aPeriodFields
then it is simply returned.Implementations must ensure that this method provides a thread-safe consistent result. An immutable implementation will naturally provide this guarantee.
- Returns:
- the period equivalent to this one, never null
-