001    /*
002    // $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/AbstractDoubleCalc.java#1 $
003    // This software is subject to the terms of the Eclipse Public License v1.0
004    // Agreement, available at the following URL:
005    // http://www.eclipse.org/legal/epl-v10.html.
006    // Copyright (C) 2006-2009 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.DoubleCalc;
016    import mondrian.calc.Calc;
017    
018    /**
019     * Abstract implementation of the {@link mondrian.calc.DoubleCalc} interface.
020     *
021     * <p>The derived class must
022     * implement the {@link #evaluateDouble(mondrian.olap.Evaluator)} method,
023     * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it.
024     *
025     * @author jhyde
026     * @version $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/AbstractDoubleCalc.java#1 $
027     * @since Sep 27, 2005
028     */
029    public abstract class AbstractDoubleCalc
030        extends AbstractCalc
031        implements DoubleCalc
032    {
033        /**
034         * Creates an AbstractDoubleCalc.
035         *
036         * @param exp Source expression
037         * @param calcs Child compiled expressions
038         */
039        protected AbstractDoubleCalc(Exp exp, Calc[] calcs) {
040            super(exp, calcs);
041            assert getType() instanceof NumericType;
042        }
043    
044        public Object evaluate(Evaluator evaluator) {
045            final double d = evaluateDouble(evaluator);
046            if (d == FunUtil.DoubleNull) {
047                return null;
048            }
049            return new Double(d);
050        }
051    }
052    
053    // End AbstractDoubleCalc.java