Package org.silverpeas.core.calendar
Class Recurrence
- java.lang.Object
-
- org.silverpeas.core.calendar.Recurrence
-
- All Implemented Interfaces:
Serializable
@Entity public class Recurrence extends Object implements Serializable
It defines the rules of the recurrence of aPlannableOnCalendar
in its planning in a calendar. APlannableOnCalendar
recurrence is defined by a recurrence period, id est a frequency (hourly, daily, weekly, monthly, or yearly), and optionally by some of the following properties:- some days of week on which the
PlannableOnCalendar
should regularly occur - some exceptions in the recurrence period of the
PlannableOnCalendar
- a termination condition.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Recurrence.ExceptionDateNormalizer
This converter is dedicated to theexceptionDates
collection.
-
Field Summary
Fields Modifier and Type Field Description static Recurrence
NO_RECURRENCE
A constant that defines a specific value for an empty recurrence.static int
NO_RECURRENCE_COUNT
A constant that defines a specific value for no recurrence count limit.static OffsetDateTime
NO_RECURRENCE_END_DATE
A constant that defines a specific value for no recurrence end date.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Recurrence()
Constructs an empty recurrence for the persistence engine.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Recurrence
copy()
Copies the specified recurrence into another object.Recurrence
endless()
Sets that the recurrence never ends.boolean
equals(Object o)
static Recurrence
every(int frequencyValue, TimeUnit frequencyUnit)
Creates a new recurrence from the specified frequency.static Recurrence
every(TimeUnit frequencyUnit)
Creates a new recurrence from the specified frequency.Recurrence
excludeEventOccurrencesStartingAt(Temporal... temporal)
Excludes from this recurrence rule the occurrences originally starting at the specified date or datetime.static Recurrence
from(RecurrencePeriod period)
Creates a new recurrence by specifying the recurrence period at which aPlannableOnCalendar
should recur.protected void
generateId()
Set<DayOfWeekOccurrence>
getDaysOfWeek()
Gets the days of week on which thePlannableOnCalendar
should recur each time.Optional<Temporal>
getEndDate()
Gets the end date of the period over which this recurrence is played by taking into account either the number of time he recurrentPlannableOnCalendar
occurs or the end date of its recurrence.Set<Temporal>
getExceptionDates()
Gets the datetime exceptions to this recurrence rule.RecurrencePeriod
getFrequency()
Gets the frequency at which thePlannableOnCalendar
should recur.int
getRecurrenceCount()
Gets the number of time thePlannableOnCalendar
should occur.Optional<Temporal>
getRecurrenceEndDate()
Gets the end date of the recurrence.Temporal
getStartDate()
Gets the start date of the period over which this recurrence is played.int
hashCode()
boolean
isEndless()
Is this recurrence endless?Recurrence
on(DayOfWeek... days)
Sets some specific days of week at which aPlannableOnCalendar
should periodically occur.Recurrence
on(List<DayOfWeekOccurrence> days)
Sets some specific occurrences of day of week at which aPlannableOnCalendar
should periodically occur within monthly or yearly period.Recurrence
on(DayOfWeekOccurrence... days)
Sets some specific occurrences of day of week at which aPlannableOnCalendar
should periodically occur within a monthly or a yearly period.Recurrence
onNoSpecificDay()
Sets that the recurrence is not linked to a specific day.Recurrence
until(int recurrenceCount)
Sets a termination to this recurrence by specifying the count of time aPlannableOnCalendar
should occur.Recurrence
until(Temporal endDate)
Sets a termination to this recurrence by specifying an inclusive date or datetime.Recurrence
withFrequency(RecurrencePeriod frequency)
Sets a frequency to this recurrence by specifying a recurrence period.
When the new frequency is a daily or a yearly one, days of weeks are reset.
-
-
-
Field Detail
-
NO_RECURRENCE
public static final Recurrence NO_RECURRENCE
A constant that defines a specific value for an empty recurrence.
-
NO_RECURRENCE_COUNT
public static final int NO_RECURRENCE_COUNT
A constant that defines a specific value for no recurrence count limit.- See Also:
- Constant Field Values
-
NO_RECURRENCE_END_DATE
public static final OffsetDateTime NO_RECURRENCE_END_DATE
A constant that defines a specific value for no recurrence end date.
-
-
Method Detail
-
every
public static Recurrence every(TimeUnit frequencyUnit)
Creates a new recurrence from the specified frequency.- Parameters:
frequencyUnit
- the unit of the frequency: DAY means DAILY, WEEK means weekly, MONTH means monthly or YEAR means YEARLY.- Returns:
- the event recurrence instance.
-
every
public static Recurrence every(int frequencyValue, TimeUnit frequencyUnit)
Creates a new recurrence from the specified frequency. For example every(2, MONTH) means every 2 month.- Parameters:
frequencyValue
- a positive number indicating how many times thePlannableOnCalendar
occurs.frequencyUnit
- the frequency unit: DAY, WEEK, MONTH, or YEAR.- Returns:
- the event recurrence instance.
-
from
public static Recurrence from(RecurrencePeriod period)
Creates a new recurrence by specifying the recurrence period at which aPlannableOnCalendar
should recur.- Parameters:
period
- the recurrence period of the event.- Returns:
- the event recurrence instance.
-
excludeEventOccurrencesStartingAt
public Recurrence excludeEventOccurrencesStartingAt(Temporal... temporal)
Excludes from this recurrence rule the occurrences originally starting at the specified date or datetime. In the case the argument is one or moreOffsetDateTime
, their time is set with the time of the start datetime of the calendar component concerned by this recurrence. If the calendar component from which the occurrences come is on all day, the specified temporal instance is then converted into aLocalDate
instance. Otherwise, if the the temporal instance is aLocalDate
it is then converted into aOffsetDateTime
with the time the one of the calendar component's start datetime; you have to ensure then theLocalDate
you pass comes from a value in UTC. If the temporal instance is already anOffsetDateTime
, then it is converted in UTC and its time set with the one of the calendar component's start datetime.- Parameters:
temporal
- a list of eitherLocalDate
orOffsetDateTime
at which originally start the occurrences to exclude.- Returns:
- itself.
-
on
public Recurrence on(DayOfWeek... days)
Sets some specific days of week at which aPlannableOnCalendar
should periodically occur. For a weekly recurrence, the specified days of week are the first one in the week. For other frequency, the specified days of week will be all the occurrences of those days of week in the recurrence period. For example, recur every weeks on monday and on tuesday or recur every month on all saturdays and on all tuesdays. This method can only be applied on recurrence period higher than the day, otherwise anIllegalStateException
will be thrown.- Parameters:
days
- the days of week at which aPlannableOnCalendar
should occur. Theses days replace the ones already set in the recurrence.- Returns:
- itself.
-
on
public Recurrence on(DayOfWeekOccurrence... days)
Sets some specific occurrences of day of week at which aPlannableOnCalendar
should periodically occur within a monthly or a yearly period. For example, recur every month on the third monday and on the first tuesday. The days of week for a weekly recurrence can also be indicated if, and only if, the nth occurrence of the day is the first one or all occurrences (as there is actually only one possible occurrence of a day in a week); any value other than 1 orALL_OCCURRENCES
is considered as an error and an IllegalArgumentException is thrown. This method can only be applied on recurrence period higher than the day, otherwise anIllegalStateException
will be thrown.- Parameters:
days
- the occurrences of day of week at which an event should occur. Theses days replace the ones already set in the recurrence.- Returns:
- itself.
-
on
public Recurrence on(List<DayOfWeekOccurrence> days)
Sets some specific occurrences of day of week at which aPlannableOnCalendar
should periodically occur within monthly or yearly period. For example, recur every month on the third monday and on the first tuesday. The days of week for a weekly recurrence can also be indicated if, and only if, the nth occurrence of the day is the first one or all occurrences (as there is actually only one possible occurrence of a day in a week); any value other than 1 orALL_OCCURRENCES
is considered as an error and an IllegalArgumentException is thrown. This method can only be applied on recurrence period higher than the day, otherwise anIllegalStateException
will be thrown.- Parameters:
days
- a list of days of week at which aPlannableOnCalendar
should occur. Theses days replace the ones already set in the recurrence.- Returns:
- itself.
-
onNoSpecificDay
public Recurrence onNoSpecificDay()
Sets that the recurrence is not linked to a specific day. So the occurrence generation will take into account only the start datetime of the event.- Returns:
- itself.
-
until
public Recurrence until(int recurrenceCount)
Sets a termination to this recurrence by specifying the count of time aPlannableOnCalendar
should occur. Settings this termination unset the recurrence end date/datetime.- Parameters:
recurrenceCount
- the number of time aPlannableOnCalendar
should occur.- Returns:
- itself.
-
until
public Recurrence until(Temporal endDate)
Sets a termination to this recurrence by specifying an inclusive date or datetime. If a datetime is passed, it is set in UTC/Greenwich and then the time is overridden by the one of the start date time of the calendar component concerned by this recurrence. In the case the calendar component is on all day(s), then the specified datetime is converted into a date. Settings this termination unset the number of time aPlannableOnCalendar
should occur.- Parameters:
endDate
- the inclusive date or datetime at which the recurrence ends.- Returns:
- itself.
-
endless
public Recurrence endless()
Sets that the recurrence never ends.- Returns:
- itself.
-
withFrequency
public Recurrence withFrequency(RecurrencePeriod frequency)
Sets a frequency to this recurrence by specifying a recurrence period.
When the new frequency is a daily or a yearly one, days of weeks are reset.- Parameters:
frequency
- the frequency to set.- Returns:
- itself.
-
isEndless
public boolean isEndless()
Is this recurrence endless?- Returns:
- true if this recurrence has no upper bound defined. False otherwise.
-
getFrequency
public RecurrencePeriod getFrequency()
Gets the frequency at which thePlannableOnCalendar
should recur.- Returns:
- the frequency as a RecurrencePeriod instance.
-
getRecurrenceCount
public int getRecurrenceCount()
Gets the number of time thePlannableOnCalendar
should occur. If NO_RECURRENCE_COUNT is returned, then no termination by recurrence count is defined.- Returns:
- the recurrence count or NO_RECURRENCE_COUNT if no such termination is defined.
-
getRecurrenceEndDate
public Optional<Temporal> getRecurrenceEndDate()
Gets the end date of the recurrence. The end date of the recurrence can be unspecified, in that case the returned end date is empty.- Returns:
- an optional recurrence end date. The optional is empty if the end date of the
recurrence is unspecified, otherwise the recurrence termination date or datetime can be get
from the
Optional
. The returned datetime is from UTC/Greenwich.
-
getEndDate
public Optional<Temporal> getEndDate()
Gets the end date of the period over which this recurrence is played by taking into account either the number of time he recurrentPlannableOnCalendar
occurs or the end date of its recurrence. The computed date can match the date of the last occurrence of the recurrentPlannableOnCalendar
for a finite recurrence without an end date explicitly set. It can be also a date after the last occurrence. The exception dates in the recurrence rule aren't taken into account. If this recurrence isn't yet applied to any recurrence calendar component, then anIllegalStateException
exception is thrown.- Returns:
- an optional recurrence actual end date. The optional is empty if the recurrence is endless.
-
getStartDate
public Temporal getStartDate()
Gets the start date of the period over which this recurrence is played. It is the date of the first occurrence of the recurrentPlannableOnCalendar
on which this recurrence is applied.If this recurrence isn't yet applied to any recurrence calendar component, then an
IllegalStateException
exception is thrown.- Returns:
- the start date of this recurrence.
-
getDaysOfWeek
public Set<DayOfWeekOccurrence> getDaysOfWeek()
Gets the days of week on which thePlannableOnCalendar
should recur each time.- Returns:
- an unmodifiable set of days of week or an empty set if no days of week are set to this recurrence.
-
getExceptionDates
public Set<Temporal> getExceptionDates()
Gets the datetime exceptions to this recurrence rule. The returned datetime are the start datetime of the occurrences that are excluded from this recurrence rule. They are the exception in the application of the recurrence rule.- Returns:
- a set of either
LocalDate
orOffsetDateTime
instances, or an empty set if there is no exception dates to this recurrence.
-
copy
public Recurrence copy()
Copies the specified recurrence into another object. The identifier of the recurrence is set to null as it is not yet persisted.- Returns:
- a copy of this recurrence.
-
generateId
protected void generateId()
-
-