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.IntegerCalc;
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.IntegerCalc} interface.
021 *
022 * <p>The derived class must
023 * implement the {@link #evaluateInteger(mondrian.olap.Evaluator)} method,
024 * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it.
025 *
026 * @author jhyde
027 * @since Sep 26, 2005
028 */
029public abstract class AbstractIntegerCalc
030    extends AbstractCalc
031    implements IntegerCalc
032{
033    /**
034     * Creates an AbstractIntegerCalc.
035     *
036     * @param exp Source expression
037     * @param calcs Child compiled expressions
038     */
039    protected AbstractIntegerCalc(Exp exp, Calc[] calcs) {
040        super(exp, calcs);
041        assert getType() instanceof NumericType;
042    }
043
044    public Object evaluate(Evaluator evaluator) {
045        int i = evaluateInteger(evaluator);
046        if (i == FunUtil.IntegerNull) {
047            return null;
048        } else {
049            return i;
050        }
051    }
052}
053
054// End AbstractIntegerCalc.java