Package com.identityworksllc.iiq.common
Class BusinessDayAdjuster
- java.lang.Object
-
- com.identityworksllc.iiq.common.BusinessDayAdjuster
-
- All Implemented Interfaces:
TemporalAdjuster
public class BusinessDayAdjuster extends Object implements TemporalAdjuster
ATemporalAdjusterthat adds or subtracts a specified number of business days to a date.A business day is a date that is not a weekend or in the list of holidays.
For example:
LocalDate now = LocalDate.now(); LocalDate nextBusinessDay = now.with(BusinessDateAdjuster.addWorkDays(1));
You can also use it with a
Calendarobject via the static helper methods.Calendar now = Calendar.getInstance(); Calendar nextBusinessDay = BusinessDateAdjuster.adjustCalendar(now, 1);
-
-
Field Summary
Fields Modifier and Type Field Description static Set<DayOfWeek>DEFAULT_WEEKEND_DAYSThe default set of weekend days (Saturday and Sunday).
-
Constructor Summary
Constructors Constructor Description BusinessDayAdjuster(int days)Creates a new BusinessDayAdjuster with no holidays and the default set of weekend days.BusinessDayAdjuster(int days, Set<LocalDate> holidays)Creates a new BusinessDayAdjuster with the given list of holidays and the default set of weekend days.BusinessDayAdjuster(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)Creates a new BusinessDayAdjuster.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BusinessDayAdjusteraddWorkDays(int days)Creates a BusinessDayAdjuster that adds the specified number of work days.static BusinessDayAdjusteraddWorkDays(int days, Set<LocalDate> holidays)Creates a BusinessDayAdjuster that adds the specified number of work days.static BusinessDayAdjusteraddWorkDays(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)Creates a BusinessDayAdjuster that adds the specified number of work days.static CalendaradjustCalendar(Calendar input, int days)Adjusts the specified calendar by the required number of business days.static CalendaradjustCalendar(Calendar input, int days, Set<LocalDate> holidays)Adjusts the specified calendar by the required number of business days.static CalendaradjustCalendar(Calendar input, int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)Adjusts the specified calendar by the required number of business days.TemporaladjustInto(Temporal temporal)Adjusts the specified temporal object by the required number of business days.static BusinessDayAdjustersubtractWorkDays(int days)Creates a BusinessDayAdjuster that subtracts the specified number of work days.static BusinessDayAdjustersubtractWorkDays(int days, Set<LocalDate> holidays)Creates a BusinessDayAdjuster that subtracts the specified number of work days.static BusinessDayAdjustersubtractWorkDays(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)Creates a WorkDayAdjuster that subtracts the specified number of work days.
-
-
-
Field Detail
-
DEFAULT_WEEKEND_DAYS
public static final Set<DayOfWeek> DEFAULT_WEEKEND_DAYS
The default set of weekend days (Saturday and Sunday).
-
-
Constructor Detail
-
BusinessDayAdjuster
public BusinessDayAdjuster(int days)
Creates a new BusinessDayAdjuster with no holidays and the default set of weekend days.- Parameters:
days- The number of business days to add (positive) or subtract (negative)
-
BusinessDayAdjuster
public BusinessDayAdjuster(int days, Set<LocalDate> holidays)
Creates a new BusinessDayAdjuster with the given list of holidays and the default set of weekend days.- Parameters:
days- The number of business days to add (positive) or subtract (negative)holidays- A set of dates to be considered holidays (non-work days)
-
BusinessDayAdjuster
public BusinessDayAdjuster(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)
Creates a new BusinessDayAdjuster.- Parameters:
days- The number of business days to add (positive) or subtract (negative)holidays- A set of dates to be considered holidays (non-work days)weekendDays- A set of days to be considered weekends
-
-
Method Detail
-
addWorkDays
public static BusinessDayAdjuster addWorkDays(int days)
Creates a BusinessDayAdjuster that adds the specified number of work days.- Parameters:
days- The number of work days to add- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
addWorkDays
public static BusinessDayAdjuster addWorkDays(int days, Set<LocalDate> holidays)
Creates a BusinessDayAdjuster that adds the specified number of work days.- Parameters:
days- The number of work days to addholidays- A set of dates to be considered holidays- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
addWorkDays
public static BusinessDayAdjuster addWorkDays(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)
Creates a BusinessDayAdjuster that adds the specified number of work days.- Parameters:
days- The number of work days to addholidays- A set of dates to be considered holidaysweekendDays- A set of days to be considered weekends- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
adjustCalendar
public static Calendar adjustCalendar(Calendar input, int days)
Adjusts the specified calendar by the required number of business days.The input calendar is not modified.
- Parameters:
input- The input calendardays- The number of business days to add (positive) or subtract (negative)- Returns:
- The adjusted calendar, a separate object from the original
-
adjustCalendar
public static Calendar adjustCalendar(Calendar input, int days, Set<LocalDate> holidays)
Adjusts the specified calendar by the required number of business days.The input calendar is not modified.
- Parameters:
input- The input calendardays- The number of business days to add (positive) or subtract (negative)holidays- A set of dates to be considered holidays- Returns:
- The adjusted calendar, a separate object from the original
-
adjustCalendar
public static Calendar adjustCalendar(Calendar input, int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)
Adjusts the specified calendar by the required number of business days.The input calendar is not modified.
- Parameters:
input- The input calendardays- The number of business days to add (positive) or subtract (negative)holidays- A set of dates to be considered holidaysweekendDays- A set of days to be considered weekends- Returns:
- The adjusted calendar, a separate object from the original
-
subtractWorkDays
public static BusinessDayAdjuster subtractWorkDays(int days, Set<LocalDate> holidays)
Creates a BusinessDayAdjuster that subtracts the specified number of work days.- Parameters:
days- The number of work days to addholidays- A set of dates to be considered holidays- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
subtractWorkDays
public static BusinessDayAdjuster subtractWorkDays(int days)
Creates a BusinessDayAdjuster that subtracts the specified number of work days.- Parameters:
days- The number of work days to add- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
subtractWorkDays
public static BusinessDayAdjuster subtractWorkDays(int days, Set<LocalDate> holidays, Set<DayOfWeek> weekendDays)
Creates a WorkDayAdjuster that subtracts the specified number of work days.- Parameters:
days- The number of work days to subtractholidays- A set of dates to be considered holidaysweekendDays- A set of days to be considered weekends- Returns:
- A BusinessDayAdjuster for use with
LocalDate.with(TemporalAdjuster)
-
adjustInto
public Temporal adjustInto(Temporal temporal)
Adjusts the specified temporal object by the required number of business days.- Specified by:
adjustIntoin interfaceTemporalAdjuster- Parameters:
temporal- the temporal object to adjust, not null- Returns:
- the adjusted temporal object, not null
- Throws:
NullPointerException- if the input object is null- See Also:
TemporalAdjuster.adjustInto(Temporal)
-
-