net.esper.util
Class JavaClassHelper

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

public class JavaClassHelper
extends java.lang.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 java.lang.Number coerceNumber(java.lang.Number numToCoerce, java.lang.Class resultType)
          Coerce the given number to the given type.
static java.lang.Class getArithmaticCoercionType(java.lang.Class typeOne, java.lang.Class typeTwo)
          Returns the coercion type for the 2 numeric types for use in arithmatic.
static java.lang.Class getBoxedType(java.lang.Class clazz)
          Returns the boxed class for the given class, or the class itself if already boxed or not a primitive type.
static java.lang.Class getCompareToCoercionType(java.lang.Class typeOne, java.lang.Class typeTwo)
          Returns for 2 classes to be compared via relational operator the Class type of common comparison.
static boolean isAssignmentCompatible(java.lang.Class parameterType, java.lang.Class parameterization)
          Returns true if 2 classes are assignment compatible.
static boolean isBoolean(java.lang.Class clazz)
          Determines if the class passed in is a boolean boxed or unboxed type.
static boolean isFloatingPointClass(java.lang.Class clazz)
          Returns true if the supplied type is a floating point number.
static boolean isFloatingPointNumber(java.lang.Number number)
          Returns true if the Number instance is a floating point number.
static boolean isNumeric(java.lang.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 java.lang.Class getBoxedType(java.lang.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(java.lang.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(java.lang.Class parameterType,
                                                   java.lang.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(java.lang.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 java.lang.Class getArithmaticCoercionType(java.lang.Class typeOne,
                                                        java.lang.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 java.lang.Number coerceNumber(java.lang.Number numToCoerce,
                                            java.lang.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(java.lang.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(java.lang.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 java.lang.Class getCompareToCoercionType(java.lang.Class typeOne,
                                                       java.lang.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:
java.lang.IllegalArgumentException - if the types cannot be compared