Class ConstantCalc

All Implemented Interfaces:
BooleanCalc, Calc, DateTimeCalc, DimensionCalc, DoubleCalc, HierarchyCalc, IntegerCalc, LevelCalc, MemberCalc, StringCalc, TupleCalc, VoidCalc

public class ConstantCalc extends GenericCalc
Calculator which always returns the same value.
Since:
Sep 27, 2005
Author:
jhyde
  • Constructor Details

    • ConstantCalc

      public ConstantCalc(Type type, Object o)
  • Method Details

    • getName

      protected String getName()
      Description copied from class: AbstractCalc
      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.

      Overrides:
      getName in class AbstractCalc
    • 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
      Overrides:
      getResultStyle in class AbstractCalc
      See Also:
    • collectArguments

      public void collectArguments(Map<String,Object> arguments)
      Description copied from class: AbstractCalc
      Collects any other arguments to this calc.

      The default implementation returns name, class, type, resultStyle. A subclass must call super, but may add other arguments.

      Overrides:
      collectArguments in class AbstractCalc
      Parameters:
      arguments - Collection of name/value pairs, represented as a map
    • evaluate

      public Object evaluate(Evaluator evaluator)
      Description copied from interface: Calc
      Evaluates this expression.
      Parameters:
      evaluator - Provides dimensional context in which to evaluate this expression
      Returns:
      Result of expression evaluation
    • evaluateInteger

      public int evaluateInteger(Evaluator evaluator)
      Description copied from interface: IntegerCalc
      Evaluates this expression to yield an int value. If the result is null, returns the special FunUtil.IntegerNull value.
      Specified by:
      evaluateInteger in interface IntegerCalc
      Overrides:
      evaluateInteger in class GenericCalc
      Parameters:
      evaluator - Evaluation context
      Returns:
      evaluation result
    • evaluateDouble

      public double evaluateDouble(Evaluator evaluator)
      Description copied from interface: DoubleCalc
      Evaluates this expression to yield a double value. If the result is null, returns the special FunUtil.DoubleNull value.
      Specified by:
      evaluateDouble in interface DoubleCalc
      Overrides:
      evaluateDouble in class GenericCalc
      Parameters:
      evaluator - Evaluation context
      Returns:
      evaluation result
    • 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:

      • The expression
        [Measures].[Unit Sales]
        depends on all dimensions except [Measures].
      • The boolean expression
        ([Measures].[Unit Sales], [Time].[1997]) > 1000
        depends on all hierarchies except [Measures] and [Time].
      • The list expression
        Filter([Store].[USA].Children, [Measures].[Unit Sales] < 50)
        depends upon all hierarchies except [Store] and [Measures]. How so? Normally the scalar expression would depend upon all hierarchies except [Measures], but the Filter function sets the [Store] context before evaluating the scalar expression, so it is not inherited from the surrounding context.

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

      public Calc[] getCalcs()
      Description copied from class: AbstractCalc
      Returns this expression's child expressions.
      Overrides:
      getCalcs in class AbstractCalc
    • constantInteger

      public static ConstantCalc constantInteger(int i)
      Creates an expression which evaluates to a given integer.
      Parameters:
      i - Integer value
      Returns:
      Constant integer expression
    • constantDouble

      public static DoubleCalc constantDouble(double v)
      Creates an expression which evaluates to a given double.
      Parameters:
      v - Double value
      Returns:
      Constant double expression
    • constantString

      public static StringCalc constantString(String s)
      Creates an expression which evaluates to a given string.
      Parameters:
      s - String value
      Returns:
      Constant string expression
    • constantBoolean

      public static BooleanCalc constantBoolean(boolean b)
      Creates an expression which evaluates to a given boolean.
      Parameters:
      b - Boolean value
      Returns:
      Constant boolean expression
    • constantNull

      public static ConstantCalc constantNull(Type type)
      Creates an expression which evaluates to null.
      Parameters:
      type - Type
      Returns:
      Constant null expression
    • constantMember

      public static Calc constantMember(Member member)
      Creates an expression which evaluates to a given member.
      Parameters:
      member - Member
      Returns:
      Constant member expression
    • constantLevel

      public static Calc constantLevel(Level level)
      Creates an expression which evaluates to a given level.
      Parameters:
      level - Level
      Returns:
      Constant level expression
    • constantHierarchy

      public static Calc constantHierarchy(Hierarchy hierarchy)
      Creates an expression which evaluates to a given hierarchy.
      Parameters:
      hierarchy - Hierarchy
      Returns:
      Constant hierarchy expression
    • constantDimension

      public static Calc constantDimension(Dimension dimension)
      Creates an expression which evaluates to a given dimension.
      Parameters:
      dimension - Dimension
      Returns:
      Constant dimension expression