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

net.jbock.validate.ContextBuilder Maven / Gradle / Ivy

There is a newer version: 5.18
Show newest version
package net.jbock.validate;

import net.jbock.annotated.AnnotatedMethods;
import net.jbock.annotated.AnnotatedOption;
import net.jbock.annotated.AnnotatedParameter;
import net.jbock.annotated.AnnotatedParameters;
import net.jbock.context.ContextModule;
import net.jbock.convert.Mapping;
import net.jbock.processor.SourceElement;

import java.util.List;

/**
 * A telescoping builder that creates the context module.
 */
public final class ContextBuilder {

    private final Step3 step3;
    private final List> namedOptions;

    private ContextBuilder(Step3 step3, List> namedOptions) {
        this.step3 = step3;
        this.namedOptions = namedOptions;
    }

    static Step1 builder(AnnotatedMethods abstractMethods) {
        return new Step1(abstractMethods);
    }

    static final class Step1 {
        private final AnnotatedMethods abstractMethods;

        private Step1(AnnotatedMethods abstractMethods) {
            this.abstractMethods = abstractMethods;
        }

        Step2 accept(List> positionalParameters) {
            return new Step2(this, positionalParameters);
        }

        List positionalParameters() {
            return abstractMethods.positionalParameters();
        }
    }

    static final class Step2 {
        private final Step1 step1;
        private final List> positionalParameters;

        private Step2(Step1 step1, List> positionalParameters) {
            this.step1 = step1;
            this.positionalParameters = positionalParameters;
        }

        List repeatablePositionalParameters() {
            return step1.abstractMethods.repeatablePositionalParameters();
        }

        Step3 accept(List> repeatablePositionalParameters) {
            return new Step3(this, repeatablePositionalParameters);
        }
    }

    static final class Step3 {
        private final Step2 step2;
        private final List> repeatablePositionalParameters;

        private Step3(Step2 step2, List> repeatablePositionalParameters) {
            this.step2 = step2;
            this.repeatablePositionalParameters = repeatablePositionalParameters;
        }

        List namedOptions() {
            return step2.step1.abstractMethods.namedOptions();
        }

        ContextBuilder accept(List> namedOptions) {
            return new ContextBuilder(this, namedOptions);
        }
    }

    /**
     * Creates the context module.
     *
     * @param sourceElement the command class
     * @return the context module
     */
    public ContextModule contextModule(SourceElement sourceElement) {
        return new ContextModule(sourceElement,
                step3.step2.positionalParameters,
                step3.repeatablePositionalParameters,
                namedOptions);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy