001    /*
002    // $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractDoubleCalc.java#2 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2006-2006 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.calc.impl;
011    
012    import mondrian.olap.*;
013    import mondrian.olap.fun.FunUtil;
014    import mondrian.olap.type.NumericType;
015    import mondrian.calc.impl.AbstractCalc;
016    import mondrian.calc.DoubleCalc;
017    import mondrian.calc.Calc;
018    
019    /**
020     * Abstract implementation of the {@link mondrian.calc.DoubleCalc} interface.
021     *
022     * <p>The derived class must
023     * implement the {@link #evaluateDouble(mondrian.olap.Evaluator)} method,
024     * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it.
025     *
026     * @author jhyde
027     * @version $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractDoubleCalc.java#2 $
028     * @since Sep 27, 2005
029     */
030    public abstract class AbstractDoubleCalc
031            extends AbstractCalc
032            implements DoubleCalc {
033        private final Calc[] calcs;
034    
035        protected AbstractDoubleCalc(Exp exp, Calc[] calcs) {
036            super(exp);
037            this.calcs = calcs;
038            assert getType() instanceof NumericType;
039        }
040    
041        public Object evaluate(Evaluator evaluator) {
042            final double d = evaluateDouble(evaluator);
043            if (d == FunUtil.DoubleNull) {
044                return null;
045            }
046            return new Double(d);
047        }
048    
049        public Calc[] getCalcs() {
050            return calcs;
051        }
052    }
053    
054    // End AbstractDoubleCalc.java