Class FunUtil

    • Field Detail

      • NullMember

        public static final mondrian.olap.fun.FunUtil.NullMember NullMember
      • DoubleNull

        public static final double DoubleNull
        Special value which indicates that a double computation has returned the MDX null value. See DoubleCalc.
        See Also:
        Constant Field Values
      • DoubleEmpty

        public static final double DoubleEmpty
        Special value which indicates that a double computation has returned the MDX EMPTY value. See DoubleCalc.
        See Also:
        Constant Field Values
      • IntegerNull

        public static final int IntegerNull
        Special value which indicates that an int computation has returned the MDX null value. See IntegerCalc.
        See Also:
        Constant Field Values
      • BooleanNull

        public static final boolean BooleanNull
        Null value in three-valued boolean logic. Actually, a placeholder until we actually implement 3VL.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FunUtil

        public FunUtil()
    • Method Detail

      • newEvalException

        public static RuntimeException newEvalException​(FunDef funDef,
                                                        String message)
        Creates an exception which indicates that an error has occurred while executing a given function.
        Parameters:
        funDef - Function being executed
        message - Explanatory message
        Returns:
        Exception that can be used as a cell result
      • newEvalException

        public static RuntimeException newEvalException​(Throwable throwable)
        Creates an exception which indicates that an error has occurred while executing a given function.
        Parameters:
        throwable - Exception
        Returns:
        Exception that can be used as a cell result
      • newEvalException

        public static RuntimeException newEvalException​(String message,
                                                        Throwable throwable)
        Creates an exception which indicates that an error has occurred while executing a given function.
        Parameters:
        message - Explanatory message
        throwable - Exception
        Returns:
        Exception that can be used as a cell result
      • checkIterListResultStyles

        public static void checkIterListResultStyles​(Calc calc)
      • checkListResultStyles

        public static void checkListResultStyles​(Calc calc)
      • isAncestorOf

        public static boolean isAncestorOf​(Member m0,
                                           Member m1,
                                           boolean strict)
        Returns whether m0 is an ancestor of m1.
        Parameters:
        strict - if true, a member is not an ancestor of itself
      • compareValues

        public static int compareValues​(double d1,
                                        double d2)
        Compares double-precision values according to MDX semantics.

        MDX requires a total order:

        -inf < NULL < ... < -1 < ... < 0 < ... < NaN < +inf
        but this is different than Java semantics, specifically with regard to Double.NaN.
      • compareValues

        public static int compareValues​(Object value0,
                                        Object value1)
        Compares two cell values.

        Nulls compare last, exceptions (including the object which indicates the the cell is not in the cache yet) next, then numbers and strings are compared by value.

        Parameters:
        value0 - First cell value
        value1 - Second cell value
        Returns:
        -1, 0, or 1, depending upon whether first cell value is less than, equal to, or greater than the second
      • decodeSyntacticType

        public static Syntax decodeSyntacticType​(String flags)
        Decodes the syntactic type of an operator.
        Parameters:
        flags - A encoded string which represents an operator signature, as used by the flags parameter used to construct a FunDefBase.
        Returns:
        A Syntax
      • decodeReturnCategory

        public static int decodeReturnCategory​(String flags)
        Decodes the signature of a function into a category code which describes the return type of the operator.

        For example, decodeReturnType("fnx") returns Category.Numeric, indicating this function has a numeric return value.

        Parameters:
        flags - The signature of an operator, as used by the flags parameter used to construct a FunDefBase.
        Returns:
        An array Category codes.
      • decodeParameterCategories

        public static int[] decodeParameterCategories​(String flags)
        Decodes a string of parameter types into an array of type codes.

        Each character is decoded using decodeCategory(String, int). For example, decodeParameterTypes("nx") returns {Category.Numeric, Category.Set}.

        Parameters:
        flags - The signature of an operator, as used by the flags parameter used to construct a FunDefBase.
        Returns:
        An array Category codes.
      • box

        public static Double box​(double d)
        Converts a double (primitive) value to a Double. DoubleNull becomes null.
      • box

        public static Integer box​(int n)
        Converts an int (primitive) value to an Integer. IntegerNull becomes null.
      • quartile

        protected static double quartile​(Evaluator evaluator,
                                         TupleList members,
                                         Calc exp,
                                         int range)
        Returns the member which lies upon a particular quartile according to a given expression.
        Parameters:
        evaluator - Evaluator
        members - List of members
        exp - Expression to rank members
        range - Quartile (1, 2 or 3)
      • compareHierarchically

        public static int compareHierarchically​(Member m1,
                                                Member m2,
                                                boolean post)
        Compares a pair of members according to their positions in a prefix-order (or postfix-order, if post is true) walk over a hierarchy.
        Parameters:
        m1 - First member
        m2 - Second member
        post - Whether to sortMembers in postfix order. If true, a parent will sortMembers immediately after its last child. If false, a parent will sortMembers immediately before its first child.
        Returns:
        -1 if m1 collates before m2, 0 if m1 equals m2, 1 if m1 collates after m2
      • compareSiblingMembers

        public static int compareSiblingMembers​(Member m1,
                                                Member m2)
        Compares two members which are known to have the same parent.

        First, compare by ordinal. This is only valid now we know they're siblings, because ordinals are only unique within a parent. If the dimension does not use ordinals, both ordinals will be -1.

        If the ordinals do not differ, compare using regular member comparison.

        Parameters:
        m1 - First member
        m2 - Second member
        Returns:
        -1 if m1 collates less than m2, 1 if m1 collates after m2, 0 if m1 == m2.
      • tupleContainsNullMember

        public static boolean tupleContainsNullMember​(Member[] tuple)
        Returns whether one of the members in a tuple is null.
      • tupleContainsNullMember

        public static boolean tupleContainsNullMember​(List<Member> tuple)
        Returns whether one of the members in a tuple is null.
      • makeNullTuple

        public static Member[] makeNullTuple​(TupleType tupleType)
      • resolveFunArgs

        public static FunDef resolveFunArgs​(Validator validator,
                                            FunDef funDef,
                                            Exp[] args,
                                            Exp[] newArgs,
                                            String name,
                                            Syntax syntax)
        Validates the arguments to a function and resolves the function.
        Parameters:
        validator - Validator used to validate function arguments and resolve the function
        funDef - Function definition, or null to deduce definition from name, syntax and argument types
        args - Arguments to the function
        newArgs - Output parameter for the resolved arguments
        name - Function name
        syntax - Syntax style used to invoke function
        Returns:
        resolved function definition
      • getNonEmptyMemberChildrenWithDetails

        public static Map<Member,​Access> getNonEmptyMemberChildrenWithDetails​(Evaluator evaluator,
                                                                                    Member member)
      • worthCaching

        public static boolean worthCaching​(Exp exp)
        Returns whether an expression is worth wrapping in "Cache( ... )".
        Parameters:
        exp - Expression
        Returns:
        Whether worth caching