|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.espertech.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 |
getClassForSimpleName(String className)
Returns the boxed class for the given classname, recognizing all primitive and abbreviations, uppercase and lowercase. |
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 String |
getParameterAsString(Class param)
Returns a parameter as a string text, allowing null values to represent a null select expression type. |
static String |
getParameterAsString(Class[] parameters)
Returns a comma-separated parameter type list in readable form, considering arrays and null-type parameters. |
static Class |
getPrimitiveClassForName(String typeName)
Returns the class for a Java primitive type name, ignoring case, and considering String as a primitive. |
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 invocationType,
Class declarationType)
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 |
isImplementsInterface(Class clazz,
Class interfaceClass)
Method to check if a given class, and its superclasses and interfaces (deep), implement a given interface. |
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. |
static boolean |
isNumericNonFP(Class clazz)
Determines if the class passed in is one of the numeric classes and not a floating point. |
static Object |
parse(Class clazz,
String text)
Parse the String using the given Java built-in class for parsing. |
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 String getParameterAsString(Class[] parameters)
parameters
- is the parameter types to render
public static String getParameterAsString(Class param)
param
- is the parameter type
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 boolean isNumericNonFP(Class clazz)
clazz
- to check
public static boolean isAssignmentCompatible(Class invocationType, Class declarationType)
invocationType
- type to assign fromdeclarationType
- 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 foundpublic static Class getClassForSimpleName(String className) throws EventAdapterException
Recognizes "int" as Integer.class and "strIng" as String.class, and "Integer" as Integer.class, and so on.
className
- is the name to recognize
EventAdapterException
- is throw if the class cannot be identifiedpublic static Class getPrimitiveClassForName(String typeName)
typeName
- is a potential primitive Java type, or some other type name
public static Object parse(Class clazz, String text)
clazz
- is the class to parse the value totext
- is the text to parse
public static boolean isImplementsInterface(Class clazz, Class interfaceClass)
clazz
- to check, including all its superclasses and their interfaces and extendsinterfaceClass
- is the interface class to look for
|
© 2007 EsperTech Inc. All rights reserved. Visit us at espertech.com |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |