Interface PeriodProvider
-
- All Known Implementing Classes:
Period
,PeriodField
,PeriodFields
public interface PeriodProvider
Provides access to a period of time, such as '2 Years and 5 Months'.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 oftoPeriodFields()
, however, is immutable.When implementing an API that accepts a
PeriodProvider
as a parameter, it is important to convert the input to aPeriodFields
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 totoPeriodFields()
.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.
- Author:
- Stephen Colebourne
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description PeriodFields
toPeriodFields()
Returns an instance ofPeriodFields
initialized from the state of this object.
-
-
-
Method Detail
-
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
-
-