For simple double
values this is a valid solution:
public class PolynomialFunction implements Function {
private final double[] coefficients;
public PolynomialFunction(double... coefficients) {
this.coefficients = coefficients;
}
@Override
public double value(double x) {
int len = coefficients.length;
double xPowI = 1;
double val = 0;
for (int i = 0; i < len; i++) {
val += coefficients[len - 1 - i] * xPowI;
xPowI *= x;
}
return val;
}
}
You should be able to refactor it to your needs.
If it turns out I haven't entirely understood your question, please comment!