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

io.legaldocml.akn.element.Preambleopt Maven / Gradle / Ivy

The newest version!
package io.legaldocml.akn.element;

import com.google.common.collect.ImmutableMap;
import io.legaldocml.akn.attribute.CoreOpt;
import io.legaldocml.akn.container.BlockElementsContainer;
import io.legaldocml.akn.container.PreambleContainersContainer;
import io.legaldocml.akn.group.ANblock;
import io.legaldocml.akn.group.BlockElements;
import io.legaldocml.akn.group.HTMLblock;
import io.legaldocml.akn.group.PreambleContainers;
import io.legaldocml.akn.util.AknList;
import io.legaldocml.akn.util.XmlReaderHelper;
import io.legaldocml.akn.visitor.AknVisitor;
import io.legaldocml.io.XmlReader;
import io.legaldocml.io.XmlWriter;

import java.io.IOException;
import java.util.function.Supplier;

import static io.legaldocml.akn.element.Groups.blockElements;
import static io.legaldocml.akn.element.Groups.convertSuper;
import static io.legaldocml.akn.element.Groups.preambleContainers;
import static java.util.Objects.requireNonNull;

/**
 * The complex type preambleopt defines the content model and attributes used by preambles. Here the eId attribute is
 * optional.
 *
 * 
 *   
 * 	   
 * 	     
 * 		 
 * 	   
 * 	   
 *   
 * 
 *
 * @author Jacques Militello
 */
public abstract class Preambleopt extends AbstractCore implements CoreOpt, PreambleContainersContainer, BlockElementsContainer {

    private static final ImmutableMap> ELEMS;

    static {
        ELEMS = ImmutableMap.>builder()
                .putAll(convertSuper(blockElements()))
                .putAll(convertSuper(preambleContainers()))
                .build();
    }

    private final AknList preambleoptElements = new AknList<>(new PreambleoptElement[4]);

    private void addPreambleoptElement(PreambleoptElement element) {
        this.preambleoptElements.add(requireNonNull(element));
    }

    private boolean removePreambleoptElement(PreambleoptElement element) {
        return this.preambleoptElements.remove(requireNonNull(element));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final PreambleoptElement remove(int index) {
        return this.preambleoptElements.remove(index);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void add(BlockElements elements) {
        addPreambleoptElement(elements);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final void add(ANblock block) {
        addPreambleoptElement(block);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public final boolean remove(ANblock block) {
        return removePreambleoptElement(block);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void add(HTMLblock block) {
        addPreambleoptElement(block);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void add(PreambleContainers preambleContainers) {
        addPreambleoptElement(preambleContainers);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void add(Container container) {
        addPreambleoptElement(container);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void read(XmlReader reader) {
        super.read(reader);
        XmlReaderHelper.read(reader, this.preambleoptElements, ELEMS);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void write(XmlWriter writer) throws IOException {
        CoreOpt.super.write(writer);
        this.preambleoptElements.write(writer);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void accept(AknVisitor visitor) {
       this.preambleoptElements.accept(visitor);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy