Package net.fortuna.ical4j.model
Class Calendar
- java.lang.Object
-
- net.fortuna.ical4j.model.Calendar
-
- All Implemented Interfaces:
Serializable
,ComponentContainer<CalendarComponent>
,PropertyContainer
public class Calendar extends Object implements Serializable, PropertyContainer, ComponentContainer<CalendarComponent>
$Id$ [Apr 5, 2004] Defines an iCalendar calendar.4.6 Calendar Components The body of the iCalendar object consists of a sequence of calendar properties and one or more calendar components. The calendar properties are attributes that apply to the calendar as a whole. The calendar components are collections of properties that express a particular calendar semantic. For example, the calendar component can specify an event, a to-do, a journal entry, time zone information, or free/busy time information, or an alarm. The body of the iCalendar object is defined by the following notation: icalbody = calprops component calprops = 2*( ; 'prodid' and 'version' are both REQUIRED, ; but MUST NOT occur more than once prodid /version / ; 'calscale' and 'method' are optional, ; but MUST NOT occur more than once calscale / method / x-prop ) component = 1*(eventc / todoc / journalc / freebusyc / / timezonec / iana-comp / x-comp) iana-comp = "BEGIN" ":" iana-token CRLF 1*contentline "END" ":" iana-token CRLF x-comp = "BEGIN" ":" x-name CRLF 1*contentline "END" ":" x-name CRLF
Example 1 - Creating a new calendar:Calendar calendar = new Calendar(); calendar.add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); calendar.add(Version.VERSION_2_0); calendar.add(CalScale.GREGORIAN); // Add events, etc..
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Calendar()
Default constructor.Calendar(Calendar c)
Creates a shallow copy of the specified calendar.Calendar(ComponentList<CalendarComponent> components)
Constructs a new calendar with no properties and the specified components.Calendar(PropertyList properties, ComponentList<CalendarComponent> components)
Initialise a Calendar object using the default configured validator.Calendar(PropertyList p, ComponentList<CalendarComponent> c, Validator<Calendar> validator)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Calendar
copy()
Creates a deep copy of the calendar.boolean
equals(Object arg0)
Optional<CalScale>
getCalendarScale()
Deprecated.ComponentList<CalendarComponent>
getComponentList()
<C extends CalendarComponent>
List<C>getComponents()
String
getContentType(Charset charset)
Returns an appropriate MIME Content-Type for the calendar object instance.Optional<Method>
getMethod()
Deprecated.Optional<ProdId>
getProductId()
Deprecated.<T extends Property>
List<T>getProperties()
PropertyList
getPropertyList()
Uid
getUid()
Returns a unique identifier as specified by components in the calendar instance.Optional<Version>
getVersion()
Deprecated.int
hashCode()
Calendar
merge(Calendar c2)
Merge all properties and components from the specified calendar with this instance.void
setComponentList(ComponentList<CalendarComponent> components)
void
setPropertyList(PropertyList properties)
Calendar[]
split()
Splits a calendar object into distinct calendar objects for unique identifiers (UID).String
toString()
void
validate()
Perform validation on the calendar, its properties and its components in its current state.void
validate(boolean recurse)
Perform validation on the calendar in its current state.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.fortuna.ical4j.model.ComponentContainer
add, getComponent, getComponents, remove, replace
-
Methods inherited from interface net.fortuna.ical4j.model.PropertyContainer
add, getProperties, getProperty, getRequiredProperty, remove, removeAll, replace
-
-
-
-
Field Detail
-
BEGIN
public static final String BEGIN
Begin token.- See Also:
- Constant Field Values
-
VCALENDAR
public static final String VCALENDAR
Calendar token.- See Also:
- Constant Field Values
-
END
public static final String END
End token.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Calendar
public Calendar()
Default constructor.
-
Calendar
public Calendar(ComponentList<CalendarComponent> components)
Constructs a new calendar with no properties and the specified components.- Parameters:
components
- a list of components to add to the calendar
-
Calendar
public Calendar(PropertyList properties, ComponentList<CalendarComponent> components)
Initialise a Calendar object using the default configured validator.- Parameters:
properties
- a list of initial calendar propertiescomponents
- a list of initial calendar components
-
Calendar
public Calendar(PropertyList p, ComponentList<CalendarComponent> c, Validator<Calendar> validator)
Constructor.- Parameters:
p
- a list of propertiesc
- a list of componentsvalidator
- used to ensure the validity of the calendar instance
-
Calendar
public Calendar(Calendar c)
Creates a shallow copy of the specified calendar.- Parameters:
c
- the calendar to copy
-
-
Method Detail
-
getComponents
public <C extends CalendarComponent> List<C> getComponents()
-
getComponentList
public final ComponentList<CalendarComponent> getComponentList()
- Specified by:
getComponentList
in interfaceComponentContainer<CalendarComponent>
- Returns:
- Returns the underlying component list.
-
setComponentList
public void setComponentList(ComponentList<CalendarComponent> components)
- Specified by:
setComponentList
in interfaceComponentContainer<CalendarComponent>
-
getPropertyList
public final PropertyList getPropertyList()
- Specified by:
getPropertyList
in interfacePropertyContainer
- Returns:
- Returns the underlying property list.
-
setPropertyList
public void setPropertyList(PropertyList properties)
- Specified by:
setPropertyList
in interfacePropertyContainer
-
validate
public final void validate() throws ValidationException
Perform validation on the calendar, its properties and its components in its current state.- Throws:
ValidationException
- where the calendar is not in a valid state
-
validate
public void validate(boolean recurse) throws ValidationException
Perform validation on the calendar in its current state.- Parameters:
recurse
- indicates whether to validate the calendar's properties and components- Throws:
ValidationException
- where the calendar is not in a valid state
-
copy
public final Calendar copy()
Creates a deep copy of the calendar.- Returns:
- a new calendar instance that protects against mutation of the source calendar
-
merge
public Calendar merge(Calendar c2)
Merge all properties and components from the specified calendar with this instance. Note that the merge process is not very sophisticated, and may result in invalid calendar data (e.g. multiple properties of a type that should only be specified once).- Parameters:
c2
- the second calendar to merge- Returns:
- a Calendar instance containing all properties and components from both of the specified calendars
-
split
public Calendar[] split()
Splits a calendar object into distinct calendar objects for unique identifiers (UID).- Returns:
- an array of calendar objects
-
getUid
public Uid getUid() throws ConstraintViolationException
Returns a unique identifier as specified by components in the calendar instance.- Returns:
- the UID property
- Throws:
ConstraintViolationException
- if zero or more than one unique identifier(s) is found in the specified calendar
-
getProductId
@Deprecated public final Optional<ProdId> getProductId()
Deprecated.Returns the mandatory prodid property.- Returns:
- the PRODID property, or null if property doesn't exist
-
getVersion
@Deprecated public final Optional<Version> getVersion()
Deprecated.Returns the mandatory version property.- Returns:
- the VERSION property, or null if property doesn't exist
-
getCalendarScale
@Deprecated public final Optional<CalScale> getCalendarScale()
Deprecated.Returns the optional calscale property.- Returns:
- the CALSCALE property, or null if property doesn't exist
-
getMethod
@Deprecated public final Optional<Method> getMethod()
Deprecated.Returns the optional method property.- Returns:
- the METHOD property, or null if property doesn't exist
-
getContentType
public String getContentType(Charset charset)
Returns an appropriate MIME Content-Type for the calendar object instance.- Parameters:
charset
- an optional encoding- Returns:
- a content type string
-
-