com.github.basking2.sdsai.itrex.functions.AbstractFunction1 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdsai-itrex Show documentation
Show all versions of sdsai-itrex Show documentation
An S-Expression inspiried library focused on iterators.
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 AbstractFunction1 implements FunctionInterface {
@Override
public R apply(final Iterator> iterator, final EvaluationContext evaluationContext) {
final T arg1 = getArgument(iterator, "1");
try {
return applyImpl(arg1, iterator, evaluationContext);
}
catch (final ClassCastException e) {
throw new SExprRuntimeException("Casting argument.", e);
}
}
/**
* Overriders of this class should implement this.
*
* @param t The desired parameter.
* @param rest Any unused arguments.
* @param context The evaluation context.
* @return The produced object.
*/
protected abstract R applyImpl(T t, Iterator> rest, EvaluationContext context);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy