Class RecurrenceRule
The goal of this implementation is to satisfy the following qualities:
- correctness: The instances returned by the iterator shall be correct for all common cases, i.e. they follow all rules defined in RFC 5545/RFC 2445.
- completeness: The iterator shall support all valid combinations defined by RFC 5545 and RFC 2445 and return reasonable results for edge cases that are not explicitly mentioned.
- performance: The iterator shall be as efficient (in speed and memory utilization) as possible.
TODO: Add validator and a validator log.
TODO: Add proper implementation of the Object.equals(Object) method.
TODO: Add support for jCal rules.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of valid recurrence rule parts.static enumEnumeration of supported rule versions.static enumValues of the new SKIP parameter as added in tools.ietf.org/html/draft-daboo-icalendar-rscale-03static classThis class represents the position of aWeekdayin a specific range. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRecurrenceRule(String recur) Create a new recurrence rule from String using theRecurrenceRule.RfcModeRecurrenceRule.RfcMode.RFC5545_LAX.RecurrenceRule(String recur, RecurrenceRule.RfcMode mode) Create a new recurrence rule from String using a customRecurrenceRule.RfcMode.RecurrenceRule(Freq freq) Create a new recurrence rule with the given base frequency.RecurrenceRule(Freq freq, RecurrenceRule.RfcMode mode) Create a new recurrence rule with the given base frequency using a customRecurrenceRule.RfcMode. -
Method Summary
Modifier and TypeMethodDescriptionReturn the value of the BYDAY part of the rule if there is any.getByPart(RecurrenceRule.Part part) Returns a specific by-rule.getCount()Get the number if instances in the recurrence set.getFreq()Return the base frequency of this recurrence rule.intGet the INTERVAL of this rule.getSkip()Return value of the skip part of this rule.org.dmfs.rfc5545.DateTimegetUntil()Get the last date an instance my have.org.dmfs.rfc5545.WeekdayGet the start of the week as defined in the rule.Returns a specific x-part.booleanhasPart(RecurrenceRule.Part part) Checks if a specific part is present in this rule.booleanReturns whether a specific x-part is present in the rule.booleanReturns whether this recurrence rule recurs forever.Get a newRuleIteratorthat iterates all instances of this rule.iterator(org.dmfs.rfc5545.DateTime start) Get a newRuleIteratorthat iterates all instances of this rule.voidSet the BYDAY part of this rule.voidsetByPart(RecurrenceRule.Part part, Integer... values) Set a specific by-rule.voidsetByPart(RecurrenceRule.Part part, List<Integer> value) Set a specific by-rule.voidsetCount(int count) Set the number of instances in the recurrence set.voidSet the base frequency of this recurrence rule.voidsetInterval(int interval) Set the INTERVAL of this rule.voidsetSkip(RecurrenceRule.Skip skip) Set the skip part of this recurrence rule.voidsetUntil(org.dmfs.rfc5545.DateTime until) Set the latest possible date of an instance.voidsetWeekStart(org.dmfs.rfc5545.Weekday wkst) Set the start of the week.voidsetWeekStart(org.dmfs.rfc5545.Weekday wkst, boolean keepWkStMo) Set the start of the week.voidSets an x-part. x-parts are supported by RFC 2445 only.toString()
-
Field Details
-
mode
The parser mode. This can not be changed once the rule has been created.
-
-
Constructor Details
-
RecurrenceRule
Create a new recurrence rule from String using theRecurrenceRule.RfcModeRecurrenceRule.RfcMode.RFC5545_LAX. The parser will be quite tolerant and skip any invalid parts to produce a valid recurrence rule.- Parameters:
recur- A recurrence rule string as defined in RFC 5545.- Throws:
InvalidRecurrenceRuleException- If an unrecoverable error occurs when parsing the rule (like FREQ is missing, or mutually exclusive parts have been found).
-
RecurrenceRule
public RecurrenceRule(String recur, RecurrenceRule.RfcMode mode) throws InvalidRecurrenceRuleException Create a new recurrence rule from String using a customRecurrenceRule.RfcMode.- Parameters:
recur- A recurrence rule string as defined in RFC 5545.mode- ARecurrenceRule.RfcModeto change the parsing behaviour in case of errors.- Throws:
InvalidRecurrenceRuleException- If the rule is invalid with respect to the chosen mode or if an unrecoverable error occurs when parsing the rule (like FREQ is missing, or mutually exclusive parts have been found).
-
RecurrenceRule
Create a new recurrence rule with the given base frequency. This constructor will useRecurrenceRule.RfcMode.RFC5545_STRICT, so created rules will have to comply with RFC 5545, otherwise an exception is thrown.- Parameters:
freq- TheFreqvalues that specified the base frequency for this rule.
-
RecurrenceRule
Create a new recurrence rule with the given base frequency using a customRecurrenceRule.RfcMode.- Parameters:
freq- TheFreqvalues that specified the base frequency for this rule.mode- ARecurrenceRule.RfcModeto change the behavior in case of errors.
-
-
Method Details
-
getFreq
Return the base frequency of this recurrence rule.- Returns:
- The
Freqvalue of this rule.
-
setFreq
Set the base frequency of this recurrence rule.TODO: check if the rule is still valid afterwards (honor the silent parameter)
- Parameters:
freq- The newFreqvalue of this rule.silent-trueto dropRecurrenceRule.Parts that are no longer valid with the new frequency silently,falseto throw an exception in that case.
-
getSkip
Return value of the skip part of this rule.- Returns:
- The
RecurrenceRule.Skipvalue of this rule.
-
setSkip
Set the skip part of this recurrence rule. Consider to set aRecurrenceRule.Part.RSCALEvalue when setting a SKIP rule, otherwise it will default to GREGORIAN calendar.- Parameters:
skip- The newRecurrenceRule.Skipvalue of this rule,nullandRecurrenceRule.Skip.OMITwill remove the SKIP part, the later one is the default anyway.
-
getInterval
public int getInterval()Get the INTERVAL of this rule.- Returns:
- The INTERVAL of this rule or
1if no INTERVAL has been specified.
-
setInterval
public void setInterval(int interval) Set the INTERVAL of this rule. The interval must be a positive integer. A value of1will just remove the INTERVAL part since that's the default value anyway.- Parameters:
interval- The new interval of this rule.- Throws:
IllegalArgumentException- if interval is not a positive integer value.
-
getUntil
public org.dmfs.rfc5545.DateTime getUntil()Get the last date an instance my have. If the rule has an UNTIL part the result is aDateTimeset to the correct time. The time zone is either UTC or floating.- Returns:
- A
DateTimeset to the UNTIL value if an UNTIL part is present,nullotherwise.
-
setUntil
public void setUntil(org.dmfs.rfc5545.DateTime until) Set the latest possible date of an instance. This will remove any COUNT rule if present. If the time zone ofuntilis not UTC and until is not floating it's automatically converted to UTC.- Parameters:
until- The UNTIL part of this rule ornullto let the instances recur forever.
-
getCount
Get the number if instances in the recurrence set. If this rule has no COUNT limit this will returnnull- Returns:
- The number of instances or
null.
-
setCount
public void setCount(int count) Set the number of instances in the recurrence set. This will remove any UNTIL rule if present.- Parameters:
count- The number if instances.
-
isInfinite
public boolean isInfinite()Returns whether this recurrence rule recurs forever.- Returns:
trueif this rule contains neither anRecurrenceRule.Part.UNTILnor aRecurrenceRule.Part.COUNTpart,falseotherwise.
-
hasPart
Checks if a specific part is present in this rule.- Parameters:
part- The part if interest.- Returns:
trueif this rule has this part,falseotherwise
-
getByPart
Returns a specific by-rule.partmay be one ofRecurrenceRule.Part.BYSECOND,RecurrenceRule.Part.BYMINUTE,RecurrenceRule.Part.BYHOUR,RecurrenceRule.Part.BYMONTHDAY,RecurrenceRule.Part.BYYEARDAY,RecurrenceRule.Part.BYWEEKNO,RecurrenceRule.Part.BYMONTH, orRecurrenceRule.Part.BYSETPOS.To get
RecurrenceRule.Part.BYDAYusegetByDayPart().- Parameters:
part- The by-rule to return.- Returns:
- A list of integer values.
-
setByPart
public void setByPart(RecurrenceRule.Part part, List<Integer> value) throws InvalidRecurrenceRuleException Set a specific by-rule.partmay be one ofRecurrenceRule.Part.BYSECOND,RecurrenceRule.Part.BYMINUTE,RecurrenceRule.Part.BYHOUR,RecurrenceRule.Part.BYMONTHDAY,RecurrenceRule.Part.BYYEARDAY,RecurrenceRule.Part.BYWEEKNO,RecurrenceRule.Part.BYMONTH, orRecurrenceRule.Part.BYSETPOS.To set
RecurrenceRule.Part.BYDAYusesetByDayPart(List).- Parameters:
part- The by-rule to set.value- A list of integers that specify the rule ornull(or an empty list) to remove the part.- Throws:
InvalidRecurrenceRuleException- if the list would become invalid by adding this part (this respects the currentRecurrenceRule.RfcMode.
-
setByPart
public void setByPart(RecurrenceRule.Part part, Integer... values) throws InvalidRecurrenceRuleException Set a specific by-rule.partmay be one ofRecurrenceRule.Part.BYSECOND,RecurrenceRule.Part.BYMINUTE,RecurrenceRule.Part.BYHOUR,RecurrenceRule.Part.BYMONTHDAY,RecurrenceRule.Part.BYYEARDAY,RecurrenceRule.Part.BYWEEKNO,RecurrenceRule.Part.BYMONTH, orRecurrenceRule.Part.BYSETPOS.To set
RecurrenceRule.Part.BYDAYusesetByDayPart(List).- Parameters:
part- The by-rule to set.values- Integers that specify the rule ornull(or an empty list) to remove the part.- Throws:
InvalidRecurrenceRuleException- if the list would become invalid by adding this part (this respects the currentRecurrenceRule.RfcMode.
-
setByDayPart
Set the BYDAY part of this rule.- Parameters:
value- AListofRecurrenceRule.WeekdayNums ornullor an empty List to remove the part
-
getByDayPart
Return the value of the BYDAY part of the rule if there is any.- Returns:
- A
ListofRecurrenceRule.WeekdayNums if the part is present ornullif there is no such part.
-
getWeekStart
public org.dmfs.rfc5545.Weekday getWeekStart()Get the start of the week as defined in the rule. If no WKST part is set this method will return the default value, which isWeekday.MO.- Returns:
- A
Weekday.
-
setWeekStart
public void setWeekStart(org.dmfs.rfc5545.Weekday wkst) Set the start of the week. If the start is set toWeekday.MOthe WKST part is effectively removed, since that's the default value. This value is important for rules having a BYWEEKNO or BYDAY part.- Parameters:
wkst- The start of the week to use when calculating the instances.
-
setWeekStart
public void setWeekStart(org.dmfs.rfc5545.Weekday wkst, boolean keepWkStMo) Set the start of the week. If the start is set toWeekday.MOthe WKST part is effectively removed (unlesskeepWkStMo == true), since that's the default value. This value is important for rules having a BYWEEKNO or BYDAY part.- Parameters:
wkst- The start of the week to use when calculating the instances.keepWkStMo- set totrueto keep the WKST field if the value isWeekday.MO. Since Monday is the default adding it is not necessary, but some implementations might be broken and use a different weekstart if it's not explicitly specified.
-
setXPart
Sets an x-part. x-parts are supported by RFC 2445 only. Ifmodeis set toRecurrenceRule.RfcMode.RFC5545_LAXa call to this method will do nothing. Ifmodeis set toRecurrenceRule.RfcMode.RFC5545_STRICTthis method will throw anUnsupportedOperationException.Note that calling this method in RFC 2445 mode will override any existing x-part of the same name.
- Parameters:
xname- The name of the x-part. Must be a valid identifier.value- The value of the x-part. Must be a valid name.- Throws:
UnsupportedOperationException- ifmodeis set toRecurrenceRule.RfcMode.RFC5545_STRICT.
-
hasXPart
Returns whether a specific x-part is present in the rule. Since RFC 5545 doesn't support x-parts this method will always returnfalseifmodeequalsRecurrenceRule.RfcMode.RFC5545_LAXorRecurrenceRule.RfcMode.RFC5545_STRICT.- Parameters:
xname- The name of the x-part to check for.- Returns:
trueif the part is present,falseotherwise.
-
getXPart
Returns a specific x-part. Since RFC 5545 doesn't support x-parts this method will always returnnullifmodeequalsRecurrenceRule.RfcMode.RFC5545_LAXorRecurrenceRule.RfcMode.RFC5545_STRICT.- Parameters:
xname- The name of the x-part to return.- Returns:
- The value of the x-part or
null.
-
iterator
Get a newRuleIteratorthat iterates all instances of this rule.Note: If the rule contains an UNTIL part with a floating value, you have to provide
nullas the timezone.- Parameters:
start- The time of the first instance in milliseconds since the epoch.timezone- TheTimeZoneof the first instance ornullfor floating times.- Returns:
- A
RecurrenceRuleIterator.
-
iterator
Get a newRuleIteratorthat iterates all instances of this rule.Note: if an UNTIL part is present and it's value is a floating time then start must be floating as well and vice versa. The same applies if the UNTIL value is an all-day value
- Parameters:
start- The first instance.- Returns:
- A
RuleIterator.
-
toString
-