com.codetaco.math.function.FuncFlatRate Maven / Gradle / Ivy
package com.codetaco.math.function;
import com.codetaco.math.Function;
import com.codetaco.math.ValueStack;
import com.codetaco.math.support.EquationSupport;
import com.codetaco.math.token.TokVariable;
import java.text.ParseException;
/**
*
* FuncFlatRate class.
*
*
* @author Chris DeGreef [email protected]
* @since 1.3.9
*/
public class FuncFlatRate extends Function {
/**
*
* Constructor for FuncFlatRate.
*
*/
public FuncFlatRate() {
super();
}
/**
*
* Constructor for FuncFlatRate.
*
*
* @param var a {@link com.codetaco.math.token.TokVariable} object.
*/
public FuncFlatRate(final TokVariable var) {
super(var);
}
/**
* {@inheritDoc}
*/
@Override
public void resolve(final ValueStack values) throws Exception {
if (values.size() < getParameterCount()) {
throw new Exception("missing operands for " + toString());
}
try {
final String tableName = values.popString();
final String[] keys = new String[5];
for (int a = 0; a < getParameterCount() - 1; a++) {
keys[a] = values.popString();
}
final EquationSupport model = getEqu().getSupport();
double rate = 0D;
rate = model.resolveRate(tableName, getEqu().getBaseDate(), keys[0], keys[1], keys[2], keys[3], keys[4]);
values.push(new Double(rate));
} catch (final ParseException e) {
e.fillInStackTrace();
throw new Exception(toString() + "; " + e.getMessage(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "function(flatrate)";
}
}