001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2006-2009 Pentaho 008// All Rights Reserved. 009*/ 010package mondrian.calc.impl; 011 012import mondrian.calc.Calc; 013import mondrian.calc.DoubleCalc; 014import mondrian.olap.Evaluator; 015import mondrian.olap.Exp; 016import mondrian.olap.fun.FunUtil; 017import mondrian.olap.type.NumericType; 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 * @since Sep 27, 2005 028 */ 029public 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