public class DayPartitionBuilder extends Object
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());
DayPartitionRule,
DateInterval.streamPartitioned(DayPartitionRule)| Constructor and Description |
|---|
DayPartitionBuilder()
Creates a new instance for building rules which are always active.
|
DayPartitionBuilder(Predicate<PlainDate> activeFilter)
Creates a new instance with given filter.
|
| Modifier and Type | Method and Description |
|---|---|
DayPartitionBuilder |
addDailyRule(ClockInterval partition)
Adds a rule to partition any calendar date.
|
DayPartitionBuilder |
addExclusion(Collection<PlainDate> dates)
Adds multiple exclusion dates.
|
DayPartitionBuilder |
addExclusion(PlainDate date)
Adds an exclusion date.
|
DayPartitionBuilder |
addSpecialRule(PlainDate specialDay,
ClockInterval partition)
Adds a rule to partition a special calendar date.
|
DayPartitionBuilder |
addWeekdayRule(SpanOfWeekdays spanOfWeekdays,
ClockInterval partition)
Adds a rule to partition a date dependending on when its day of week falls into given range.
|
DayPartitionBuilder |
addWeekdayRule(Weekday dayOfWeek,
ClockInterval partition)
Adds a rule to partition a date dependending on its day of week.
|
DayPartitionBuilder |
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.
|
DayPartitionRule |
build()
Creates a new day partition rule.
|
public DayPartitionBuilder()
Creates a new instance for building rules which are always active.
public DayPartitionBuilder(Predicate<PlainDate> activeFilter)
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.
activeFilter - determines when the rule to be created is active (should be stateless)DayPartitionRule.and(DayPartitionRule)public DayPartitionBuilder addDailyRule(ClockInterval partition)
Adds a rule to partition any calendar date.
partition - a clock intervalIllegalArgumentException - if there is no canonical form of given interval (for example for [00:00/24:00])IsoInterval.toCanonical()public DayPartitionBuilder addWeekdayRule(Weekday dayOfWeek, ClockInterval partition)
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.
dayOfWeek - controls the partitioning in the final day partition rulepartition - a clock intervalIllegalArgumentException - if there is no canonical form of given interval (for example for [00:00/24:00])IsoInterval.toCanonical()public DayPartitionBuilder 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.
This method can be called multiple times using the same arguments in order to define more than one disjunct partition.
from - starting day of weekto - ending day of weekpartition - a clock intervalIllegalArgumentException - if there is no canonical form of given interval (for example for [00:00/24:00])IsoInterval.toCanonical()public DayPartitionBuilder addWeekdayRule(SpanOfWeekdays spanOfWeekdays, ClockInterval partition)
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.
spanOfWeekdays - span of weekdays with start and endpartition - a clock intervalIllegalArgumentException - if there is no canonical form of given interval (for example for [00:00/24:00])IsoInterval.toCanonical()public DayPartitionBuilder addSpecialRule(PlainDate specialDay, ClockInterval partition)
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.
specialDay - controls the partitioning in the final day partition rulepartition - a clock intervalIllegalArgumentException - if there is no canonical form of given interval (for example for [00:00/24:00])IsoInterval.toCanonical()public DayPartitionBuilder addExclusion(PlainDate date)
Adds an exclusion date.
date - the calendar date to be excluded from creating day partitionsDayPartitionRule.isExcluded(PlainDate),
addExclusion(Collection)public DayPartitionBuilder addExclusion(Collection<PlainDate> dates)
Adds multiple exclusion dates.
dates - collection of calendar dates to be excluded from creating day partitionsDayPartitionRule.isExcluded(PlainDate),
addExclusion(PlainDate)public DayPartitionRule build()
Creates a new day partition rule.
Copyright © 2014–2021. All rights reserved.