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

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

package colesico.framework.dslvalidator.builder;

import colesico.framework.dslvalidator.commands.ValueChain;

import java.util.function.Function;

public final class WithOnToken implements CommandToken {

    private final ValidationProgramBuilder programBuilder;
    private final WithOnToken parent;

    private final String subject;
    private final Function valueExtractor;
    private final CommandToken[] commands;

    public WithOnToken(ValidationProgramBuilder programBuilder) {
        this.programBuilder = programBuilder;
        this.parent = null;
        this.subject = null;
        this.valueExtractor = null;
        this.commands = null;
    }

    public WithOnToken(ValidationProgramBuilder programBuilder,
                       WithOnToken parent,
                       String subject,
                       Function valueExtractor,
                       CommandToken... commands) {

        this.programBuilder = programBuilder;
        this.parent = parent;
        this.subject = subject;
        this.valueExtractor = valueExtractor;
        this.commands = commands;
    }

    public WithOnToken on(final String subject,
                             final Function valueExtractor,
                             final CommandToken... commands) {

        return new WithOnToken<>(programBuilder, this, subject, valueExtractor, commands);
    }

    @Override
    public void build() {
        if (parent != null) {
            parent.build();
            programBuilder.begin(new ValueChain(subject, valueExtractor));
            for (CommandToken cmd : commands) {
                cmd.build();
            }
            programBuilder.end();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy