All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.fortuna.ical4j.model.ComponentContainer Maven / Gradle / Ivy

There is a newer version: 4.0.8
Show newest version
package net.fortuna.ical4j.model;

import java.util.function.BiFunction;

public interface ComponentContainer extends ComponentListAccessor {

    void setComponentList(ComponentList components);

    /**
     * Add a subcomponent to this component.
     * @param component the subcomponent to add
     * @return a reference to this component to support method chaining
     */
    default > T add(C component) {
        setComponentList((ComponentList) getComponentList().add(component));
        //noinspection unchecked
        return (T) this;
    }

    /**
     * Remove a subcomponent from this component.
     * @param component the subcomponent to remove
     * @return a reference to this component to support method chaining
     */
    default > T remove(C component) {
        setComponentList((ComponentList)  getComponentList().remove(component));
        //noinspection unchecked
        return (T) this;
    }

    /**
     * Add a subcomponent to this component whilst removing all other subcomponents with the same component name.
     * @param component the subcomponent to add
     * @return a reference to the component to support method chaining
     */
    default > T replace(C component) {
        setComponentList((ComponentList)  getComponentList().replace(component));
        //noinspection unchecked
        return (T) this;
    }

    /**
     * A functional method used to apply a component to a container in an undefined way.
     *
     * For example, a null check can be introduced as follows:
     *
     *  container.with((container, component) -> if (component != null) container.add(component); return container;)
     * @param f
     * @param c
     * @return
     * @param 
     */
    default > T with(BiFunction f, C c) {
        return f.apply((T) this, c);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy