net.intelie.pipes.FunctionContextList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pipes-api Show documentation
Show all versions of pipes-api Show documentation
Intelie Pipes' API classes and interfaces
package net.intelie.pipes;
import net.intelie.pipes.types.Metadata;
import net.intelie.pipes.util.Iterables;
import java.util.ArrayList;
import java.util.List;
public class FunctionContextList {
private final FunctionContextList parent;
private final FunctionContext context;
public FunctionContextList(Metadata metadata) {
this(null, new FunctionContext(metadata));
}
private FunctionContextList(FunctionContextList parent, FunctionContext context) {
this.parent = parent;
this.context = context;
}
public FunctionContext getContext() {
return context;
}
public FunctionContextList makeChild(Metadata metadata) {
return new FunctionContextList(parent, context.makeChild(metadata));
}
private boolean hasFunction(FunctionContext other, List path) {
if (context.sameFunctionAs(other) || parent != null && parent.hasFunction(other, path)) {
if (context.isFunction())
path.add(context.getDescription());
return true;
} else {
return false;
}
}
public FunctionContextList insideFunction(FunctionContext context) throws PipeException {
List path = new ArrayList<>();
if (hasFunction(context, path)) {
path.add(context.getDescription());
throw new PipeException("Recursive function expansion not allowed: %s", Iterables.join("->", path));
}
return new FunctionContextList(this, context);
}
}