public final class RecurrenceRule
extends java.lang.Object
The goal of this implementation is to satisfy the following qualities:
TODO: Add validator and a validator log.
TODO: Add proper implementation of the Object.equals(Object) method.
TODO: Add support for jCal rules.
| Modifier and Type | Class and Description |
|---|---|
static class |
RecurrenceRule.Part
Enumeration of valid recurrence rule parts.
|
static class |
RecurrenceRule.RfcMode
Enumeration of supported rule versions.
|
static class |
RecurrenceRule.Skip
Values of the new SKIP parameter as added in tools.ietf.org/html/draft-daboo-icalendar-rscale-03
|
static class |
RecurrenceRule.WeekdayNum
This class represents the position of a
Weekday in a specific range. |
| Modifier and Type | Field and Description |
|---|---|
RecurrenceRule.RfcMode |
mode
The parser mode.
|
| Constructor and Description |
|---|
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 custom
RecurrenceRule.RfcMode. |
RecurrenceRule(java.lang.String recur)
Create a new recurrence rule from String using the
RecurrenceRule.RfcMode RecurrenceRule.RfcMode.RFC5545_LAX. |
RecurrenceRule(java.lang.String recur,
RecurrenceRule.RfcMode mode)
Create a new recurrence rule from String using a custom
RecurrenceRule.RfcMode. |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<RecurrenceRule.WeekdayNum> |
getByDayPart()
Return the value of the BYDAY part of the rule if there is any.
|
java.util.List<java.lang.Integer> |
getByPart(RecurrenceRule.Part part)
Returns a specific by-rule.
|
java.lang.Integer |
getCount()
Get the number if instances in the recurrence set.
|
Freq |
getFreq()
Return the base frequency of this recurrence rule.
|
int |
getInterval()
Get the INTERVAL of this rule.
|
RecurrenceRule.Skip |
getSkip()
Return value of the skip part of this rule.
|
org.dmfs.rfc5545.DateTime |
getUntil()
Get the last date an instance my have.
|
org.dmfs.rfc5545.Weekday |
getWeekStart()
Get the start of the week as defined in the rule.
|
java.lang.String |
getXPart(java.lang.String xname)
Returns a specific x-part.
|
boolean |
hasPart(RecurrenceRule.Part part)
Checks if a specific part is present in this rule.
|
boolean |
hasXPart(java.lang.String xname)
Returns whether a specific x-part is present in the rule.
|
boolean |
isInfinite()
Returns whether this recurrence rule recurs forever.
|
RecurrenceRuleIterator |
iterator(org.dmfs.rfc5545.DateTime start)
Get a new
RuleIterator that iterates all instances of this rule. |
RecurrenceRuleIterator |
iterator(long start,
java.util.TimeZone timezone)
Get a new
RuleIterator that iterates all instances of this rule. |
void |
setByDayPart(java.util.List<RecurrenceRule.WeekdayNum> value)
Set the BYDAY part of this rule.
|
void |
setByPart(RecurrenceRule.Part part,
java.lang.Integer... values)
Set a specific by-rule.
|
void |
setByPart(RecurrenceRule.Part part,
java.util.List<java.lang.Integer> value)
Set a specific by-rule.
|
void |
setCount(int count)
Set the number of instances in the recurrence set.
|
void |
setFreq(Freq freq,
boolean silent)
Set the base frequency of this recurrence rule.
|
void |
setInterval(int interval)
Set the INTERVAL of this rule.
|
void |
setSkip(RecurrenceRule.Skip skip)
Set the skip part of this recurrence rule.
|
void |
setUntil(org.dmfs.rfc5545.DateTime until)
Set the latest possible date of an instance.
|
void |
setWeekStart(org.dmfs.rfc5545.Weekday wkst)
Set the start of the week.
|
void |
setWeekStart(org.dmfs.rfc5545.Weekday wkst,
boolean keepWkStMo)
Set the start of the week.
|
void |
setXPart(java.lang.String xname,
java.lang.String value)
Sets an x-part. x-parts are supported by RFC 2445 only.
|
java.lang.String |
toString() |
public final RecurrenceRule.RfcMode mode
public RecurrenceRule(java.lang.String recur)
throws InvalidRecurrenceRuleException
RecurrenceRule.RfcMode RecurrenceRule.RfcMode.RFC5545_LAX. The parser will be quite tolerant and skip any invalid
parts to produce a valid recurrence rule.recur - A recurrence rule string as defined in RFC 5545.InvalidRecurrenceRuleException - If an unrecoverable error occurs when parsing the rule (like FREQ is missing, or mutually exclusive parts have been found).public RecurrenceRule(java.lang.String recur,
RecurrenceRule.RfcMode mode)
throws InvalidRecurrenceRuleException
RecurrenceRule.RfcMode.recur - A recurrence rule string as defined in RFC 5545.mode - A RecurrenceRule.RfcMode to change the parsing behaviour in case of errors.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).public RecurrenceRule(Freq freq)
RecurrenceRule.RfcMode.RFC5545_STRICT, so created rules will have to
comply with RFC 5545, otherwise an exception is thrown.freq - The Freq values that specified the base frequency for this rule.public RecurrenceRule(Freq freq, RecurrenceRule.RfcMode mode)
RecurrenceRule.RfcMode.freq - The Freq values that specified the base frequency for this rule.mode - A RecurrenceRule.RfcMode to change the behavior in case of errors.public Freq getFreq()
Freq value of this rule.public void setFreq(Freq freq, boolean silent)
TODO: check if the rule is still valid afterwards (honor the silent parameter)
freq - The new Freq value of this rule.silent - true to drop RecurrenceRule.Parts that are no longer valid with the new frequency silently, false to throw an exception in
that case.public RecurrenceRule.Skip getSkip()
RecurrenceRule.Skip value of this rule.public void setSkip(RecurrenceRule.Skip skip)
RecurrenceRule.Part.RSCALE value when setting a SKIP rule, otherwise it will default to GREGORIAN
calendar.skip - The new RecurrenceRule.Skip value of this rule, null and RecurrenceRule.Skip.OMIT will remove the SKIP part, the later one is the default anyway.public int getInterval()
1 if no INTERVAL has been specified.public void setInterval(int interval)
1 will just remove the INTERVAL part since that's the
default value anyway.interval - The new interval of this rule.java.lang.IllegalArgumentException - if interval is not a positive integer value.public org.dmfs.rfc5545.DateTime getUntil()
DateTime set to the correct time. The time zone is either
UTC or floating.DateTime set to the UNTIL value if an UNTIL part is present, null otherwise.public void setUntil(org.dmfs.rfc5545.DateTime until)
until is not UTC and until is
not floating it's automatically converted to UTC.until - The UNTIL part of this rule or null to let the instances recur forever.public java.lang.Integer getCount()
nullnull.public void setCount(int count)
count - The number if instances.public boolean isInfinite()
true if this rule contains neither an RecurrenceRule.Part.UNTIL nor a RecurrenceRule.Part.COUNT part, false otherwise.public boolean hasPart(RecurrenceRule.Part part)
part - The part if interest.true if this rule has this part, false otherwisepublic java.util.List<java.lang.Integer> getByPart(RecurrenceRule.Part part)
part may be one of RecurrenceRule.Part.BYSECOND, RecurrenceRule.Part.BYMINUTE, RecurrenceRule.Part.BYHOUR, RecurrenceRule.Part.BYMONTHDAY,
RecurrenceRule.Part.BYYEARDAY, RecurrenceRule.Part.BYWEEKNO, RecurrenceRule.Part.BYMONTH, or RecurrenceRule.Part.BYSETPOS. To get RecurrenceRule.Part.BYDAY use getByDayPart().
part - The by-rule to return.public void setByPart(RecurrenceRule.Part part, java.util.List<java.lang.Integer> value) throws InvalidRecurrenceRuleException
part may be one of RecurrenceRule.Part.BYSECOND, RecurrenceRule.Part.BYMINUTE, RecurrenceRule.Part.BYHOUR, RecurrenceRule.Part.BYMONTHDAY,
RecurrenceRule.Part.BYYEARDAY, RecurrenceRule.Part.BYWEEKNO, RecurrenceRule.Part.BYMONTH, or RecurrenceRule.Part.BYSETPOS. To set RecurrenceRule.Part.BYDAY use setByDayPart(List).
part - The by-rule to set.value - A list of integers that specify the rule or null (or an empty list) to remove the part.InvalidRecurrenceRuleException - if the list would become invalid by adding this part (this respects the current RecurrenceRule.RfcMode.public void setByPart(RecurrenceRule.Part part, java.lang.Integer... values) throws InvalidRecurrenceRuleException
part may be one of RecurrenceRule.Part.BYSECOND, RecurrenceRule.Part.BYMINUTE, RecurrenceRule.Part.BYHOUR, RecurrenceRule.Part.BYMONTHDAY,
RecurrenceRule.Part.BYYEARDAY, RecurrenceRule.Part.BYWEEKNO, RecurrenceRule.Part.BYMONTH, or RecurrenceRule.Part.BYSETPOS. To set RecurrenceRule.Part.BYDAY use setByDayPart(List).
part - The by-rule to set.values - Integers that specify the rule or null (or an empty list) to remove the part.InvalidRecurrenceRuleException - if the list would become invalid by adding this part (this respects the current RecurrenceRule.RfcMode.public void setByDayPart(java.util.List<RecurrenceRule.WeekdayNum> value)
value - A List of RecurrenceRule.WeekdayNums or null or an empty List to remove the partpublic java.util.List<RecurrenceRule.WeekdayNum> getByDayPart()
List of RecurrenceRule.WeekdayNums if the part is present or null if there is no such part.public org.dmfs.rfc5545.Weekday getWeekStart()
Weekday.MO.Weekday.public void setWeekStart(org.dmfs.rfc5545.Weekday wkst)
Weekday.MO the WKST part is effectively removed, since that's the default value. This value is
important for rules having a BYWEEKNO or BYDAY part.wkst - The start of the week to use when calculating the instances.public void setWeekStart(org.dmfs.rfc5545.Weekday wkst,
boolean keepWkStMo)
Weekday.MO the WKST part is effectively removed (unless keepWkStMo == true), since
that's the default value. This value is important for rules having a BYWEEKNO or BYDAY part.wkst - The start of the week to use when calculating the instances.keepWkStMo - set to true to keep the WKST field if the value is Weekday.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.public void setXPart(java.lang.String xname,
java.lang.String value)
mode is set to RecurrenceRule.RfcMode.RFC5545_LAX a call to this method will do nothing. If
mode is set to RecurrenceRule.RfcMode.RFC5545_STRICT this method will throw an UnsupportedOperationException. Note that calling this method in RFC 2445 mode will override any existing x-part of the same name.
xname - The name of the x-part. Must be a valid identifier.value - The value of the x-part. Must be a valid name.java.lang.UnsupportedOperationException - if mode is set to RecurrenceRule.RfcMode.RFC5545_STRICT.public boolean hasXPart(java.lang.String xname)
false if
mode equals RecurrenceRule.RfcMode.RFC5545_LAX or RecurrenceRule.RfcMode.RFC5545_STRICT.xname - The name of the x-part to check for.true if the part is present, false otherwise.public java.lang.String getXPart(java.lang.String xname)
null if mode equals RecurrenceRule.RfcMode.RFC5545_LAX or RecurrenceRule.RfcMode.RFC5545_STRICT.xname - The name of the x-part to return.null.public RecurrenceRuleIterator iterator(long start, java.util.TimeZone timezone)
RuleIterator that iterates all instances of this rule. Note: If the rule contains an UNTIL part with a floating
value, you have to provide null as the timezone.
start - The time of the first instance in milliseconds since the epoch.timezone - The TimeZone of the first instance or null for floating times.RecurrenceRuleIterator.public RecurrenceRuleIterator iterator(org.dmfs.rfc5545.DateTime start)
RuleIterator that 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
start - The first instance.RuleIterator.public java.lang.String toString()
toString in class java.lang.Object