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