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

colesico.framework.dslvalidator.builder.ValidationProgramBuilder Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
package colesico.framework.dslvalidator.builder;

import colesico.framework.dslvalidator.Chain;
import colesico.framework.dslvalidator.Command;

import java.util.Deque;

public class ValidationProgramBuilder {

    private Deque stack;

    public Deque getStack() {
        return stack;
    }

    public void setStack(Deque stack) {
        this.stack = stack;
    }

    /**
     * Starts new nested chain.
     *
     * @param chain
     * @return
     */
    public final void begin(final Chain chain) {
        Chain parentChain = stack.peek();
        stack.push(chain);
        if (parentChain != null) {
            parentChain.getCommands().add(chain);
        }
    }

    /**
     * Ends current chain and returns to the parent one.
     */
    public final void end() {
        stack.pop();
        if (stack.isEmpty()) {
            throw new RuntimeException("Validation tree is empty");
        }
    }

    /**
     * Adds comman to current chain
     *
     * @return
     */
    public final void add(Command command) {
        stack.peek().getCommands().add(command);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy