|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.camel.util.ObjectHelper
public final class ObjectHelper
A number of useful helper methods for working with Objects
Method Summary | ||
---|---|---|
static String |
after(String text,
String after)
|
|
static String |
asString(Object[] objects)
Turns the given object arrays into a meaningful string |
|
static String |
before(String text,
String before)
|
|
static String |
between(String text,
String after,
String before)
|
|
static String |
capitalize(String text)
|
|
static
|
cast(Class<T> toType,
Object value)
Converts the given value to the required type or throw a meaningful exception |
|
static String |
classCanonicalName(Object value)
Returns the canonical type name of the given value |
|
static String |
className(Object value)
Returns the type name of the given value |
|
static void |
close(Closeable closeable,
String name,
org.apache.commons.logging.Log log)
Closes the given resource if it is available, logging any closing exceptions to the given log |
|
static int |
compare(Object a,
Object b)
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefully |
|
static int |
compare(Object a,
Object b,
boolean ignoreCase)
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefully |
|
static boolean |
contains(Object collectionOrArray,
Object value)
Returns true if the collection contains the specified value |
|
static Class<?> |
convertPrimitiveTypeToWrapperType(Class<?> type)
Converts primitive types such as int to its wrapper type like Integer |
|
static Iterator<Throwable> |
createExceptionIterator(Throwable exception)
Creates an iterator to walk the exception from the bottom up (the last caused by going upwards to the root exception). |
|
static Iterator<Object> |
createIterator(Object value)
Creates an iterator over the value if the value is a collection, an Object[] or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value Will default use comma for String separating String values. |
|
static Iterator<Object> |
createIterator(Object value,
String delimiter)
Creates an iterator over the value if the value is a collection, an Object[] or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value |
|
static boolean |
equal(Object a,
Object b)
A helper method for comparing objects for equality while handling nulls |
|
static boolean |
equalByteArray(byte[] a,
byte[] b)
A helper method for comparing byte arrays for equality while handling nulls |
|
static boolean |
evaluateValuePredicate(Object value)
Evaluate the value as a predicate which attempts to convert the value to a boolean otherwise true is returned if the value is not null |
|
static List<Method> |
findMethodsWithAnnotation(Class<?> type,
Class<? extends Annotation> annotationType)
Returns a list of methods which are annotated with the given annotation |
|
static List<Method> |
findMethodsWithAnnotation(Class<?> type,
Class<? extends Annotation> annotationType,
boolean checkMetaAnnotations)
Returns a list of methods which are annotated with the given annotation |
|
static String |
getDefaultCharacterSet()
Helper method to return the default character set name |
|
static
|
getException(Class<T> type,
Throwable exception)
Retrieves the given exception type from the exception. |
|
static String |
getIdentityHashCode(Object object)
|
|
static String |
getPropertyName(Method method)
Returns the Java Bean property name of the given method, if it is a setter |
|
static Scanner |
getScanner(Exchange exchange,
Object value)
Creates a Scanner for scanning the given value. |
|
static boolean |
getSystemProperty(String name,
Boolean defaultValue)
A helper method to access a boolean system property, catching any security exceptions |
|
static String |
getSystemProperty(String name,
String defaultValue)
A helper method to access a system property, catching any security exceptions |
|
static boolean |
hasAnnotation(AnnotatedElement elem,
Class<? extends Annotation> annotationType,
boolean checkMetaAnnotations)
Checks if a Class or Method are annotated with the given annotation |
|
static boolean |
hasAnnotation(Annotation[] annotations,
Class<?> type)
Returns true if the given collection of annotations matches the given type |
|
static Object |
invokeMethod(Method method,
Object instance,
Object... parameters)
A helper method to invoke a method via reflection and wrap any exceptions as RuntimeCamelException instances |
|
static boolean |
isAssignableFrom(Class<?> a,
Class<?> b)
Returns true if a class is assignable from another class like the Class.isAssignableFrom(Class) method but which also includes
coercion between primitive types to deal with Java 5 primitive type
wrapping |
|
static boolean |
isEmpty(Object value)
Tests whether the value is null or an empty string. |
|
static boolean |
isEqualToAny(Object object,
Object... values)
Returns true if the given object is equal to any of the expected value |
|
static boolean |
isJavaIdentifier(String name)
Returns true if the given name is a valid java identifier |
|
static boolean |
isNotEmpty(Object value)
Tests whether the value is not null or an empty string. |
|
static boolean |
isOverridingMethod(Method source,
Method target)
Tests whether the target method overrides the source method. |
|
static Class<?> |
loadClass(String name)
Attempts to load the given class name using the thread context class loader or the class loader used to load this class |
|
static Class<?> |
loadClass(String name,
ClassLoader loader)
Attempts to load the given class name using the thread context class loader or the given class loader |
|
static InputStream |
loadResourceAsStream(String name)
Attempts to load the given resource as a stream using the thread context class loader or the class loader used to load this class |
|
static URL |
loadResourceAsURL(String name)
Attempts to load the given resource as a stream using the thread context class loader or the class loader used to load this class |
|
static boolean |
matches(List<Object> list)
Returns the predicate matching boolean on a List result set where
if the first element is a boolean its value is used otherwise this method
returns true if the collection is not empty |
|
static String |
name(Class<?> type)
Returns the type name of the given type or null if the type variable is null |
|
static
|
newInstance(Class<?> actualType,
Class<T> expectedType)
A helper method to create a new instance of a type using the default constructor arguments. |
|
static
|
newInstance(Class<T> type)
A helper method to create a new instance of a type using the default constructor arguments. |
|
static String |
normalizeClassName(String name)
Cleans the string to pure java identifier so we can use it for loading class names. |
|
static void |
notEmpty(String value,
String name)
Asserts whether the string is not empty. |
|
static void |
notEmpty(String value,
String name,
Object on)
Asserts whether the string is not empty. |
|
static void |
notNull(Object value,
String name)
Asserts whether the value is not null |
|
static void |
notNull(Object value,
String name,
Object on)
Asserts whether the value is not null |
|
static String |
removeStartingCharacters(String text,
char ch)
Removes any starting characters on the given text which match the given character |
|
static String[] |
splitOnCharacter(String value,
String needle,
int count)
|
|
static Boolean |
toBoolean(Object value)
|
|
static Object |
type(Object bean)
Returns the type of the given object or null if the value is null |
|
static int |
typeCoerceCompare(TypeConverter converter,
Object leftValue,
Object rightValue)
A helper method for comparing objects ordering in which it uses type coerce to coerce types between the left and right values. |
|
static boolean |
typeCoerceEquals(TypeConverter converter,
Object leftValue,
Object rightValue)
A helper method for comparing objects for equality in which it uses type coerce to coerce types between the left and right values. |
|
static boolean |
typeCoerceNotEquals(TypeConverter converter,
Object leftValue,
Object rightValue)
A helper method for comparing objects for equality in which it uses type coerce to coerce types between the left and right values. |
|
static CamelExecutionException |
wrapCamelExecutionException(Exchange exchange,
Throwable e)
Wraps the caused exception in a CamelExecutionException if its not
already such an exception. |
|
static RuntimeCamelException |
wrapRuntimeCamelException(Throwable e)
Wraps the caused exception in a RuntimeCamelException if its not
already such an exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean typeCoerceEquals(TypeConverter converter, Object leftValue, Object rightValue)
public static boolean typeCoerceNotEquals(TypeConverter converter, Object leftValue, Object rightValue)
public static int typeCoerceCompare(TypeConverter converter, Object leftValue, Object rightValue)
public static boolean equal(Object a, Object b)
public static boolean equalByteArray(byte[] a, byte[] b)
public static boolean isEqualToAny(Object object, Object... values)
public static int compare(Object a, Object b)
public static int compare(Object a, Object b, boolean ignoreCase)
a
- the first objectb
- the second objectignoreCase
- ignore case for string comparisonpublic static Boolean toBoolean(Object value)
public static void notNull(Object value, String name)
value
- the value to testname
- the key that resolved the value
IllegalArgumentException
- is thrown if assertion failspublic static void notNull(Object value, String name, Object on)
value
- the value to teston
- additional description to indicate where this problem occured (appended as toString())name
- the key that resolved the value
IllegalArgumentException
- is thrown if assertion failspublic static void notEmpty(String value, String name)
value
- the string to testname
- the key that resolved the value
IllegalArgumentException
- is thrown if assertion failspublic static void notEmpty(String value, String name, Object on)
value
- the string to teston
- additional description to indicate where this problem occured (appended as toString())name
- the key that resolved the value
IllegalArgumentException
- is thrown if assertion failspublic static boolean isEmpty(Object value)
value
- the value, if its a String it will be tested for text length as well
public static boolean isNotEmpty(Object value)
value
- the value, if its a String it will be tested for text length as well
public static String[] splitOnCharacter(String value, String needle, int count)
public static String removeStartingCharacters(String text, char ch)
text
- the stringch
- the initial characters to remove
public static String capitalize(String text)
public static String after(String text, String after)
public static String before(String text, String before)
public static String between(String text, String after, String before)
public static boolean contains(Object collectionOrArray, Object value)
public static Iterator<Object> createIterator(Object value)
value
- the value
public static Iterator<Object> createIterator(Object value, String delimiter)
value
- the valuedelimiter
- delimiter for separating String values
public static boolean matches(List<Object> list)
List
result set where
if the first element is a boolean its value is used otherwise this method
returns true if the collection is not empty
public static String getSystemProperty(String name, String defaultValue)
name
- the name of the system property requireddefaultValue
- the default value to use if the property is not
available or a security exception prevents access
public static boolean getSystemProperty(String name, Boolean defaultValue)
name
- the name of the system property requireddefaultValue
- the default value to use if the property is not
available or a security exception prevents access
public static String name(Class<?> type)
public static String className(Object value)
public static String classCanonicalName(Object value)
public static Class<?> loadClass(String name)
name
- the name of the class to load
public static Class<?> loadClass(String name, ClassLoader loader)
name
- the name of the class to loadloader
- the class loader to use after the thread context class
loader
public static InputStream loadResourceAsStream(String name)
name
- the name of the resource to load
public static URL loadResourceAsURL(String name)
name
- the name of the resource to load
public static Object invokeMethod(Method method, Object instance, Object... parameters)
RuntimeCamelException
instances
method
- the method to invokeinstance
- the object instance (or null for static methods)parameters
- the parameters to the method
public static boolean isOverridingMethod(Method source, Method target)
source
- the source methodtarget
- the target method
public static List<Method> findMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType)
type
- the type to reflect onannotationType
- the annotation type
public static List<Method> findMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations)
type
- the type to reflect onannotationType
- the annotation typecheckMetaAnnotations
- check for meta annotations
public static boolean hasAnnotation(AnnotatedElement elem, Class<? extends Annotation> annotationType, boolean checkMetaAnnotations)
elem
- the Class or Method to reflect onannotationType
- the annotation typecheckMetaAnnotations
- check for meta annotations
public static String asString(Object[] objects)
objects
- an array of objects or null
public static boolean isAssignableFrom(Class<?> a, Class<?> b)
Class.isAssignableFrom(Class)
method but which also includes
coercion between primitive types to deal with Java 5 primitive type
wrapping
public static Class<?> convertPrimitiveTypeToWrapperType(Class<?> type)
Integer
public static String getDefaultCharacterSet()
public static String getPropertyName(Method method)
public static boolean hasAnnotation(Annotation[] annotations, Class<?> type)
public static void close(Closeable closeable, String name, org.apache.commons.logging.Log log)
closeable
- the object to closename
- the name of the resourcelog
- the log to use when reporting closure warningspublic static <T> T cast(Class<T> toType, Object value)
public static <T> T newInstance(Class<T> type)
public static <T> T newInstance(Class<?> actualType, Class<T> expectedType)
public static boolean isJavaIdentifier(String name)
public static Object type(Object bean)
public static boolean evaluateValuePredicate(Object value)
public static RuntimeCamelException wrapRuntimeCamelException(Throwable e)
RuntimeCamelException
if its not
already such an exception.
e
- the caused exception
public static CamelExecutionException wrapCamelExecutionException(Exchange exchange, Throwable e)
CamelExecutionException
if its not
already such an exception.
e
- the caused exception
public static String normalizeClassName(String name)
name
- the class name
public static Iterator<Throwable> createExceptionIterator(Throwable exception)
exception
- the exception
public static <T> T getException(Class<T> type, Throwable exception)
type
- the exception type wanted to retrieveexception
- the caused exception
public static Scanner getScanner(Exchange exchange, Object value)
Scanner
for scanning the given value.
exchange
- the current exchangevalue
- the value, typically the message IN body
public static String getIdentityHashCode(Object object)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |