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

net.fortuna.ical4j.vcard.EntityContainer Maven / Gradle / Ivy

The newest version!
package net.fortuna.ical4j.vcard;

import java.util.List;
import java.util.function.BiFunction;

/**
 * Provides mutator methods for {@link Entity} collections.
 */
public interface EntityContainer {

    EntityList getEntityList();

    void setEntityList(EntityList cards);

    /**
     * Add a subcomponent to this component.
     *
     * @param entity the subcomponent to add
     * @return a reference to this component to support method chaining
     */
    default EntityContainer add(Entity entity) {
        setEntityList(getEntityList().add(entity));
        return this;
    }

    /**
     * Remove a subcomponent from this component.
     *
     * @param entity the subcomponent to remove
     * @return a reference to this component to support method chaining
     */
    default EntityContainer remove(Entity entity) {
        setEntityList(getEntityList().remove(entity));
        return this;
    }

    default List getEntities() {
        return getEntityList().getAll();
    }

    /**
     * A functional method used to apply an entity to a container in an undefined way.
     * 

* For example, a null check can be introduced as follows: *

* container.with((container, entity) -> if (entity != null) container.add(entity); return container;) * * @param f * @param entity * @return */ default T with(BiFunction, T> f, List entity) { //noinspection unchecked return f.apply((T) this, entity); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy