biweekly.component
Class ICalComponent

java.lang.Object
  extended by biweekly.component.ICalComponent
Direct Known Subclasses:
ICalendar, Observance, RawComponent, VAlarm, VEvent, VFreeBusy, VJournal, VTimezone, VTodo

public abstract class ICalComponent
extends Object

The base class for iCalendar components.

Author:
Michael Angstadt

Field Summary
protected  ListMultimap<Class<? extends ICalComponent>,ICalComponent> components
           
protected  ListMultimap<Class<? extends ICalProperty>,ICalProperty> properties
           
 
Constructor Summary
ICalComponent()
           
 
Method Summary
 void addComponent(ICalComponent component)
          Adds a sub-component to this component.
 RawComponent addExperimentalComponent(String name)
          Adds an experimental sub-component to this component.
 RawProperty addExperimentalProperty(String name, ICalDataType dataType, String value)
          Adds an experimental property to this component.
 RawProperty addExperimentalProperty(String name, String value)
          Adds an experimental property to this component.
 void addProperty(ICalProperty property)
          Adds a property to this component.
protected  void checkOptionalCardinality(List<String> warnings, Class<? extends ICalProperty>... classes)
          Utility method for validating that there is no more than one instance of each of the given properties.
protected  void checkRequiredCardinality(List<String> warnings, Class<? extends ICalProperty>... classes)
          Utility method for validating that there is exactly one instance of each of the given properties.
<T extends ICalComponent>
T
getComponent(Class<T> clazz)
          Gets the first component of a given class.
 ListMultimap<Class<? extends ICalComponent>,ICalComponent> getComponents()
          Gets all the sub-components associated with this component.
<T extends ICalComponent>
List<T>
getComponents(Class<T> clazz)
          Gets all components of a given class.
 RawComponent getExperimentalComponent(String name)
          Gets the first experimental sub-component with a given name.
 List<RawComponent> getExperimentalComponents()
          Gets all experimental sub-components associated with this component.
 List<RawComponent> getExperimentalComponents(String name)
          Gets all experimental sub-component with a given name.
 List<RawProperty> getExperimentalProperties()
          Gets all experimental properties associated with this component.
 List<RawProperty> getExperimentalProperties(String name)
          Gets all experimental properties with a given name.
 RawProperty getExperimentalProperty(String name)
          Gets the first experimental property with a given name.
 ListMultimap<Class<? extends ICalProperty>,ICalProperty> getProperties()
          Gets all the properties associated with this component.
<T extends ICalProperty>
List<T>
getProperties(Class<T> clazz)
          Gets all properties of a given class.
<T extends ICalProperty>
T
getProperty(Class<T> clazz)
          Gets the first property of a given class.
 void removeExperimentalComponents(String name)
          Removes all experimental sub-components that have the given name.
 void removeExperimentalProperty(String name)
          Removes all experimental properties that have the given name.
 void removeProperties(Class<? extends ICalProperty> clazz)
          Removes properties from the iCalendar object.
<T extends ICalComponent>
void
setComponent(Class<T> clazz, T component)
          Replaces all components of a given class with the given component.
 void setComponent(ICalComponent component)
          Replaces all components of a given class with the given component.
 RawComponent setExperimentalComponents(String name)
          Adds an experimental sub-component to this component, removing all existing components that have the same name.
 RawProperty setExperimentalProperty(String name, ICalDataType dataType, String value)
          Adds an experimental property to this component, removing all existing properties that have the same name.
 RawProperty setExperimentalProperty(String name, String value)
          Adds an experimental property to this component, removing all existing properties that have the same name.
<T extends ICalProperty>
void
setProperty(Class<T> clazz, T property)
          Replaces all existing properties of the given class with a single property instance.
 void setProperty(ICalProperty property)
          Replaces all existing properties of the given class with a single property instance.
 List<ValidationWarnings.WarningsGroup> validate(List<ICalComponent> hierarchy)
          Checks the component for data consistency problems or deviations from the spec.
protected  void validate(List<ICalComponent> components, List<String> warnings)
          Checks the component for data consistency problems or deviations from the spec.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

components

protected final ListMultimap<Class<? extends ICalComponent>,ICalComponent> components

properties

protected final ListMultimap<Class<? extends ICalProperty>,ICalProperty> properties
Constructor Detail

ICalComponent

public ICalComponent()
Method Detail

getProperty

public <T extends ICalProperty> T getProperty(Class<T> clazz)
Gets the first property of a given class.

Parameters:
clazz - the property class
Returns:
the property or null if not found

getProperties

public <T extends ICalProperty> List<T> getProperties(Class<T> clazz)
Gets all properties of a given class.

Parameters:
clazz - the property class
Returns:
the properties

getProperties

public ListMultimap<Class<? extends ICalProperty>,ICalProperty> getProperties()
Gets all the properties associated with this component.

Returns:
the properties

addProperty

public void addProperty(ICalProperty property)
Adds a property to this component.

Parameters:
property - the property to add

setProperty

public void setProperty(ICalProperty property)
Replaces all existing properties of the given class with a single property instance.

Parameters:
property - the property (must not be null)

setProperty

public <T extends ICalProperty> void setProperty(Class<T> clazz,
                                                 T property)
Replaces all existing properties of the given class with a single property instance. If the property instance is null, then all instances of that property will be removed.

Parameters:
clazz - the property class (e.g. "Version.class")
property - the property or null to remove

removeProperties

public void removeProperties(Class<? extends ICalProperty> clazz)
Removes properties from the iCalendar object.

Parameters:
clazz - the class of the properties to remove (e.g. "Version.class")

getExperimentalProperty

public RawProperty getExperimentalProperty(String name)
Gets the first experimental property with a given name.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
Returns:
the property or null if none were found

getExperimentalProperties

public List<RawProperty> getExperimentalProperties(String name)
Gets all experimental properties with a given name.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
Returns:
the properties

getExperimentalProperties

public List<RawProperty> getExperimentalProperties()
Gets all experimental properties associated with this component.

Returns:
the properties

addExperimentalProperty

public RawProperty addExperimentalProperty(String name,
                                           String value)
Adds an experimental property to this component.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
value - the property value
Returns:
the property object that was created

addExperimentalProperty

public RawProperty addExperimentalProperty(String name,
                                           ICalDataType dataType,
                                           String value)
Adds an experimental property to this component.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
dataType - the property's data type (e.g. "text") or null if unknown
value - the property value
Returns:
the property object that was created

setExperimentalProperty

public RawProperty setExperimentalProperty(String name,
                                           String value)
Adds an experimental property to this component, removing all existing properties that have the same name.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
value - the property value
Returns:
the property object that was created

setExperimentalProperty

public RawProperty setExperimentalProperty(String name,
                                           ICalDataType dataType,
                                           String value)
Adds an experimental property to this component, removing all existing properties that have the same name.

Parameters:
name - the property name (e.g. "X-ALT-DESC")
dataType - the property's data type (e.g. "text") or null if unknown
value - the property value
Returns:
the property object that was created

removeExperimentalProperty

public void removeExperimentalProperty(String name)
Removes all experimental properties that have the given name.

Parameters:
name - the component name (e.g. "X-ALT-DESC")

getComponent

public <T extends ICalComponent> T getComponent(Class<T> clazz)
Gets the first component of a given class.

Parameters:
clazz - the component class
Returns:
the component or null if not found

getComponents

public <T extends ICalComponent> List<T> getComponents(Class<T> clazz)
Gets all components of a given class.

Parameters:
clazz - the component class
Returns:
the components

getComponents

public ListMultimap<Class<? extends ICalComponent>,ICalComponent> getComponents()
Gets all the sub-components associated with this component.

Returns:
the sub-components

addComponent

public void addComponent(ICalComponent component)
Adds a sub-component to this component.

Parameters:
component - the component to add

setComponent

public void setComponent(ICalComponent component)
Replaces all components of a given class with the given component.

Parameters:
component - the component (must not be null)

setComponent

public <T extends ICalComponent> void setComponent(Class<T> clazz,
                                                   T component)
Replaces all components of a given class with the given component. If the component instance is null, then all instances of that component will be removed.

Parameters:
clazz - the component's class
component - the component or null to remove

getExperimentalComponent

public RawComponent getExperimentalComponent(String name)
Gets the first experimental sub-component with a given name.

Parameters:
name - the component name (e.g. "X-PARTY")
Returns:
the component or null if none were found

getExperimentalComponents

public List<RawComponent> getExperimentalComponents(String name)
Gets all experimental sub-component with a given name.

Parameters:
name - the component name (e.g. "X-PARTY")
Returns:
the components

getExperimentalComponents

public List<RawComponent> getExperimentalComponents()
Gets all experimental sub-components associated with this component.

Returns:
the sub-components

addExperimentalComponent

public RawComponent addExperimentalComponent(String name)
Adds an experimental sub-component to this component.

Parameters:
name - the component name (e.g. "X-PARTY")
Returns:
the component object that was created

setExperimentalComponents

public RawComponent setExperimentalComponents(String name)
Adds an experimental sub-component to this component, removing all existing components that have the same name.

Parameters:
name - the component name (e.g. "X-PARTY")
Returns:
the component object that was created

removeExperimentalComponents

public void removeExperimentalComponents(String name)
Removes all experimental sub-components that have the given name.

Parameters:
name - the component name (e.g. "X-PARTY")

validate

public final List<ValidationWarnings.WarningsGroup> validate(List<ICalComponent> hierarchy)
Checks the component for data consistency problems or deviations from the spec. These problems will not prevent the component from being written to a data stream, but may prevent it from being parsed correctly by the consuming application. These problems can largely be avoided by reading the Javadocs of the component class, or by being familiar with the iCalendar standard.

Parameters:
hierarchy - the hierarchy of components that the component belongs to
Returns:
a list of warnings or an empty list if no problems were found
See Also:
ICalendar.validate()

validate

protected void validate(List<ICalComponent> components,
                        List<String> warnings)
Checks the component for data consistency problems or deviations from the spec. Meant to be overridden by child classes.

Parameters:
components - the hierarchy of components that the component belongs to
warnings - the list to add the warnings to

checkRequiredCardinality

protected void checkRequiredCardinality(List<String> warnings,
                                        Class<? extends ICalProperty>... classes)
Utility method for validating that there is exactly one instance of each of the given properties.

Parameters:
warnings - the list to add the warnings to
classes - the properties to check

checkOptionalCardinality

protected void checkOptionalCardinality(List<String> warnings,
                                        Class<? extends ICalProperty>... classes)
Utility method for validating that there is no more than one instance of each of the given properties.

Parameters:
warnings - the list to add the warnings to
classes - the properties to check


Copyright © 2013 Michael Angstadt. All Rights Reserved.