001 /*
002 // $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/AbstractTupleListCalc.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.type.SetType;
014 import mondrian.calc.*;
015
016 import java.util.List;
017
018 /**
019 * Abstract implementation of the {@link mondrian.calc.ListCalc} interface
020 * for expressions that return a list of tuples but never a list of members.
021 *
022 * <p>The derived class must
023 * implement the {@link #evaluateTupleList(mondrian.olap.Evaluator)} method,
024 * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it.
025 *
026 * @see AbstractListCalc
027 *
028 * @author jhyde
029 * @version $Id: //open/mondrian-release/3.2/src/main/mondrian/calc/impl/AbstractTupleListCalc.java#1 $
030 * @since Oct 24, 2008
031 */
032 public abstract class AbstractTupleListCalc
033 extends AbstractCalc
034 implements TupleListCalc
035 {
036 private final boolean mutable;
037
038 /**
039 * Creates an abstract implementation of a compiled expression which
040 * returns a mutable list of tuples.
041 *
042 * @param exp Expression which was compiled
043 * @param calcs List of child compiled expressions (for dependency
044 * analysis)
045 */
046 protected AbstractTupleListCalc(Exp exp, Calc[] calcs) {
047 this(exp, calcs, true);
048 }
049
050 /**
051 * Creates an abstract implementation of a compiled expression which
052 * returns a list.
053 *
054 * @param exp Expression which was compiled
055 * @param calcs List of child compiled expressions (for dependency
056 * analysis)
057 * @param mutable Whether the list is mutable
058 */
059 protected AbstractTupleListCalc(Exp exp, Calc[] calcs, boolean mutable) {
060 super(exp, calcs);
061 this.mutable = mutable;
062 assert type instanceof SetType : "expecting a set: " + getType();
063 assert getType().getArity() > 1;
064 }
065
066 public SetType getType() {
067 return (SetType) super.getType();
068 }
069
070 public final Object evaluate(Evaluator evaluator) {
071 final List<Member[]> tupleList = evaluateTupleList(evaluator);
072 assert tupleList != null : "null as empty tuple list is deprecated";
073 return tupleList;
074 }
075
076 public ResultStyle getResultStyle() {
077 return mutable
078 ? ResultStyle.MUTABLE_LIST
079 : ResultStyle.LIST;
080 }
081
082 public String toString() {
083 return "AbstractTupleListCalc object";
084 }
085
086 // override return type
087 public final List<Member[]> evaluateList(Evaluator evaluator) {
088 return evaluateTupleList(evaluator);
089 }
090 }
091
092 // End AbstractTupleListCalc.java