mondrian.calc.impl
Class AbstractCalc

java.lang.Object
  extended by mondrian.calc.impl.AbstractCalc
All Implemented Interfaces:
Calc
Direct Known Subclasses:
AbstractBooleanCalc, AbstractDateTimeCalc, AbstractDimensionCalc, AbstractDoubleCalc, AbstractHierarchyCalc, AbstractIntegerCalc, AbstractIterCalc, AbstractLevelCalc, AbstractListCalc, AbstractMemberCalc, AbstractMemberIterCalc, AbstractMemberListCalc, AbstractStringCalc, AbstractTupleCalc, AbstractTupleIterCalc, AbstractTupleListCalc, GenericCalc, GenericIterCalc, MemberOrderKeyFunDef.CalcImpl

public abstract class AbstractCalc
extends java.lang.Object
implements Calc

Abstract implementation of the Calc interface.

Since:
Sep 27, 2005
Version:
$Id: //open/mondrian/src/main/mondrian/calc/impl/AbstractCalc.java#16 $
Author:
jhyde

Field Summary
protected  Exp exp
           
protected  Type type
           
 
Constructor Summary
protected AbstractCalc(Exp exp, Calc[] calcs)
          Creates an AbstractCalc.
 
Method Summary
 void accept(CalcWriter calcWriter)
          Prints this expression, by accepting a visiting CalcWriter.
static boolean anyDepends(Calc[] calcs, Hierarchy hierarchy)
          Returns true if one of the calcs depends on the given dimension.
static boolean anyDependsButFirst(Calc[] calcs, Hierarchy hierarchy)
          Returns true if calc[0] depends on dimension, else false if calc[0] returns dimension, else true if any of the other calcs depend on dimension.
static boolean butDepends(Calc[] calcs, Hierarchy hierarchy)
          Returns true if any of the calcs depend on dimension, else false if any of the calcs return dimension, else true.
 boolean dependsOn(Hierarchy hierarchy)
          Returns whether this expression depends upon a given hierarchy.
 java.util.List<java.lang.Object> getArguments()
          Returns any other arguments to this calc.
 Calc[] getCalcs()
          Returns this expression's child expressions.
protected  java.lang.String getName()
          Returns the name of this expression type, used when serializing an expression to a string.
 ResultStyle getResultStyle()
          Returns style in which the result of evaluating this expression is returned.
 Type getType()
          Returns the type of this expression.
static Evaluator simplifyEvaluator(Calc calc, Evaluator evaluator)
          Returns a simplified evalator whose context is the same for every dimension which an expression depends on, and the default member for every dimension which it does not depend on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface mondrian.calc.Calc
evaluate
 

Field Detail

type

protected final Type type

exp

protected final Exp exp
Constructor Detail

AbstractCalc

protected AbstractCalc(Exp exp,
                       Calc[] calcs)
Creates an AbstractCalc.

Parameters:
exp - Source expression
calcs - Child compiled expressions
Method Detail

getType

public Type getType()
Description copied from interface: Calc
Returns the type of this expression.

Specified by:
getType in interface Calc

accept

public void accept(CalcWriter calcWriter)
Description copied from interface: Calc
Prints this expression, by accepting a visiting CalcWriter.

Specified by:
accept in interface Calc
Parameters:
calcWriter - Writer

getName

protected java.lang.String getName()
Returns the name of this expression type, used when serializing an expression to a string.

The default implementation tries to extract a name from a function call, if any, then prints the last part of the class name.


getCalcs

public Calc[] getCalcs()
Returns this expression's child expressions.


dependsOn

public boolean dependsOn(Hierarchy hierarchy)
Description copied from interface: Calc
Returns whether this expression depends upon a given hierarchy.

If it does not depend on the hierarchy, then re-evaluating the expression with a different member of this context must produce the same answer.

Some examples:

Specified by:
dependsOn in interface Calc
Parameters:
hierarchy - Hierarchy
Returns:
Whether this expression's result depends upon the current member of the hierarchy

anyDepends

public static boolean anyDepends(Calc[] calcs,
                                 Hierarchy hierarchy)
Returns true if one of the calcs depends on the given dimension.


anyDependsButFirst

public static boolean anyDependsButFirst(Calc[] calcs,
                                         Hierarchy hierarchy)
Returns true if calc[0] depends on dimension, else false if calc[0] returns dimension, else true if any of the other calcs depend on dimension.

Typical application: Aggregate({Set}, {Value Expression}) depends upon everything {Value Expression} depends upon, except the dimensions of {Set}.


butDepends

public static boolean butDepends(Calc[] calcs,
                                 Hierarchy hierarchy)
Returns true if any of the calcs depend on dimension, else false if any of the calcs return dimension, else true.


getArguments

public java.util.List<java.lang.Object> getArguments()
Returns any other arguments to this calc. The default implementation returns the empty list.


simplifyEvaluator

public static Evaluator simplifyEvaluator(Calc calc,
                                          Evaluator evaluator)
Returns a simplified evalator whose context is the same for every dimension which an expression depends on, and the default member for every dimension which it does not depend on.

The default member is often the 'all' member, so this evaluator is usually the most efficient context in which to evaluate the expression.

Parameters:
calc -
evaluator -

getResultStyle

public ResultStyle getResultStyle()
Description copied from interface: Calc
Returns style in which the result of evaluating this expression is returned.

One application of this method is for the compiler to figure out whether the compiled expression is returning a mutable list. If a mutable list is required, the compiler can create a mutable copy.

Specified by:
getResultStyle in interface Calc
See Also:
ExpCompiler.compileList(mondrian.olap.Exp, boolean)

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads