001 /* 002 // $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractIterCalc.java#5 $ 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-2008 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.calc.Calc; 013 import mondrian.calc.IterCalc; 014 import mondrian.calc.ResultStyle; 015 import mondrian.olap.Evaluator; 016 import mondrian.olap.Exp; 017 import mondrian.olap.Member; 018 import mondrian.olap.type.SetType; 019 020 /** 021 * Abstract implementation of the {@link mondrian.calc.IterCalc} interface. 022 * 023 * <p>The derived class must 024 * implement the {@link #evaluateIterable(mondrian.olap.Evaluator)} method, 025 * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it. 026 * 027 * @author <a>Richard M. Emberson</a> 028 * @version $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractIterCalc.java#5 $ 029 * @since Jan 14, 2007 030 */ 031 032 public abstract class AbstractIterCalc 033 extends AbstractCalc 034 implements IterCalc { 035 private final Calc[] calcs; 036 037 /** 038 * Creates an abstract implementation of a compiled expression which returns 039 * an Iterable. 040 * 041 * @param exp Expression which was compiled 042 * @param calcs List of child compiled expressions (for dependency 043 * analysis) 044 */ 045 protected AbstractIterCalc(Exp exp, Calc[] calcs) { 046 super(exp); 047 this.calcs = calcs; 048 assert getType() instanceof SetType : "expecting a set: " + getType(); 049 } 050 051 public Object evaluate(Evaluator evaluator) { 052 final Iterable iter = evaluateIterable(evaluator); 053 return iter; 054 } 055 056 public Calc[] getCalcs() { 057 return calcs; 058 } 059 060 public ResultStyle getResultStyle() { 061 return ResultStyle.ITERABLE; 062 } 063 064 @SuppressWarnings({"unchecked"}) 065 public Iterable<Member> evaluateMemberIterable(Evaluator evaluator) { 066 return (Iterable<Member>) evaluateIterable(evaluator); 067 } 068 069 @SuppressWarnings({"unchecked"}) 070 public Iterable<Member[]> evaluateTupleIterable(Evaluator evaluator) { 071 return (Iterable<Member[]>) evaluateIterable(evaluator); 072 } 073 074 } 075 076 // End AbstractIterCalc.java