Class DayPartitionBuilder
A mutable builder for creating day partition rules.
This class enables the easy construction of daily shop opening times or weekly work time schedules. Example:
DayPartitionRule rule = new DayPartitionBuilder() .addExclusion(PlainDate.of(2016, 8, 27)) .addWeekdayRule(MONDAY, FRIDAY, ClockInterval.between(PlainTime.of(9, 0), PlainTime.of(12, 30))) .addWeekdayRule(MONDAY, ClockInterval.between(PlainTime.of(14, 0), PlainTime.of(16, 0))) .addWeekdayRule(THURSDAY, ClockInterval.between(PlainTime.of(14, 0), PlainTime.of(19, 0))) .build(); List<TimestampInterval> intervals = // determine all intervals for August and September in 2016 DateInterval.between(PlainDate.of(2016, 8, 1), PlainDate.of(2016, 9, 30)) .streamPartitioned(rule) .parallel() .collect(Collectors.toList());
- Since:
- 4.18
- Author:
- Meno Hochschild
- See Also:
DayPartitionRule
,DateInterval.streamPartitioned(DayPartitionRule)
-
Constructor Summary
ConstructorDescriptionCreates a new instance for building rules which are always active.DayPartitionBuilder(Predicate<PlainDate> activeFilter)
Creates a new instance with given filter. -
Method Summary
Modifier and TypeMethodDescriptionaddDailyRule(ClockInterval partition)
Adds a rule to partition any calendar date.addExclusion(Collection<PlainDate> dates)
Adds multiple exclusion dates.addExclusion(PlainDate date)
Adds an exclusion date.addSpecialRule(PlainDate specialDay, ClockInterval partition)
Adds a rule to partition a special calendar date.addWeekdayRule(SpanOfWeekdays spanOfWeekdays, ClockInterval partition)
Adds a rule to partition a date dependending on when its day of week falls into given range.addWeekdayRule(Weekday dayOfWeek, ClockInterval partition)
Adds a rule to partition a date dependending on its day of week.addWeekdayRule(Weekday from, Weekday to, ClockInterval partition)
Adds a rule to partition a date dependending on when its day of week falls into given range.build()
Creates a new day partition rule.
-
Constructor Details
-
DayPartitionBuilder
public DayPartitionBuilder()Creates a new instance for building rules which are always active.
-
DayPartitionBuilder
Creates a new instance with given filter.
If only one rule is to be applied then setting an active filter has a similar effect as setting an exclusion date. However, if two or more rules with different filters are created then the new combined day-partition-rule (based on and-chaining) will not completely exclude certain dates only because of one partial rule with a special filter.
- Parameters:
activeFilter
- determines when the rule to be created is active (should be stateless)- Since:
- 4.19
- See Also:
DayPartitionRule.and(DayPartitionRule)
-
-
Method Details
-
addDailyRule
Adds a rule to partition any calendar date.
- Parameters:
partition
- a clock interval- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if there is no canonical form of given interval (for example for [00:00/24:00])- Since:
- 4.20
- See Also:
IsoInterval.toCanonical()
-
addWeekdayRule
Adds a rule to partition a date dependending on its day of week.
This method can be called multiple times for the same day of week in order to define more than one disjunct partition.
- Parameters:
dayOfWeek
- controls the partitioning in the final day partition rulepartition
- a clock interval- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if there is no canonical form of given interval (for example for [00:00/24:00])- See Also:
IsoInterval.toCanonical()
-
addWeekdayRule
Adds a rule to partition a date dependending on when its day of week falls into given range.
This method can be called multiple times using the same arguments in order to define more than one disjunct partition.
- Parameters:
from
- starting day of weekto
- ending day of weekpartition
- a clock interval- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if there is no canonical form of given interval (for example for [00:00/24:00])- Since:
- 4.20
- See Also:
IsoInterval.toCanonical()
-
addWeekdayRule
Adds a rule to partition a date dependending on when its day of week falls into given range.
This method can be called multiple times using the same arguments in order to define more than one disjunct partition.
- Parameters:
spanOfWeekdays
- span of weekdays with start and endpartition
- a clock interval- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if there is no canonical form of given interval (for example for [00:00/24:00])- Since:
- 4.20
- See Also:
IsoInterval.toCanonical()
-
addSpecialRule
Adds a rule to partition a special calendar date.
This method can be called multiple times for the same special day in order to define more than one disjunct partition.
- Parameters:
specialDay
- controls the partitioning in the final day partition rulepartition
- a clock interval- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException
- if there is no canonical form of given interval (for example for [00:00/24:00])- See Also:
IsoInterval.toCanonical()
-
addExclusion
Adds an exclusion date.
- Parameters:
date
- the calendar date to be excluded from creating day partitions- Returns:
- this instance for method chaining
- See Also:
DayPartitionRule.isExcluded(PlainDate)
,addExclusion(Collection)
-
addExclusion
Adds multiple exclusion dates.
- Parameters:
dates
- collection of calendar dates to be excluded from creating day partitions- Returns:
- this instance for method chaining
- See Also:
DayPartitionRule.isExcluded(PlainDate)
,addExclusion(PlainDate)
-
build
Creates a new day partition rule.
- Returns:
- DayPartitionRule
-