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

org.jtwig.reflection.input.InputParameterResolverContext Maven / Gradle / Ivy

There is a newer version: 5.87.0.RELEASE
Show newest version
package org.jtwig.reflection.input;

import com.google.common.base.Function;
import org.jtwig.reflection.util.Lists2;

import java.util.List;

public class InputParameterResolverContext {
    private final List> inputParameters;

    private InputParameterResolverContext (InputParameterResolverContext prototype) {
        this.inputParameters = Lists2.transform(prototype.inputParameters, new Function, InputParameter>() {
            @Override
            public InputParameter apply(InputParameter input) {
                InputParameter clone = new InputParameter(input.value);
                clone.used = input.used;
                return clone;
            }
        });
    }

    public InputParameterResolverContext(List inputParameters) {
        this.inputParameters = Lists2.transform(inputParameters, new Function>() {
            @Override
            public InputParameter apply(T input) {
                return new InputParameter(input);
            }
        });
    }

    public InputParameterResolverContext markAsUsed(int position) {
        inputParameters.get(position).used = true;
        return this;
    }

    public boolean isUsed (int position) {
        return inputParameters.get(position).used;
    }

    public T value (int position) {
        return inputParameters.get(position).value;
    }

    public int size () {
        return inputParameters.size();
    }

    @Override
    public InputParameterResolverContext clone () {
        return new InputParameterResolverContext(this);
    }

    public void merge(InputParameterResolverContext clonedContext) {
        for (int i = 0; i < clonedContext.inputParameters.size(); i++) {
            inputParameters.get(i).used = clonedContext.inputParameters.get(i).used;
        }
    }

    public boolean fullyUsed() {
        for (InputParameter inputParameter : inputParameters) {
            if (!inputParameter.used) return false;
        }
        return true;
    }

    private static class InputParameter {
        private final T value;
        private boolean used;

        public InputParameter(T value) {
            this.value = value;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy