com.triactive.jdo.util
Class Types

java.lang.Object
  extended bycom.triactive.jdo.util.Types

public final class Types
extends java.lang.Object

Contains static methods related to Java and JDO type conversions.

Author:
Mike Martin

Method Summary
static boolean areAssignableFrom(java.lang.Class[] boxedParamTypes, java.lang.Class[] boxedArgTypes)
          Tests if a set of parameters types are all assignable from a given set of argument types.
static java.lang.Class binaryNumericPromotion(java.lang.Class[] types)
          Performs binary numeric promotion on a set of input types.
static java.lang.Class binaryNumericPromotion(java.lang.Class operand1Type, java.lang.Class operand2Type)
          Performs binary numeric promotion on a pair of types.
static java.lang.Class box(java.lang.Class c)
          Performs a boxing conversion, if applicable.
static java.lang.Class[] box(java.lang.Class[] c)
          Performs a boxing conversion on multiple classes.
static java.lang.Class unaryNumericPromotion(java.lang.Class operandType)
          Performs unary numeric promotion on the given type.
static java.lang.Class unbox(java.lang.Class c)
          Performs an unboxing conversion, if applicable.
static java.lang.Class[] unbox(java.lang.Class[] c)
          Performs an unboxing conversion on multiple classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

box

public static java.lang.Class box(java.lang.Class c)
Performs a boxing conversion, if applicable. If the type is a Java primitive type it's equivalent wrapper class is returned. Otherwise the type itself is returned.

Parameters:
c - the type to be boxed, or null
Returns:
The boxed equivalent, or the type itself if not applicable. null is returned if the argument was null.

unbox

public static java.lang.Class unbox(java.lang.Class c)
Performs an unboxing conversion, if applicable. If the type is a Java primitive wrapper class it's equivalent primitive type is returned. Otherwise the type itself is returned.

Parameters:
c - the type to be unboxed, or null
Returns:
The unboxed equivalent, or the type itself if not applicable. null is returned if the argument was null.

box

public static java.lang.Class[] box(java.lang.Class[] c)
Performs a boxing conversion on multiple classes. The returned array contains the results of calling box(Class) on every class in the argument array.

Parameters:
c - the types to be boxed
Returns:
the boxed equivalent of all the types in c

unbox

public static java.lang.Class[] unbox(java.lang.Class[] c)
Performs an unboxing conversion on multiple classes. The returned array contains the results of calling unbox(Class) on every class in the argument array.

Parameters:
c - the types to be unboxed
Returns:
the unboxed equivalent of all the types in c

areAssignableFrom

public static boolean areAssignableFrom(java.lang.Class[] boxedParamTypes,
                                        java.lang.Class[] boxedArgTypes)
Tests if a set of parameters types are all assignable from a given set of argument types. Returns true iff the number of types match and each parameter type is assignable from its corresponding argument type. "Assignable" is defined by Class.isAssignableFrom().

All classes in the parameter type array and the argument type array must already be boxed.

Parameters:
boxedParamTypes - the parameter types
boxedArgTypes - the argument types
Returns:
true if the all the parameter types are assignable from the argument types.

unaryNumericPromotion

public static java.lang.Class unaryNumericPromotion(java.lang.Class operandType)
Performs unary numeric promotion on the given type. Unary numeric promotion is as defined in §5.6.1 of the Java Language Specification.

Parameters:
operandType - the type to be promoted, or null
Returns:
The promoted type, or null if the argument was null.

binaryNumericPromotion

public static java.lang.Class binaryNumericPromotion(java.lang.Class[] types)
Performs binary numeric promotion on a set of input types. Binary numeric promotion is as defined in §14.6.2 of the JDO 2.0 spec.

Parameters:
types - The input types to be promoted. If more than two types are present then the first two are promoted, then the promoted type and the third type are promoted, and so on for all the types.
Returns:
The promoted type. Returns null if the input array is empty. Returns the first type if the input array has only one type.
Throws:
java.lang.IllegalArgumentException - if any argument type is not a subclass of java.lang.Number

binaryNumericPromotion

public static java.lang.Class binaryNumericPromotion(java.lang.Class operand1Type,
                                                     java.lang.Class operand2Type)
Performs binary numeric promotion on a pair of types. Binary numeric promotion is as defined in §14.6.2 of the JDO 2.0 spec.

Parameters:
operand1Type - the first type in the pair.
operand2Type - the other type in the pair.
Returns:
The promoted type.
Throws:
java.lang.IllegalArgumentException - if either argument type is not a subclass of java.lang.Number


Copyright 2001-2007 The TJDO Project All Rights Reserved.