Class TypeUtil

java.lang.Object
mondrian.olap.type.TypeUtil

public class TypeUtil extends Object
Utility methods relating to types.
Since:
Feb 17, 2005
Author:
jhyde
  • Constructor Details

    • TypeUtil

      public TypeUtil()
  • Method Details

    • stripSetType

      public static Type stripSetType(Type type)
      Given a set type, returns the element type. Or its element type, if it is a set type. And so on.
      Parameters:
      type - Type
      Returns:
      underlying element type which is not a set type
    • toMemberOrTupleType

      public static Type toMemberOrTupleType(Type type)
      Converts a type to a member or tuple type. If it cannot, returns null.
      Parameters:
      type - Type
      Returns:
      member or tuple type
    • toMemberType

      public static MemberType toMemberType(Type type)
      Converts a type to a member type. If it is a set, strips the set. If it is a member type, returns the type unchanged. If it is a dimension, hierarchy or level type, converts it to a member type. If it is a tuple, number, string, or boolean, returns null.
      Parameters:
      type - Type
      Returns:
      type as a member type
    • isUnionCompatible

      public static boolean isUnionCompatible(Type type1, Type type2)
      Returns whether this type is union-compatible with another. In general, to be union-compatible, types must have the same dimensionality.
      Parameters:
      type1 - First type
      type2 - Second type
      Returns:
      whether types are union-compatible
    • canEvaluate

      public static boolean canEvaluate(Type type)
      Returns whether a value of a given type can be evaluated to a scalar value.

      The rules are as follows:

      • Clearly boolean, numeric and string expressions can be evaluated.
      • Member and tuple expressions can be interpreted as a scalar value. The expression is evaluated to establish the context where a measure can be evaluated.
      • Hierarchy and dimension expressions are implicitly converted into the current member, and evaluated as above.
      • Level expressions cannot be evaluated
      • Cube and Set (even sets with a single member) cannot be evaluated.
      Parameters:
      type - Type
      Returns:
      Whether an expression of this type can be evaluated to yield a scalar value.
    • isSet

      public static boolean isSet(Type type)
      Returns whether a type is a set type.
      Parameters:
      type - Type
      Returns:
      Whether a value of this type can be evaluated to yield a set.
    • couldBeMember

      public static boolean couldBeMember(Type type)
    • typeToCategory

      public static int typeToCategory(Type type)
      Converts a Type value to a Category ordinal.
      Parameters:
      type - Type
      Returns:
      category ordinal
    • computeCommonType

      public static Type computeCommonType(boolean allowConversions, Type... types)
      Returns a type sufficiently broad to hold any value of several types, but as narrow as possible. If there is no such type, returns null.

      The result is equivalent to calling Type.computeCommonType(Type, int[]) pairwise.

      Parameters:
      allowConversions - Whether to allow implicit conversions
      types - Array of types
      Returns:
      Most general type which encompases all types
    • canConvert

      public static boolean canConvert(int ordinal, Type fromType, int to, List<Resolver.Conversion> conversions)
      Returns whether we can convert an argument of a given category to a given parameter category.
      Parameters:
      ordinal - argument ordinal
      fromType - actual argument type
      to - formal parameter category
      conversions - list of implicit conversions required (out)
      Returns:
      whether can convert from 'from' to 'to'
    • getHierarchies

      public static List<Hierarchy> getHierarchies(Type type)
      Returns the hierarchies in a set, member, or tuple type.
      Parameters:
      type - Type
      Returns:
      List of hierarchies