Each CER Timeline has some important properties that you will need to know before working with Timelines in your CER rule sets, rule tests and any code which is a client of CER:
- each CER Timeline is immutable (like all data types used in CER);
- each reference to Timeline is parameterized with the type of value held in the Timeline, which can be primitives such as String, Date, Number, Boolean etc. or an arbitrarily complex type such as a Rule Class or another parameterized type such as List. As for other parameterized types in CER, the parameter itself should be an immutable object;
- each CER Timeline extends infinitely far into the past and infinitely far into the future1. In other words, each CER Timeline has a value on any date, no matter how far in the past or future that date might be;
- when a CER Timeline is created, the timeline will be divided into a collection of intervals, with each interval holding a constant value for a period of time within the timeline. Contiguous intervals always have different2values, otherwise they would have been merged into a single interval.each CER Timeline extends infinitely far into the past and infinitely far into the future;
There are a number of consequences of these properties:
- it is not possible to have a "gap" in the middle of a timeline - all intervals in a timeline are contiguous;
- it is not possible to have a timeline which starts on a particular date; in certain circumstances a sensible default will need to be chosen, for example if you have a Timeline<Number> for the income arising from an Employment, then that income should be 0 on all dates before the Employment start date;
- it is not possible to have a timeline which ends on a particular date - the last value in the timeline applies "until further notice", i.e. arbitrarily far into the future; in certain circumstances a sensible default will need to be chosen, for example if you have a Timeline<Number> for the income arising from an Employment, then if there is a known end date for that Employment, then the income should be 0 on all dates after the Employment has ended; otherwise if there is no known end date for that Employment, then the latest income should apply until further notice;
- any attempt to create a timeline that does not have a value for any date will fail. In particular, each timeline must have a value which applies from the start of time, signified by a start date of null;
- each timeline can contain a finite number of value changes. This presents a limitation for timelines which represent values which change an arbitrary number of times. For example, you might have a Timeline<Number> to represent a person's age, with the value 0 up until the person's first birthday, the value 1 up until the person's second birthday and so on. For Persons who are still alive it is not possible to predict how many more birthdays they will have, and so a practical limit (e.g. of 200, say) must be imposed. In practice, this limitation should not present any difficulties.
2 Same/different values are detected by the semantic of Java's
Object.equals(...). All types used as a parameterized type to Timeline must have sensible implementations of
Object.equals(...) and
Object.hashCode().