Package com.onenetwork.platform.data.tlv
Interface TimelineBuilder
public interface TimelineBuilder
Used by
TimelineCalculator
implementations to specify a Timeline (a sequence of buckets) at runtime.
Supports simple specifications, for example:
14 days, then 8 split weeks, then 3 monthsSupport more complex "business calendar" specifications, for example:
2 weeks-worth of days, followed by 2 months-worth of split weeks, followed by 3 monthsSample code from a TimelineCalculator, using TimelineBuilder:
public void calculate(TimelineBuilder builder, MapThe buckets should be added in the order in which they will appear on the Timeline, otherwise an exception will be thrown. For example, the code fragments below are erroneous:arg1) { Calendar startDateCopy = (Calendar) builder.getStartDate().clone(); startDateCopy.add(Calendar.DAY_OF_YEAR, -1); builder.setStartDate(startDateCopy); builder.addWeeksOfDays(2); builder.addMonthsOfSplitWeeks(2); builder.addBuckets(Bucketization.MONTHLY, 3); }
addMonthsOfWeeks(2); // Next line will throw an exception, because days must be added before weeks addWeeksOfDays(4);
addBuckets(Bucketiation.WEEKLY, 4); // Next line will throw an exception, because days must be added before weeks addBuckets(Bucketiation.DAILY, 15);
-
Method Summary
Modifier and Type Method Description void
addBuckets(Bucketization bucketization, int count)
Convenience method to add a number of buckets of a given type to the end of the Timeline.int
addMonthsOfDays(int monthCount)
Adds as many DAILY buckets as are necessary to fillmonthCount
months, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present).int
addMonthsOfSplitWeeks(int monthCount)
LikeaddMonthsOfWeeks(int)
, but adds split weeks instead of standard weeks.int
addMonthsOfWeeks(int monthCount)
Adds as many WEEKLY buckets as are necessary to fillmonthCount
months, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present).int
addWeeksOfDays(int weekCount)
Adds as many DAILY buckets as are necessary to fillweekCount
weeks, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present).java.util.List<Pair<Bucketization,java.lang.Integer>>
getBucketCounts()
java.util.Calendar
getStartDate()
void
setStartDate(java.util.Calendar cal)
Start data of timeline.
NOTE: Start date should be set before setting any bucket count.
-
Method Details
-
addBuckets
Convenience method to add a number of buckets of a given type to the end of the Timeline. -
addWeeksOfDays
int addWeeksOfDays(int weekCount)Adds as many DAILY buckets as are necessary to fillweekCount
weeks, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present). Less than 7 days may be used to fill the "first week" if it doesn't start on the start day of the week. For example: assume the next available bucket date is Wednesday 27th September 2017 and the Start Day of Week is Monday. If the user provides a value of "2", then 12 DAILY buckets will be added (Wed 27 through Sun 1, and Mon 2 through Sun 8).- Parameters:
weekCount
- number of weeks to be filled with DAILY buckets.
-
addMonthsOfDays
int addMonthsOfDays(int monthCount)Adds as many DAILY buckets as are necessary to fillmonthCount
months, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present). Fewer days may be used to fill the "first month" if it doesn't start on the start day of the month. For example: assume the next available bucket date is Friday 15th September 2017. If the user provides a value of "2", then 47 DAILY buckets will be added (Fri 15 through Sat 30, and Mon 1 through Tue 31).- Parameters:
monthCount
- number of months to be filled with DAILY buckets.
-
addMonthsOfWeeks
int addMonthsOfWeeks(int monthCount)Adds as many WEEKLY buckets as are necessary to fillmonthCount
months, starting from the day after the last bucket added to this TimelineBuilder (or StartDate if no other buckets are present). Fewer days may be used to fill the "first month" if it doesn't start on the start day of the month. The last week added may overlap month boundaries. For example: assume the next available bucket date is Monday 11th September 2017 and the Start Day of Week is Monday. If the user provides a value of "1", then 3 WEEKLY buckets will be added (Mon 11 - Sun 17, Mon 18 - Sun 24, Mon 25 - Sun 1).- Parameters:
monthCount
- number of months to be filled with WEEKLY buckets.
-
addMonthsOfSplitWeeks
int addMonthsOfSplitWeeks(int monthCount)LikeaddMonthsOfWeeks(int)
, but adds split weeks instead of standard weeks. This has the advantage that the last split week can be "split" to ensure it doesn't exceed the month boundary. For example: assume the next available bucket date is Monday 11th September 2017 and the Start Day of Week is Monday. If the user provides a value of "1", then 3 SPLIT_WEEKLY buckets will be added (Mon 11 - Sun 17, Mon 18 - Sun 24, Mon 25 - Sat 30).- Parameters:
monthCount
- number of months to be filled with SPLIT_WEEKLY buckets.
-
getStartDate
java.util.Calendar getStartDate()- Returns:
startDate
-
setStartDate
void setStartDate(java.util.Calendar cal)Start data of timeline.
NOTE: Start date should be set before setting any bucket count. If not set then User selected start date will be used. -
getBucketCounts
java.util.List<Pair<Bucketization,java.lang.Integer>> getBucketCounts()- Returns:
- List of Bucketization with bucket count
-