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

net.intelie.pipes.FunctionContextList Maven / Gradle / Ivy

There is a newer version: 0.25.5
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy