org.jtwig.reflection.input.InputParameterResolverContext Maven / Gradle / Ivy
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