
com.github.basking2.sdsai.itrex.packages.JavaMathPackage 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.packages;
import com.github.basking2.sdsai.itrex.EvaluationContext;
import com.github.basking2.sdsai.itrex.Evaluator;
import com.github.basking2.sdsai.itrex.SExprRuntimeException;
import com.github.basking2.sdsai.itrex.functions.AbstractFunction1;
import com.github.basking2.sdsai.itrex.functions.AbstractFunction2;
import com.github.basking2.sdsai.itrex.functions.FunctionInterface;
import com.github.basking2.sdsai.itrex.util.TypeConversion;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
/**
*/
public class JavaMathPackage implements Package {
@Override
public void importTo(final Evaluator evaluator, String packageName) {
for (final Method m : Math.class.getMethods()) {
final String functionName;
if (packageName == null) {
functionName = "javamath." + m.getName();
}
else if (packageName.isEmpty()) {
functionName = m.getName();
}
else {
functionName = packageName + "." + m.getName();
}
if (m.getParameterCount() == 2) {
FunctionInterface extends Object> f = new MathFunction2(functionName);
evaluator.register(functionName, f);
}
else if (m.getParameterCount() == 1) {
FunctionInterface extends Object> f = new MathFunction1(functionName);
evaluator.register(functionName, f);
}
}
}
private static class MathFunction1 extends AbstractFunction1
© 2015 - 2025 Weber Informatics LLC | Privacy Policy