net.esper.util
Class JavaClassHelper

java.lang.Object
  extended by net.esper.util.JavaClassHelper

public class JavaClassHelper
extends Object

Helper for questions about Java classes such as

what is the boxed type for a primitive type

is this a numeric type.


Constructor Summary
JavaClassHelper()
           
 
Method Summary
static Number coerceNumber(Number numToCoerce, Class resultType)
          Coerce the given number to the given type.
static Class getArithmaticCoercionType(Class typeOne, Class typeTwo)
          Returns the coercion type for the 2 numeric types for use in arithmatic.
static String getBoxedClassName(String className)
          Returns for the class name given the class name of the boxed (wrapped) type if the class name is one of the Java primitive types.
static Class getBoxedType(Class clazz)
          Returns the boxed class for the given class, or the class itself if already boxed or not a primitive type.
static Class getCompareToCoercionType(Class typeOne, Class typeTwo)
          Returns for 2 classes to be compared via relational operator the Class type of common comparison.
static boolean isAssignmentCompatible(Class parameterType, Class parameterization)
          Returns true if 2 classes are assignment compatible.
static boolean isBoolean(Class clazz)
          Determines if the class passed in is a boolean boxed or unboxed type.
static boolean isFloatingPointClass(Class clazz)
          Returns true if the supplied type is a floating point number.
static boolean isFloatingPointNumber(Number number)
          Returns true if the Number instance is a floating point number.
static boolean isJavaBuiltinDataType(Class clazz)
          Returns true if the class passed in is a Java built-in data type (primitive or wrapper) including String.
static boolean isNumeric(Class clazz)
          Determines if the class passed in is one of the numeric classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaClassHelper

public JavaClassHelper()
Method Detail

getBoxedType

public static Class getBoxedType(Class clazz)
Returns the boxed class for the given class, or the class itself if already boxed or not a primitive type. For primitive unboxed types returns the boxed types, e.g. returns java.lang.Integer for passing int.class. For any other class, returns the class passed.

Parameters:
clazz - is the class to return the boxed class for
Returns:
boxed variant of the same class

isNumeric

public static boolean isNumeric(Class clazz)
Determines if the class passed in is one of the numeric classes.

Parameters:
clazz - to check
Returns:
true if numeric, false if not

isAssignmentCompatible

public static final boolean isAssignmentCompatible(Class parameterType,
                                                   Class parameterization)
Returns true if 2 classes are assignment compatible.

Parameters:
parameterType - type to assign from
parameterization - type to assign to
Returns:
true if assignment compatible, false if not

isBoolean

public static boolean isBoolean(Class clazz)
Determines if the class passed in is a boolean boxed or unboxed type.

Parameters:
clazz - to check
Returns:
true if boolean, false if not

getArithmaticCoercionType

public static Class getArithmaticCoercionType(Class typeOne,
                                              Class typeTwo)
Returns the coercion type for the 2 numeric types for use in arithmatic. Note: byte and short types always result in integer.

Parameters:
typeOne -
typeTwo -
Returns:
coerced type

coerceNumber

public static Number coerceNumber(Number numToCoerce,
                                  Class resultType)
Coerce the given number to the given type. Allows coerce to lower resultion number. Does't coerce to primitive types.

Parameters:
numToCoerce - is the number to coerce to the given type
resultType - is the result type to return
Returns:
the numToCoerce as a value in the given result type

isFloatingPointNumber

public static boolean isFloatingPointNumber(Number number)
Returns true if the Number instance is a floating point number.

Parameters:
number - to check
Returns:
true if number is Float or Double type

isFloatingPointClass

public static boolean isFloatingPointClass(Class clazz)
Returns true if the supplied type is a floating point number.

Parameters:
clazz - to check
Returns:
true if primitive or boxed float or double

getCompareToCoercionType

public static Class getCompareToCoercionType(Class typeOne,
                                             Class typeTwo)
Returns for 2 classes to be compared via relational operator the Class type of common comparison. The output is always Long.class, Double.class, String.class or Boolean.class depending on whether the passed types are numeric and floating-point. Accepts primitive as well as boxed types.

Parameters:
typeOne -
typeTwo -
Returns:
One of Long.class, Double.class or String.class
Throws:
IllegalArgumentException - if the types cannot be compared

getBoxedClassName

public static String getBoxedClassName(String className)
Returns for the class name given the class name of the boxed (wrapped) type if the class name is one of the Java primitive types.

Parameters:
className - is a class name, a Java primitive type or other class
Returns:
boxed class name if Java primitive type, or just same class name passed in if not a primitive type

isJavaBuiltinDataType

public static boolean isJavaBuiltinDataType(Class clazz)
Returns true if the class passed in is a Java built-in data type (primitive or wrapper) including String.

Parameters:
clazz - to check
Returns:
true if built-in data type, or false if not