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

com.github.basking2.sdsai.itrex.functions.AbstractFunction3 Maven / Gradle / Ivy

There is a newer version: 1.1.23
Show newest version
package com.github.basking2.sdsai.itrex.functions;

import com.github.basking2.sdsai.itrex.EvaluationContext;
import com.github.basking2.sdsai.itrex.SExprRuntimeException;

import java.util.Iterator;

import static com.github.basking2.sdsai.itrex.functions.Functions.getArgument;

/**
 * A function that takes 1 argument of a given type.
 */
public abstract class AbstractFunction3 implements FunctionInterface {
    @Override
    public R apply(final Iterator iterator, final EvaluationContext evaluationContext) {
        final T1 arg1 = getArgument(iterator, "1");
        final T2 arg2 = getArgument(iterator, "2");
        final T3 arg3 = getArgument(iterator, "3");

        try {
            return applyImpl(arg1, arg2, arg3, iterator, evaluationContext);
        }
        catch (final ClassCastException e) {
            throw new SExprRuntimeException("Casting argument.", e);
        }
    }

    /**
     * @param arg1 The first argument.
     * @param arg2 The second argument.
     * @param arg3 The third argument.
     * @param rest Any unused arguments.
     * @param context The evaluation context.
     * @return The result.
     */
    protected abstract R applyImpl(T1 arg1, T2 arg2, T3 arg3, Iterator rest, EvaluationContext context);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy