|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.esper.util.JavaClassHelper
public class JavaClassHelper
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 boolean |
canCoerce(Class numberClassToBeCoerced,
Class numberClassToCoerceTo)
Determines if a number can be coerced upwards to another number class without loss. |
static Number |
coerceBoxed(Number numToCoerce,
Class resultBoxedType)
Coerce the given number to the given type, assuming the type is a Boxed 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 |
getClassForName(String className)
Returns the class given a fully-qualified class name. |
static Class |
getCommonCoercionType(Class[] types)
Determines a common denominator type to which one or more types can be casted or coerced. |
static Class |
getCompareToCoercionType(Class typeOne,
Class typeTwo)
Returns for 2 classes to be compared via relational operator the Class type of common comparison. |
static Class |
getPrimitiveType(Class clazz)
Returns the un-boxed class for the given class, or the class itself if already un-boxed or not a primitive type. |
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 |
---|
public JavaClassHelper()
Method Detail |
---|
public static Class getBoxedType(Class clazz)
clazz
- is the class to return the boxed class for
public static Class getPrimitiveType(Class clazz)
clazz
- is the class to return the unboxed (or primitive) class for
public static boolean isNumeric(Class clazz)
clazz
- to check
public static final boolean isAssignmentCompatible(Class parameterType, Class parameterization)
parameterType
- type to assign fromparameterization
- type to assign to
public static boolean isBoolean(Class clazz)
clazz
- to check
public static Class getArithmaticCoercionType(Class typeOne, Class typeTwo) throws CoercionException
typeOne
- is the first typetypeTwo
- is the second type
CoercionException
- if types don't allow coercionpublic static Number coerceBoxed(Number numToCoerce, Class resultBoxedType)
numToCoerce
- is the number to coerce to the given typeresultBoxedType
- is the boxed result type to return
public static boolean isFloatingPointNumber(Number number)
number
- to check
public static boolean isFloatingPointClass(Class clazz)
clazz
- to check
public static Class getCompareToCoercionType(Class typeOne, Class typeTwo)
typeOne
- is the first typetypeTwo
- is the second type
IllegalArgumentException
- if the types cannot be comparedpublic static boolean canCoerce(Class numberClassToBeCoerced, Class numberClassToCoerceTo)
Clients must pass in two classes that are numeric types.
Any number class can be coerced to double, while only double cannot be coerced to float. Any non-floating point number can be coerced to long. Integer can be coerced to Byte and Short even though loss is possible, for convenience.
numberClassToBeCoerced
- the number class to be coercednumberClassToCoerceTo
- the number class to coerce to
public static String getBoxedClassName(String className)
className
- is a class name, a Java primitive type or other class
public static boolean isJavaBuiltinDataType(Class clazz)
clazz
- to check
public static Class getCommonCoercionType(Class[] types) throws CoercionException
Null values are allowed as part of the input and indicate a 'null' constant value in an expression tree. Such as value doesn't have any type and can be ignored in determining a result type.
For numeric types, determines a coercion type that all types can be converted to via the method getArithmaticCoercionType.
Indicates that there is no common denominator type by throwing CoercionException
.
types
- is an array of one or more types, which can be Java built-in (primitive or wrapper)
or user types
CoercionException
- when no coercion type could be determinedpublic static Class getClassForName(String className) throws ClassNotFoundException
className
- is the fully-qualified class name, java primitive types included.
ClassNotFoundException
- if the class cannot be found
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |