Class PeriodAdjustment
- java.lang.Object
-
- com.opengamma.strata.basics.date.PeriodAdjustment
-
- All Implemented Interfaces:
Resolvable<DateAdjuster>
,Serializable
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class PeriodAdjustment extends Object implements Resolvable<DateAdjuster>, org.joda.beans.ImmutableBean, Serializable
An adjustment that alters a date by adding a period of calendar days, months and years.This adjustment adds a
Period
to the input date using an addition convention, followed by an adjustment to ensure the result is a valid business day.Addition is performed using standard calendar addition. It is not possible to add a number of business days using this class. See
DaysAdjustment
for an alternative that can handle addition of business days.There are two steps in the calculation:
In step one, the period is added using the specified
PeriodAdditionConvention
.In step two, the result of step one is optionally adjusted to be a business day using a
BusinessDayAdjustment
.For example, a rule represented by this class might be: "the end date is 5 years after the start date, with end-of-month rule based on the last business day of the month, adjusted to be a valid London business day using the 'ModifiedFollowing' convention".
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PeriodAdjustment.Builder
The bean-builder forPeriodAdjustment
.static class
PeriodAdjustment.Meta
The meta-bean forPeriodAdjustment
.
-
Field Summary
Fields Modifier and Type Field Description static PeriodAdjustment
NONE
An instance that performs no adjustment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalDate
adjust(LocalDate date, ReferenceData refData)
Adjusts the date, adding the period and then applying the business day adjustment.static PeriodAdjustment.Builder
builder()
Returns a builder used to create an instance of the bean.boolean
equals(Object obj)
PeriodAdditionConvention
getAdditionConvention()
Gets the addition convention to apply.BusinessDayAdjustment
getAdjustment()
Gets the business day adjustment that is performed to the result of the addition.Period
getPeriod()
Gets the period to be added.int
hashCode()
static PeriodAdjustment.Meta
meta()
The meta-bean forPeriodAdjustment
.PeriodAdjustment.Meta
metaBean()
static PeriodAdjustment
of(Period period, PeriodAdditionConvention additionConvention, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period.static PeriodAdjustment
ofLastBusinessDay(Period period, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period using the last business day of month convention.static PeriodAdjustment
ofLastDay(Period period, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period using the last day of month convention.DateAdjuster
resolve(ReferenceData refData)
Resolves this adjustment using the specified reference data, returning an adjuster.PeriodAdjustment.Builder
toBuilder()
Returns a builder that allows this bean to be mutated.String
toString()
Returns a string describing the adjustment.
-
-
-
Field Detail
-
NONE
public static final PeriodAdjustment NONE
An instance that performs no adjustment.
-
-
Method Detail
-
of
public static PeriodAdjustment of(Period period, PeriodAdditionConvention additionConvention, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period.When adjusting a date, the specified period is added to the input date. The business day adjustment will then be used to ensure the result is a valid business day.
- Parameters:
period
- the period to add to the input dateadditionConvention
- the convention used to perform the additionadjustment
- the business day adjustment to apply to the result of the addition- Returns:
- the period adjustment
-
ofLastDay
public static PeriodAdjustment ofLastDay(Period period, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period using the last day of month convention.When adjusting a date, the specified period is added to the input date. The business day adjustment will then be used to ensure the result is a valid business day.
The period must consist only of months and/or years.
- Parameters:
period
- the period to add to the input dateadjustment
- the business day adjustment to apply to the result of the addition- Returns:
- the period adjustment
-
ofLastBusinessDay
public static PeriodAdjustment ofLastBusinessDay(Period period, BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by the specified period using the last business day of month convention.When adjusting a date, the specified period is added to the input date. The business day adjustment will then be used to ensure the result is a valid business day.
The period must consist only of months and/or years.
- Parameters:
period
- the period to add to the input dateadjustment
- the business day adjustment to apply to the result of the addition- Returns:
- the period adjustment
-
adjust
public LocalDate adjust(LocalDate date, ReferenceData refData)
Adjusts the date, adding the period and then applying the business day adjustment.The calculation is performed in two steps.
Step one, use
PeriodAdditionConvention.adjust(LocalDate, Period, HolidayCalendar)
to add the period.Step two, use
BusinessDayAdjustment.adjust(LocalDate, ReferenceData)
to adjust the result of step one.- Parameters:
date
- the date to adjustrefData
- the reference data, used to find the holiday calendar- Returns:
- the adjusted date
-
resolve
public DateAdjuster resolve(ReferenceData refData)
Resolves this adjustment using the specified reference data, returning an adjuster.This returns a
DateAdjuster
that performs the same calculation as this adjustment. It binds the holiday calendar, looked up from the reference data, into the result. As such, there is no need to pass the reference data in again.- Specified by:
resolve
in interfaceResolvable<DateAdjuster>
- Parameters:
refData
- the reference data, used to find the holiday calendar- Returns:
- the adjuster, bound to a specific holiday calendar
-
toString
public String toString()
Returns a string describing the adjustment.
-
meta
public static PeriodAdjustment.Meta meta()
The meta-bean forPeriodAdjustment
.- Returns:
- the meta-bean, not null
-
builder
public static PeriodAdjustment.Builder builder()
Returns a builder used to create an instance of the bean.- Returns:
- the builder, not null
-
metaBean
public PeriodAdjustment.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getPeriod
public Period getPeriod()
Gets the period to be added.When the adjustment is performed, this period will be added to the input date.
- Returns:
- the value of the property, not null
-
getAdditionConvention
public PeriodAdditionConvention getAdditionConvention()
Gets the addition convention to apply.When the adjustment is performed, this convention is used to refine the adjusted date. The most common convention is to move the end date to the last business day of the month if the start date is the last business day of the month.
- Returns:
- the value of the property, not null
-
getAdjustment
public BusinessDayAdjustment getAdjustment()
Gets the business day adjustment that is performed to the result of the addition.This adjustment is applied to the result of the addition calculation.
If no adjustment is required, use the 'None' business day adjustment.
- Returns:
- the value of the property, not null
-
toBuilder
public PeriodAdjustment.Builder toBuilder()
Returns a builder that allows this bean to be mutated.- Returns:
- the mutable builder, not null
-
-