mondrian.olap.type
Class TypeUtil

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

public class TypeUtil
extends Object

Utility methods relating to types.

Since:
Feb 17, 2005
Author:
jhyde
 

Constructor Summary
TypeUtil()
           
 
Method Summary
static boolean canConvert(int from, int to, int[] conversionCount)
          Returns whether we can convert an argument of a given category to a given parameter category.
static boolean canEvaluate(Type type)
          Returns whether a value of a given type can be evaluated to a scalar value.
static Type computeCommonType(boolean allowConversions, Type... types)
          Returns a type sufficiently broad to hold any value of several types, but as narrow as possible.
static boolean couldBeMember(Type type)
           
static boolean isSet(Type type)
          Returns whether a type is a set type.
static boolean isUnionCompatible(Type type1, Type type2)
          Returns whether this type is union-compatible with another.
(package private) static
<T> T
neq(T t1, T t2)
           
static Type stripSetType(Type type)
          Given a set type, returns the element type.
static Type toMemberOrTupleType(Type type)
          Converts a type to a member or tuple type.
static MemberType toMemberType(Type type)
          Converts a type to a member type.
static int typeToCategory(Type type)
          Converts a Type value to a Category ordinal.
static Hierarchy typeToHierarchy(Type type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeUtil

public TypeUtil()
Method Detail

typeToHierarchy

public static Hierarchy typeToHierarchy(Type type)

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:

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 from,
                                 int to,
                                 int[] conversionCount)
Returns whether we can convert an argument of a given category to a given parameter category.

Parameters:
from - actual argument category
to - formal parameter category
conversionCount - in/out count of number of conversions performed; is incremented if the conversion is non-trivial (for example, converting a member to a level).
Returns:
whether can convert from 'from' to 'to'

neq

static <T> T neq(T t1,
                 T t2)

SourceForge.net_Logo