uk.org.retep.math.model.MonadicFunctionOp Maven / Gradle / Ivy
The newest version!
package uk.org.retep.math.model;
import uk.org.retep.math.MathematicsException;
import uk.org.retep.math.visitor.ArithmeticVisitor;
/**
* A monadic Function. Here when accepting a visitor, if it's an instance of {@link FunctionArithmeticVisitor}
* then {@link #acceptImpl(uk.org.retep.math.visitor.FunctionArithmeticVisitor) } is called, otherwise
* we simply accept against the child. Doing this allows us to still optimise etc the parameter, but the function
* will never be optimised.
*
*/
public abstract class MonadicFunctionOp
extends MonadicOp
{
@Override
public final Object accept( ArithmeticVisitor visitor )
throws MathematicsException
{
if( getVisitor().isAssignableFrom( visitor.getClass() ) )
{
return acceptImpl( getVisitor().cast( visitor ) );
}
else if( getValue() != null )
{
return getValue().accept( visitor );
}
else
{
return null;
}
}
protected abstract Class getVisitor();
protected abstract Object acceptImpl( V visitor )
throws MathematicsException;
}