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

io.github.vmzakharov.ecdataframe.dsl.function.IntrinsicFunctionDescriptorBuilder Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.github.vmzakharov.ecdataframe.dsl.function;

import io.github.vmzakharov.ecdataframe.dsl.EvalContext;
import io.github.vmzakharov.ecdataframe.dsl.value.Value;
import io.github.vmzakharov.ecdataframe.dsl.value.ValueType;
import org.eclipse.collections.api.list.ListIterable;
import org.eclipse.collections.impl.factory.Lists;

import java.util.function.Function;

public class IntrinsicFunctionDescriptorBuilder
extends IntrinsicFunctionDescriptor
{
    private Function action = ignore -> Value.VOID;
    private Function, ValueType> returnTypeFunction = ignore -> ValueType.VOID;

    public IntrinsicFunctionDescriptorBuilder(String newName)
    {
        super(newName);
    }

    public IntrinsicFunctionDescriptorBuilder action(Function newAction)
    {
        this.action = newAction;
        return this;
    }

    public IntrinsicFunctionDescriptorBuilder parameterNames(ListIterable parameterNames)
    {
        this.setParameterNames(parameterNames);
        return this;
    }

    public IntrinsicFunctionDescriptorBuilder parameterNames(String... parameterNames)
    {
        return this.parameterNames(Lists.immutable.of(parameterNames));
    }

    public IntrinsicFunctionDescriptorBuilder returnType(ValueType newReturnType)
    {
        this.returnType(ignore -> newReturnType);
        return this;
    }

    public IntrinsicFunctionDescriptorBuilder returnType(Function, ValueType> newReturnTypeFunction)
    {
        this.returnTypeFunction = newReturnTypeFunction;
        return this;
    }

    @Override
    public Value evaluate(EvalContext context)
    {
        return this.action.apply(context);
    }

    @Override
    public ValueType returnType(ListIterable parameterTypes)
    {
        return this.returnTypeFunction.apply(parameterTypes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy