repicea.math.formula.ExpressionHandler Maven / Gradle / Ivy
Show all versions of repicea-mathstats Show documentation
/*
* This file is part of the repicea-statistics library.
*
* Copyright (C) 2009-2012 Mathieu Fortin for Rouge-Epicea
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed with the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* Please see the license at http://www.gnu.org/copyleft/lesser.html.
*/
package repicea.math.formula;
import java.security.InvalidParameterException;
import java.util.Map;
/**
* The ExpressionHandler class handles either doubles, MathFormula instances or
* variables.
* @author Mathieu Fortin - May 2013
*
* @param the class that is handled by this instance
*/
abstract class ExpressionHandler
implements Calculable {
protected final P expression;
protected ExpressionHandler(P expression) {
this.expression = expression;
}
static class DoubleHandler extends ExpressionHandler {
public DoubleHandler(Double d) {
super(d);
}
@Override
public double calculate() {
return expression;
}
}
static class MathFormulaHandler extends ExpressionHandler {
public MathFormulaHandler(MathFormula expression) {
super(expression);
}
@Override
public double calculate() {
return expression.calculate();
}
}
static class VariableHandler extends ExpressionHandler