KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > calc > impl > AbstractListCalc


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractListCalc.java#3 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2006-2006 Julian Hyde
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.calc.impl;
11
12 import mondrian.olap.Evaluator;
13 import mondrian.olap.Exp;
14 import mondrian.olap.type.SetType;
15 import mondrian.calc.ListCalc;
16 import mondrian.calc.Calc;
17 import mondrian.calc.ExpCompiler;
18
19 import java.util.List JavaDoc;
20
21 /**
22  * Abstract implementation of the {@link mondrian.calc.ListCalc} interface.
23  *
24  * <p>The derived class must
25  * implement the {@link #evaluateList(mondrian.olap.Evaluator)} method,
26  * and the {@link #evaluate(mondrian.olap.Evaluator)} method will call it.
27  *
28  * @author jhyde
29  * @version $Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractListCalc.java#3 $
30  * @since Sep 27, 2005
31  */

32 public abstract class AbstractListCalc
33         extends AbstractCalc
34         implements ListCalc {
35     private final Calc[] calcs;
36     private final boolean mutable;
37
38     /**
39      * Creates an abstract implementation of a compiled expression which returns
40      * a mutable list.
41      *
42      * @param exp Expression which was compiled
43      * @param calcs List of child compiled expressions (for dependency
44      * analysis)
45      */

46     protected AbstractListCalc(Exp exp, Calc[] calcs) {
47         this(exp, calcs, true);
48     }
49
50     /**
51      * Creates an abstract implementation of a compiled expression which returns
52      * a list.
53      *
54      * @param exp Expression which was compiled
55      * @param calcs List of child compiled expressions (for dependency
56      * analysis)
57      * @param mutable Whether the list is mutable
58      */

59     protected AbstractListCalc(Exp exp, Calc[] calcs, boolean mutable) {
60         super(exp);
61         this.calcs = calcs;
62         this.mutable = mutable;
63         assert getType() instanceof SetType : "expecting a set: " + getType();
64     }
65
66     public Object JavaDoc evaluate(Evaluator evaluator) {
67         final List JavaDoc list = evaluateList(evaluator);
68         assert list != null : "null as empty list is deprecated";
69         return list;
70     }
71
72     public Calc[] getCalcs() {
73         return calcs;
74     }
75
76     public ExpCompiler.ResultStyle getResultStyle() {
77         return mutable ?
78             ExpCompiler.ResultStyle.MUTABLE_LIST :
79             ExpCompiler.ResultStyle.LIST;
80     }
81 }
82
83 // End AbstractListCalc.java
84
Popular Tags