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

io.legaldocml.business.builder.element.HierarchyBuilder Maven / Gradle / Ivy

The newest version!
package io.legaldocml.business.builder.element;

import io.legaldocml.akn.element.Content;
import io.legaldocml.akn.element.Heading;
import io.legaldocml.akn.element.Hierarchy;
import io.legaldocml.akn.element.HierarchyElement;
import io.legaldocml.akn.element.Intro;
import io.legaldocml.akn.element.Num;
import io.legaldocml.akn.element.Subheading;
import io.legaldocml.business.builder.AbstractBusinessPartBuilder;
import io.legaldocml.business.builder.BusinessBuilder;
import io.legaldocml.business.builder.BusinessBuilderException;
import io.legaldocml.business.builder.group.HierElementsBuilder;
import io.legaldocml.business.util.EidFactory;

import java.util.function.Consumer;

/**
 * @author Jacques Militello
 */
public final class HierarchyBuilder extends AbstractBusinessPartBuilder implements HierElementsBuilder {

    private final Hierarchy parent;
    private final T hierarchy;

    public HierarchyBuilder(BusinessBuilder businessBuilder, T hierarchy) {
        this(businessBuilder, null, hierarchy);
    }

    public HierarchyBuilder(BusinessBuilder businessBuilder, Hierarchy parent, T hierarchy) {
        super(businessBuilder, hierarchy);
        this.parent = parent;
        this.hierarchy = hierarchy;
    }

    public final InlineTypeBuilder num() {
        if (hierarchy.getNum() != null) {
            throw new BusinessBuilderException(" is not null : [" + hierarchy.getNum() + "]");
        }
        Num num = new Num();
        this.hierarchy.setNum(num);
        return new InlineTypeBuilder<>(getBusinessBuilder(), num);
    }

    public InlineReqTypeBuilder heading() {
       return heading(null);
    }

    public InlineReqTypeBuilder heading(Consumer consumer) {
        if (hierarchy.getHeading() != null) {
            throw new BusinessBuilderException(" is not null : [" + hierarchy.getHeading() + "]");
        }
        Heading heading = new Heading();
        this.hierarchy.setHeading(heading);

        if (consumer != null) {
            consumer.accept(heading);
        }

        return new InlineReqTypeBuilder<>(getBusinessBuilder(), heading);
    }

    public InlineReqTypeBuilder subHeading() {
        if (hierarchy.getSubheading() != null) {
            throw new BusinessBuilderException(" is not null : [" + hierarchy.getSubheading() + "]");
        }
        Subheading subheading = new Subheading();
        this.hierarchy.setSubheading(subheading);
        return new InlineReqTypeBuilder<>(getBusinessBuilder(), subheading);
    }

    public HierarchyBuilder eId(String number) {
        EidFactory.makeAndFill(this.parent, this.hierarchy, number);
        return this;
    }

    public  HierarchyBuilder next() {
        E el = this.getBusinessBuilder().getStrategy().next(this.hierarchy);
        this.hierarchy.addHierarchyElement(el);
        return new HierarchyBuilder<>(getBusinessBuilder(), this.hierarchy, el);
    }

    public  HierarchyBuilder newChild(String element) {
        HierarchyElement el = Hierarchy.ELEMS.get(element).get();
        this.hierarchy.addHierarchyElement(el);
        return new HierarchyBuilder(getBusinessBuilder(), (E) el);
    }

    public BlocksBuilder intro() {
       return intro(null);
    }

    public BlocksBuilder intro(Consumer consumer) {
        if (hierarchy.getIntro() != null) {
            throw new BusinessBuilderException(" is not null : [" + hierarchy.getIntro() + "]");
        }
        Intro intro = new Intro();
        this.hierarchy.setIntro(intro);
        if (consumer != null) {
            consumer.accept(intro);
        }
        return new BlocksBuilder<>(getBusinessBuilder(), this.hierarchy, intro);
    }

    public BlocksBuilder content() {
       return content(null);
    }

    public BlocksBuilder content(Consumer consumer) {
        if (hierarchy.getContent() != null) {
            throw new BusinessBuilderException(" is not null : [" + hierarchy.getContent() + "]");
        }
        Content content = new Content();
        this.hierarchy.setContent(content);

        if (consumer != null) {
            consumer.accept(content);
        }

        return new BlocksBuilder<>(getBusinessBuilder(), this.hierarchy, content);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy