FileDocCategorySizeDatePackage
PowerEval.javaAPI DocApache Poi 3.0.13475Sun Mar 11 12:59:28 GMT 2007org.apache.poi.hssf.record.formula.eval

PowerEval

public class PowerEval extends NumericOperationEval
author
Amol S. Deshmukh < amolweb at ya hoo dot com >

Fields Summary
private PowerPtg
delegate
private static final ValueEvalToNumericXlator
NUM_XLATOR
Constructors Summary
public PowerEval(Ptg ptg)


       
        delegate = (PowerPtg) ptg;
    
Methods Summary
public Evalevaluate(Eval[] operands, int srcRow, short srcCol)

        Eval retval = null;
        double d0 = 0;
        double d1 = 0;
        
        switch (operands.length) {
        default: // will rarely happen. currently the parser itself fails.
            retval = ErrorEval.UNKNOWN_ERROR;
            break;
        case 2:
            ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
            if (ve instanceof NumericValueEval) {
                d0 = ((NumericValueEval) ve).getNumberValue();
            }
            else if (ve instanceof BlankEval) {
                // do nothing
            }
            else {
                retval = ErrorEval.VALUE_INVALID;
            }
            
            if (retval == null) { // no error yet
                ve = singleOperandEvaluate(operands[1], srcRow, srcCol);
                if (ve instanceof NumericValueEval) {
                    d1 = ((NumericValueEval) ve).getNumberValue();
                }
                else if (ve instanceof BlankEval) {
                    // do nothing
                }
                else {
                    retval = ErrorEval.VALUE_INVALID;
                }
            }
        } // end switch

        if (retval == null) {
            double p = Math.pow(d0, d1);
            retval = (Double.isNaN(p)) 
                    ? (ValueEval) ErrorEval.VALUE_INVALID 
                    : new NumberEval(p);
        }
        return retval;
    
public intgetNumberOfOperands()

        return delegate.getNumberOfOperands();
    
public intgetType()

        return delegate.getType();
    
protected ValueEvalToNumericXlatorgetXlator()

        return NUM_XLATOR;