|
||||||||||
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 java.lang.String |
after(java.lang.String text,
java.lang.String after)
|
|
static java.lang.String |
asString(java.lang.Object[] objects)
Turns the given object arrays into a meaningful string |
|
static java.lang.String |
before(java.lang.String text,
java.lang.String before)
|
|
static java.lang.String |
between(java.lang.String text,
java.lang.String after,
java.lang.String before)
|
|
static java.lang.String |
capitalize(java.lang.String text)
|
|
static
|
cast(java.lang.Class<T> toType,
java.lang.Object value)
Converts the given value to the required type or throw a meaningful exception |
|
static java.lang.String |
classCanonicalName(java.lang.Object value)
Returns the canonical type name of the given value |
|
static java.lang.String |
className(java.lang.Object value)
Returns the type name of the given value |
|
static void |
close(java.io.Closeable closeable,
java.lang.String name,
org.slf4j.Logger log)
Deprecated. will be removed in Camel 3.0. Instead use IOHelper.close(java.io.Closeable, String, org.slf4j.Logger) instead |
|
static int |
compare(java.lang.Object a,
java.lang.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(java.lang.Object a,
java.lang.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(java.lang.Object collectionOrArray,
java.lang.Object value)
Returns true if the collection contains the specified value |
|
static java.lang.Class<?> |
convertPrimitiveTypeToWrapperType(java.lang.Class<?> type)
Converts primitive types such as int to its wrapper type like Integer |
|
static java.util.Iterator<java.lang.Throwable> |
createExceptionIterator(java.lang.Throwable exception)
Creates an iterator to walk the exception from the bottom up (the last caused by going upwards to the root exception). |
|
static java.util.Iterator<java.lang.Object> |
createIterator(java.lang.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 java.util.Iterator<java.lang.Object> |
createIterator(java.lang.Object value,
java.lang.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(java.lang.Object a,
java.lang.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(java.lang.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 java.util.List<java.lang.reflect.Method> |
findMethodsWithAnnotation(java.lang.Class<?> type,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns a list of methods which are annotated with the given annotation |
|
static java.util.List<java.lang.reflect.Method> |
findMethodsWithAnnotation(java.lang.Class<?> type,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
boolean checkMetaAnnotations)
Returns a list of methods which are annotated with the given annotation |
|
static java.util.Properties |
getCamelPropertiesWithPrefix(java.lang.String prefix,
CamelContext camelContext)
A helper method to access a camel context properties with a prefix |
|
static java.lang.String |
getDefaultCharacterSet()
Helper method to return the default character set name |
|
static
|
getException(java.lang.Class<T> type,
java.lang.Throwable exception)
Retrieves the given exception type from the exception. |
|
static java.lang.String |
getIdentityHashCode(java.lang.Object object)
|
|
static java.lang.String |
getPropertyName(java.lang.reflect.Method method)
Returns the Java Bean property name of the given method, if it is a setter |
|
static java.util.Scanner |
getScanner(Exchange exchange,
java.lang.Object value)
Creates a Scanner for scanning the given value. |
|
static boolean |
getSystemProperty(java.lang.String name,
java.lang.Boolean defaultValue)
A helper method to access a boolean system property, catching any security exceptions |
|
static java.lang.String |
getSystemProperty(java.lang.String name,
java.lang.String defaultValue)
A helper method to access a system property, catching any security exceptions |
|
static boolean |
hasAnnotation(java.lang.reflect.AnnotatedElement elem,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
boolean checkMetaAnnotations)
Checks if a Class or Method are annotated with the given annotation |
|
static boolean |
hasAnnotation(java.lang.annotation.Annotation[] annotations,
java.lang.Class<?> type)
Returns true if the given collection of annotations matches the given type |
|
static boolean |
hasDefaultPublicNoArgConstructor(java.lang.Class type)
Does the given class have a default public no-arg constructor. |
|
static java.lang.Object |
invokeMethod(java.lang.reflect.Method method,
java.lang.Object instance,
java.lang.Object... parameters)
A helper method to invoke a method via reflection and wrap any exceptions as RuntimeCamelException instances |
|
static boolean |
isAssignableFrom(java.lang.Class<?> a,
java.lang.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(java.lang.Object value)
Tests whether the value is null or an empty string. |
|
static boolean |
isEqualToAny(java.lang.Object object,
java.lang.Object... values)
Returns true if the given object is equal to any of the expected value |
|
static boolean |
isJavaIdentifier(java.lang.String name)
Returns true if the given name is a valid java identifier |
|
static boolean |
isNotEmpty(java.lang.Object value)
Tests whether the value is not null or an empty string. |
|
static boolean |
isOverridingMethod(java.lang.reflect.Method source,
java.lang.reflect.Method target)
Tests whether the target method overrides the source method. |
|
static java.lang.Class<?> |
loadClass(java.lang.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 java.lang.Class<?> |
loadClass(java.lang.String name,
java.lang.ClassLoader loader)
Attempts to load the given class name using the thread context class loader or the given class loader |
|
static java.lang.Class<?> |
loadClass(java.lang.String name,
java.lang.ClassLoader loader,
boolean needToWarn)
Attempts to load the given class name using the thread context class loader or the given class loader |
|
static java.io.InputStream |
loadResourceAsStream(java.lang.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 java.net.URL |
loadResourceAsURL(java.lang.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 java.lang.Class<?> |
loadSimpleType(java.lang.String name)
Load a simple type |
|
static java.lang.String |
lookupConstantFieldValue(java.lang.Class clazz,
java.lang.String name)
Lookup the constant field on the given class with the given name |
|
static boolean |
matches(java.util.List 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 java.lang.String |
name(java.lang.Class<?> type)
Returns the type name of the given type or null if the type variable is null |
|
static
|
newInstance(java.lang.Class<?> actualType,
java.lang.Class<T> expectedType)
A helper method to create a new instance of a type using the default constructor arguments. |
|
static
|
newInstance(java.lang.Class<T> type)
A helper method to create a new instance of a type using the default constructor arguments. |
|
static java.lang.String |
normalizeClassName(java.lang.String name)
Cleans the string to pure java identifier so we can use it for loading class names. |
|
static void |
notEmpty(java.lang.String value,
java.lang.String name)
Asserts whether the string is not empty. |
|
static void |
notEmpty(java.lang.String value,
java.lang.String name,
java.lang.Object on)
Asserts whether the string is not empty. |
|
static void |
notNull(java.lang.Object value,
java.lang.String name)
Asserts whether the value is not null |
|
static void |
notNull(java.lang.Object value,
java.lang.String name,
java.lang.Object on)
Asserts whether the value is not null |
|
static java.lang.String |
removeStartingCharacters(java.lang.String text,
char ch)
Removes any starting characters on the given text which match the given character |
|
static java.lang.String[] |
splitOnCharacter(java.lang.String value,
java.lang.String needle,
int count)
|
|
static java.lang.Boolean |
toBoolean(java.lang.Object value)
|
|
static java.lang.Object |
type(java.lang.Object bean)
Returns the type of the given object or null if the value is null |
|
static int |
typeCoerceCompare(TypeConverter converter,
java.lang.Object leftValue,
java.lang.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,
java.lang.Object leftValue,
java.lang.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,
java.lang.Object leftValue,
java.lang.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,
java.lang.Throwable e)
Wraps the caused exception in a CamelExecutionException if its not
already such an exception. |
|
static RuntimeCamelException |
wrapRuntimeCamelException(java.lang.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, java.lang.Object leftValue, java.lang.Object rightValue)
public static boolean typeCoerceNotEquals(TypeConverter converter, java.lang.Object leftValue, java.lang.Object rightValue)
public static int typeCoerceCompare(TypeConverter converter, java.lang.Object leftValue, java.lang.Object rightValue)
public static boolean equal(java.lang.Object a, java.lang.Object b)
public static boolean equalByteArray(byte[] a, byte[] b)
public static boolean isEqualToAny(java.lang.Object object, java.lang.Object... values)
public static int compare(java.lang.Object a, java.lang.Object b)
public static int compare(java.lang.Object a, java.lang.Object b, boolean ignoreCase)
a
- the first objectb
- the second objectignoreCase
- ignore case for string comparisonpublic static java.lang.Boolean toBoolean(java.lang.Object value)
public static void notNull(java.lang.Object value, java.lang.String name)
value
- the value to testname
- the key that resolved the value
java.lang.IllegalArgumentException
- is thrown if assertion failspublic static void notNull(java.lang.Object value, java.lang.String name, java.lang.Object on)
value
- the value to teston
- additional description to indicate where this problem occurred (appended as toString())name
- the key that resolved the value
java.lang.IllegalArgumentException
- is thrown if assertion failspublic static void notEmpty(java.lang.String value, java.lang.String name)
value
- the string to testname
- the key that resolved the value
java.lang.IllegalArgumentException
- is thrown if assertion failspublic static void notEmpty(java.lang.String value, java.lang.String name, java.lang.Object on)
value
- the string to teston
- additional description to indicate where this problem occurred (appended as toString())name
- the key that resolved the value
java.lang.IllegalArgumentException
- is thrown if assertion failspublic static boolean isEmpty(java.lang.Object value)
value
- the value, if its a String it will be tested for text length as well
public static boolean isNotEmpty(java.lang.Object value)
value
- the value, if its a String it will be tested for text length as well
public static java.lang.String[] splitOnCharacter(java.lang.String value, java.lang.String needle, int count)
public static java.lang.String removeStartingCharacters(java.lang.String text, char ch)
text
- the stringch
- the initial characters to remove
public static java.lang.String capitalize(java.lang.String text)
public static java.lang.String after(java.lang.String text, java.lang.String after)
public static java.lang.String before(java.lang.String text, java.lang.String before)
public static java.lang.String between(java.lang.String text, java.lang.String after, java.lang.String before)
public static boolean contains(java.lang.Object collectionOrArray, java.lang.Object value)
public static java.util.Iterator<java.lang.Object> createIterator(java.lang.Object value)
value
- the value
public static java.util.Iterator<java.lang.Object> createIterator(java.lang.Object value, java.lang.String delimiter)
value
- the valuedelimiter
- delimiter for separating String values
public static boolean matches(java.util.List 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 java.lang.String getSystemProperty(java.lang.String name, java.lang.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(java.lang.String name, java.lang.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 java.util.Properties getCamelPropertiesWithPrefix(java.lang.String prefix, CamelContext camelContext)
prefix
- the prefixcamelContext
- the camel context
public static java.lang.String name(java.lang.Class<?> type)
public static java.lang.String className(java.lang.Object value)
public static java.lang.String classCanonicalName(java.lang.Object value)
public static java.lang.Class<?> loadClass(java.lang.String name)
name
- the name of the class to load
public static java.lang.Class<?> loadClass(java.lang.String name, java.lang.ClassLoader loader)
name
- the name of the class to loadloader
- the class loader to use after the thread context class loader
public static java.lang.Class<?> loadClass(java.lang.String name, java.lang.ClassLoader loader, boolean needToWarn)
name
- the name of the class to loadloader
- the class loader to use after the thread context class loaderneedToWarn
- when true logs a warning when a class with the given name could not be loaded
public static java.lang.Class<?> loadSimpleType(java.lang.String name)
name
- the name of the class to load
public static java.io.InputStream loadResourceAsStream(java.lang.String name)
name
- the name of the resource to load
public static java.net.URL loadResourceAsURL(java.lang.String name)
name
- the name of the resource to load
public static java.lang.Object invokeMethod(java.lang.reflect.Method method, java.lang.Object instance, java.lang.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(java.lang.reflect.Method source, java.lang.reflect.Method target)
source
- the source methodtarget
- the target method
public static java.util.List<java.lang.reflect.Method> findMethodsWithAnnotation(java.lang.Class<?> type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
type
- the type to reflect onannotationType
- the annotation type
public static java.util.List<java.lang.reflect.Method> findMethodsWithAnnotation(java.lang.Class<?> type, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, boolean checkMetaAnnotations)
type
- the type to reflect onannotationType
- the annotation typecheckMetaAnnotations
- check for meta annotations
public static boolean hasAnnotation(java.lang.reflect.AnnotatedElement elem, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType, boolean checkMetaAnnotations)
elem
- the Class or Method to reflect onannotationType
- the annotation typecheckMetaAnnotations
- check for meta annotations
public static java.lang.String asString(java.lang.Object[] objects)
objects
- an array of objects or null
public static boolean isAssignableFrom(java.lang.Class<?> a, java.lang.Class<?> b)
Class.isAssignableFrom(Class)
method but which also includes
coercion between primitive types to deal with Java 5 primitive type
wrapping
public static java.lang.Class<?> convertPrimitiveTypeToWrapperType(java.lang.Class<?> type)
Integer
public static java.lang.String getDefaultCharacterSet()
public static java.lang.String getPropertyName(java.lang.reflect.Method method)
public static boolean hasAnnotation(java.lang.annotation.Annotation[] annotations, java.lang.Class<?> type)
@Deprecated public static void close(java.io.Closeable closeable, java.lang.String name, org.slf4j.Logger log)
IOHelper.close(java.io.Closeable, String, org.slf4j.Logger)
instead
closeable
- the object to closename
- the name of the resourcelog
- the log to use when reporting closure warningspublic static <T> T cast(java.lang.Class<T> toType, java.lang.Object value)
public static <T> T newInstance(java.lang.Class<T> type)
public static <T> T newInstance(java.lang.Class<?> actualType, java.lang.Class<T> expectedType)
public static boolean hasDefaultPublicNoArgConstructor(java.lang.Class type)
public static boolean isJavaIdentifier(java.lang.String name)
public static java.lang.Object type(java.lang.Object bean)
public static boolean evaluateValuePredicate(java.lang.Object value)
public static RuntimeCamelException wrapRuntimeCamelException(java.lang.Throwable e)
RuntimeCamelException
if its not
already such an exception.
e
- the caused exception
public static CamelExecutionException wrapCamelExecutionException(Exchange exchange, java.lang.Throwable e)
CamelExecutionException
if its not
already such an exception.
e
- the caused exception
public static java.lang.String normalizeClassName(java.lang.String name)
name
- the class name
public static java.util.Iterator<java.lang.Throwable> createExceptionIterator(java.lang.Throwable exception)
exception
- the exception
public static <T> T getException(java.lang.Class<T> type, java.lang.Throwable exception)
type
- the exception type wanted to retrieveexception
- the caused exception
public static java.util.Scanner getScanner(Exchange exchange, java.lang.Object value)
Scanner
for scanning the given value.
exchange
- the current exchangevalue
- the value, typically the message IN body
public static java.lang.String getIdentityHashCode(java.lang.Object object)
public static java.lang.String lookupConstantFieldValue(java.lang.Class clazz, java.lang.String name)
clazz
- the classname
- the name of the field to lookup
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |