Module ical4j.core

Class Calendar

java.lang.Object
net.fortuna.ical4j.model.Calendar
All Implemented Interfaces:
Serializable, CalendarPropertyAccessor, ComponentContainer<CalendarComponent>, ComponentListAccessor<CalendarComponent>, FluentCalendar, PropertyContainer, PropertyListAccessor, Prototype<Calendar>

$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:
  • Field Details

  • Constructor Details

    • Calendar

      public Calendar()
      Default constructor.
    • Calendar

      public Calendar(ComponentList<? extends 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<? extends CalendarComponent> components)
      Initialise a Calendar object using the default configured validator.
      Parameters:
      properties - a list of initial calendar properties
      components - a list of initial calendar components
    • Calendar

      public Calendar(PropertyList p, ComponentList<? extends CalendarComponent> c, Validator<Calendar> validator)
      Constructor.
      Parameters:
      p - a list of properties
      c - a list of components
      validator - 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 Details

    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getFluentTarget

      public Calendar getFluentTarget()
      Specified by:
      getFluentTarget in interface FluentCalendar
    • getComponents

      public <C extends CalendarComponent> List<C> getComponents()
    • getComponentList

      public final ComponentList<CalendarComponent> getComponentList()
      Specified by:
      getComponentList in interface ComponentListAccessor<CalendarComponent>
      Returns:
      Returns the underlying component list.
    • setComponentList

      public void setComponentList(ComponentList<CalendarComponent> components)
      Specified by:
      setComponentList in interface ComponentContainer<CalendarComponent>
    • getProperties

      public <T extends Property> List<T> getProperties()
      Explicitly override due to conflict with groovy implicit method..
      Type Parameters:
      T -
      Returns:
    • getPropertyList

      public final PropertyList getPropertyList()
      Specified by:
      getPropertyList in interface PropertyListAccessor
      Returns:
      Returns the underlying property list.
    • setPropertyList

      public void setPropertyList(PropertyList properties)
      Specified by:
      setPropertyList in interface PropertyContainer
    • validate

      public ValidationResult 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 ValidationResult 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.
      Specified by:
      copy in interface Prototype<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
    • 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
    • equals

      public final boolean equals(Object arg0)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object