com.miginfocom.calendar.activity.recurrence
Class RecurrenceRule

java.lang.Object
  extended by com.miginfocom.calendar.activity.recurrence.RecurrenceRule
All Implemented Interfaces:
Recurrence

public class RecurrenceRule
extends java.lang.Object
implements Recurrence

This is the default implementation of a recurring RRULE and EXRULE in RFC 2445. RFC 2445

See Also:
CompositeRecurrence

Constructor Summary
RecurrenceRule()
          Constructor.
RecurrenceRule(int freqField)
          Constructor.
RecurrenceRule(int freqField, int interval)
          Constructor
 
Method Summary
 void addByXXXRule(ByXXXRuleData byXXXRuleData)
          Adds a ByXXX rule to this recurrence.
 int[] getBySetPos()
          Return the value setted by setBySetPos(int[])
 ByXXXRuleData[] getByXXXRules()
          Returns all ByXXXRuleDatas contains in this object.
 java.util.ArrayList getDateRanges(DateRangeI baseRange, DateRangeI withinRange, boolean optimizeRange)
          Will return the recurrences for this rule.
 int getFrequency()
          Returns the frequency field
 int getInterval()
          Returns the recurrence interval
 java.lang.Long getLastRecurrenceMillis(DateRangeI baseRange, java.util.Calendar max)
          Returns the end date (millisecond inclusive) of the last recurrence or null if the recurrence will continue forever.
 java.lang.Integer getRepetitionCount()
          Returns the maximum repetitions for the recurrence or null if "forever"
 java.util.Calendar getUntilDate()
          Returns the max extent of the recurrence or null if "forever"
 java.lang.Integer getWeekStart()
          Returns the week start rule associated with this recurrence rule.
 boolean isRepeatingForever()
          Returns if this recurrence has no end limit and will thus be repeating forever.
 void setBySetPos(int[] bySetPos)
          In the values (ranges) specified by this recurrence's BYXXXRULES only concider the indexes in bySetPos.
 void setByXXXRules(ByXXXRuleData[] byXXXRules)
          Sets the array with ByXXXRuleData object to use for this recurrencey.
 void setFrequency(int freqField)
          Sets the frequency field
 void setInterval(int interval)
          Sets the recurrence interval
 void setRepetitionCount(java.lang.Integer repCount)
          Sets the maximum repetitions for the recurrence or null if "forever" Only one of UntilDate and RepetitionCount may be set according to RFC2445 but you can here.
 void setUntilDate(java.util.Calendar untilCal)
          Sets the max extent of the recurrence or null if "forever".
 void setWeekStart(java.lang.Integer weekStart)
          Sets the week start rule associated with this recurrence rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecurrenceRule

public RecurrenceRule()
Constructor. Interval set to 1 and frequency set to Calendar#DAY_OF_WEEK.


RecurrenceRule

public RecurrenceRule(int freqField)
Constructor. Interval set to 1.

Parameters:
freqField - The field (E.g. Calendar.DAY_OF_YEAR to iterate over.
"YEARLY" is Calendar.YEAR
"MONTHLY" is Calendar.MONTH
"WEEKLY" is Calendar.WEEK_OF_YEAR
"DAILY" is Calendar.DAY_OF_YEAR
"HOURLY" is Calendar.HOUR
"MINUTELY" is Calendar.MINUTE
"SECONDLY" is Calendar.SECOND

RecurrenceRule

public RecurrenceRule(int freqField,
                      int interval)
Constructor

Parameters:
freqField - The field (E.g. Calendar.DAY_OF_YEAR to iterate over.
"YEARLY" is Calendar.YEAR
"MONTHLY" is Calendar.MONTH
"WEEKLY" is Calendar.WEEK_OF_YEAR
"DAILY" is Calendar.DAY_OF_YEAR
"HOURLY" is Calendar.HOUR
"MINUTELY" is Calendar.MINUTE
"SECONDLY" is Calendar.SECOND
interval - An interval. E.g. 2 means "every other".
Method Detail

getDateRanges

public java.util.ArrayList getDateRanges(DateRangeI baseRange,
                                         DateRangeI withinRange,
                                         boolean optimizeRange)
Will return the recurrences for this rule. Will not return baseRange if it isn't a valid part in the recurrence rule. No recurrences before baseRange's start date-time will be returned.

Specified by:
getDateRanges in interface Recurrence
Parameters:
baseRange - The range on which to base the returned ranges. Called DTSTART/DTEND in RFC 2445 (iCalendar). This is the first dateRange in the recurrence.
withinRange - All returned ranges will have touch this range. Never null.
optimizeRange - Optimizes the recurrence rule for withinRange. Set to false if the recurrence is bugging. This is working in the tests but the algorithm is quite advanced and is a bit hard to find all possibilities for how this optimization works. Note that this value should not in any way change the returned values, it will only use less computations if set to true.
Returns:
The recurrence date ranges. Never null. The list will not be sorted. Will contain newly created and free to use MutableDateRanges

getLastRecurrenceMillis

public java.lang.Long getLastRecurrenceMillis(DateRangeI baseRange,
                                              java.util.Calendar max)
Description copied from interface: Recurrence
Returns the end date (millisecond inclusive) of the last recurrence or null if the recurrence will continue forever.

Specified by:
getLastRecurrenceMillis in interface Recurrence
Parameters:
baseRange - The range on which to base the recurrence on ranges. Called DTSTART/DTEND in RFC 2445 (iCalendar)
max - If not null the evaluation will never go after this date and this will thus be the latest date possible to return. Since the recurrences have to be evaluated in all to return the last recurrence this can be a safetynet to not make the evaluation take too much time.
Returns:
The end date (millisecond inclusive) of the last recurrence or null if the recurrence will continue forever.

isRepeatingForever

public boolean isRepeatingForever()
Description copied from interface: Recurrence
Returns if this recurrence has no end limit and will thus be repeating forever.

Specified by:
isRepeatingForever in interface Recurrence
Returns:
If this recurrence has no end limit and will thus be repeating forever.

setFrequency

public void setFrequency(int freqField)
Sets the frequency field

Parameters:
freqField - The field (E.g. Calendar.DAY_OF_YEAR to iterate over.
"YEARLY" is Calendar.YEAR
"MONTHLY" is Calendar.MONTH
"WEEKLY" is Calendar.WEEK_OF_YEAR
"DAILY" is Calendar.DAY_OF_YEAR
"HOURLY" is Calendar.HOUR_OF_DAY
"MINUTELY" is Calendar.MINUTE
"SECONDLY" is Calendar.SECOND

getFrequency

public int getFrequency()
Returns the frequency field

Returns:
The field (E.g. Calendar.DAY_OF_YEAR to iterate over.
"YEARLY" is Calendar.YEAR
"MONTHLY" is Calendar.MONTH
"WEEKLY" is Calendar.WEEK_OF_YEAR
"DAILY" is Calendar.DAY_OF_YEAR
"HOURLY" is Calendar.HOUR_OF_DAY
"MINUTELY" is Calendar.MINUTE
"SECONDLY" is Calendar.SECOND

setInterval

public void setInterval(int interval)
Sets the recurrence interval

Parameters:
interval - An interval. E.g. 2 mens "every other".

getInterval

public int getInterval()
Returns the recurrence interval

Returns:
An interval. E.g. 2 mens "every other".

getUntilDate

public java.util.Calendar getUntilDate()
Returns the max extent of the recurrence or null if "forever"

Returns:
The max extent of the recurrence or null if "forever"
See Also:
getRepetitionCount()

setUntilDate

public void setUntilDate(java.util.Calendar untilCal)
Sets the max extent of the recurrence or null if "forever". Only one of UntilDate and RepetitionCount may be set according to RFC2445 but you can here.

Parameters:
untilCal - The max extent of the recurrence or null if "forever"
See Also:
setRepetitionCount(Integer)

getRepetitionCount

public java.lang.Integer getRepetitionCount()
Returns the maximum repetitions for the recurrence or null if "forever"

Returns:
The maximum repetitions for the recurrence or null if "forever"
See Also:
getUntilDate()

setRepetitionCount

public void setRepetitionCount(java.lang.Integer repCount)
Sets the maximum repetitions for the recurrence or null if "forever" Only one of UntilDate and RepetitionCount may be set according to RFC2445 but you can here.

Parameters:
repCount - The maximum repetitions for the recurrence or null if "forever"
See Also:
setUntilDate(Calendar)

getWeekStart

public java.lang.Integer getWeekStart()
Returns the week start rule associated with this recurrence rule. This value does currently not affect the outcome of the recurrence dates, it is just a holder of the information for re-cretation.

Returns:
The week start if set. E.g. Calendar.MONDAY.

setWeekStart

public void setWeekStart(java.lang.Integer weekStart)
Sets the week start rule associated with this recurrence rule. This value does currently not affect the outcome of the recurrence dates, it is just a holder of the information for re-cretation.

Parameters:
weekStart - The week start or null if not specified. E.g. Calendar.MONDAY.

addByXXXRule

public void addByXXXRule(ByXXXRuleData byXXXRuleData)
Adds a ByXXX rule to this recurrence. See "RFC 2445" for more information about recurrence.

Parameters:
byXXXRuleData - The rule to add.

getByXXXRules

public ByXXXRuleData[] getByXXXRules()
Returns all ByXXXRuleDatas contains in this object. The live array. See "RFC 2445" for more information about recurrence.

Returns:
ll ByXXXRuleDatas contains in this object. The live array, may be null and must not be altered!

setByXXXRules

public void setByXXXRules(ByXXXRuleData[] byXXXRules)
Sets the array with ByXXXRuleData object to use for this recurrencey. See "RFC 2445" for more information about recurrence.

Parameters:
byXXXRules - The object to use. Reference is kept and sorted

setBySetPos

public void setBySetPos(int[] bySetPos)
In the values (ranges) specified by this recurrence's BYXXXRULES only concider the indexes in bySetPos.

For instance an element of value 1 would only keep the second value (it's 0-based) and -2 would only keep the second to last value. Can be of any length and elements that corresponds to an nonexistent position is quietly ignored.

This correspons to BYSETPOS in RFC 2445.

Parameters:
bySetPos - A list of positions to filter by when evaluating the ByXXXRules. null turns of filter. Note that the element's value is 0-based as opposed to the values in RFC 2445 which are 1-based.

getBySetPos

public int[] getBySetPos()
Return the value setted by setBySetPos(int[])

Returns:
The value setted by setBySetPos(int[]). May be null.
See Also:
setBySetPos(int[])


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.