Package org.apache.camel.support
Class ObjectHelper
java.lang.Object
org.apache.camel.support.ObjectHelper
A number of useful helper methods for working with Objects
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
callWithTCCL
(Callable<?> call, ClassLoader classloader) Calling the Callable with the setting of TCCL with a given classloader.static Object
callWithTCCL
(Callable<?> call, org.apache.camel.Exchange exchange) Calling the Callable with the setting of TCCL with the camel context application classloader.static int
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefullystatic int
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefullystatic Iterable<?>
createIterable
(Object value) Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by comma, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterable<?>
createIterable
(Object value, String delimiter) Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterable<?>
createIterable
(Object value, String delimiter, boolean allowEmptyValues) Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterable<?>
createIterable
(Object value, String delimiter, boolean allowEmptyValues, boolean pattern) Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuecreateIterable
(String value) createIterable
(String value, String delimiter) createIterable
(String value, String delimiter, boolean allowEmptyValues) createIterable
(String value, String delimiter, boolean allowEmptyValues, boolean pattern) static Iterator<?>
createIterator
(Object value) Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by comma, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterator<?>
createIterator
(Object value, String delimiter) Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterator<?>
createIterator
(Object value, String delimiter, boolean allowEmptyValues) Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Iterator<?>
createIterator
(Object value, String delimiter, boolean allowEmptyValues, boolean pattern) Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single valuestatic Object
invokeMethod
(Method method, Object instance, Object... parameters) A helper method to invoke a method via reflection and wrap any exceptions asRuntimeCamelException
instancesstatic Object
invokeMethodSafe
(Method method, Object instance, Object... parameters) A helper method to invoke a method via reflection in a safe way by allowing to invoke methods that are not accessible by default and wrap any exceptions asRuntimeCamelException
instancesstatic boolean
isFloatingNumber
(String text) Checks whether the text is a float point numberstatic boolean
Checks whether the text is an integer numberstatic <T> T
newInstance
(Class<?> actualType, Class<T> expectedType) A helper method to create a new instance of a type using the default constructor arguments.static <T> T
newInstance
(Class<T> type) A helper method to create a new instance of a type using the default constructor arguments.static int
typeCoerceCompare
(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects ordering in which it uses type coercion to coerce types between the left and right values.static boolean
typeCoerceContains
(org.apache.camel.TypeConverter typeConverter, Object collectionOrArray, Object value, boolean ignoreCase) Returns true if the collection contains the specified valuestatic boolean
typeCoerceEquals
(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects for equality in which it uses type coercion to coerce types between the left and right values.static boolean
typeCoerceEquals
(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue, boolean ignoreCase) A helper method for comparing objects for equality in which it uses type coercion to coerce types between the left and right values.static boolean
typeCoerceNotEquals
(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects for inequality in which it uses type coercion to coerce types between the left and right values.
-
Method Details
-
typeCoerceEquals
public static boolean typeCoerceEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects for equality in which it uses type coercion to coerce types between the left and right values. This allows you test for equality for example with a String and Integer type as Camel will be able to coerce the types. -
typeCoerceEquals
public static boolean typeCoerceEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue, boolean ignoreCase) A helper method for comparing objects for equality in which it uses type coercion to coerce types between the left and right values. This allows you test for equality for example with a String and Integer type as Camel will be able to coerce the types. -
typeCoerceNotEquals
public static boolean typeCoerceNotEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects for inequality in which it uses type coercion to coerce types between the left and right values. This allows you test for inequality for example with a String and Integer type as Camel will be able to coerce the types. -
typeCoerceCompare
public static int typeCoerceCompare(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue) A helper method for comparing objects ordering in which it uses type coercion to coerce types between the left and right values. This allows you test for ordering for example with a String and Integer type as Camel will be able to coerce the types. -
isNumber
Checks whether the text is an integer number -
isFloatingNumber
Checks whether the text is a float point number -
invokeMethod
A helper method to invoke a method via reflection and wrap any exceptions asRuntimeCamelException
instances- Parameters:
method
- the method to invokeinstance
- the object instance (or null for static methods)parameters
- the parameters to the method- Returns:
- the result of the method invocation
-
invokeMethodSafe
public static Object invokeMethodSafe(Method method, Object instance, Object... parameters) throws InvocationTargetException, IllegalAccessException A helper method to invoke a method via reflection in a safe way by allowing to invoke methods that are not accessible by default and wrap any exceptions asRuntimeCamelException
instances- Parameters:
method
- the method to invokeinstance
- the object instance (or null for static methods)parameters
- the parameters to the method- Returns:
- the result of the method invocation
- Throws:
InvocationTargetException
IllegalAccessException
-
newInstance
A helper method to create a new instance of a type using the default constructor arguments. -
newInstance
A helper method to create a new instance of a type using the default constructor arguments. -
compare
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefully -
compare
A helper method for performing an ordered comparison on the objects handling nulls and objects which do not handle sorting gracefully- Parameters:
a
- the first objectb
- the second objectignoreCase
- ignore case for string comparison
-
callWithTCCL
public static Object callWithTCCL(Callable<?> call, org.apache.camel.Exchange exchange) throws Exception Calling the Callable with the setting of TCCL with the camel context application classloader.- Parameters:
call
- the Callable instanceexchange
- the exchange- Returns:
- the result of Callable return
- Throws:
Exception
-
callWithTCCL
Calling the Callable with the setting of TCCL with a given classloader.- Parameters:
call
- the Callable instanceclassloader
- the class loader- Returns:
- the result of Callable return
- Throws:
Exception
-
createIterable
Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by comma, 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. This method does not allow empty values- Parameters:
value
- the value- Returns:
- the iterable
-
createIterable
Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value This method does not allow empty values- Parameters:
value
- the valuedelimiter
- delimiter for separating String values- Returns:
- the iterable
-
createIterable
-
createIterable
-
createIterable
-
createIterable
-
createIterator
Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by comma, 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. This method does not allow empty values- Parameters:
value
- the value- Returns:
- the iterator
-
createIterator
Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value This method does not allow empty values- Parameters:
value
- the valuedelimiter
- delimiter for separating String values- Returns:
- the iterator
-
createIterator
Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value In case of primitive type arrays the returnedIterator
iterates over the corresponding Java primitive wrapper objects of the given elements inside thevalue
array. That's we get an autoboxing of the primitive types here for free as it's also the case in Java language itself.- Parameters:
value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty values- Returns:
- the iterator
-
createIterator
public static Iterator<?> createIterator(Object value, String delimiter, boolean allowEmptyValues, boolean pattern) Creates an iterator over the value if the value is aStream
, collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value In case of primitive type arrays the returnedIterator
iterates over the corresponding Java primitive wrapper objects of the given elements inside thevalue
array. That's we get an autoboxing of the primitive types here for free as it's also the case in Java language itself.- Parameters:
value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuespattern
- whether the delimiter is a pattern- Returns:
- the iterator
-
createIterable
Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value In case of primitive type arrays the returnedIterable
iterates over the corresponding Java primitive wrapper objects of the given elements inside thevalue
array. That's we get an autoboxing of the primitive types here for free as it's also the case in Java language itself.- Parameters:
value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty values- Returns:
- the iterable
- See Also:
-
createIterable
public static Iterable<?> createIterable(Object value, String delimiter, boolean allowEmptyValues, boolean pattern) Creates an iterable over the value if the value is a collection, an Object[], a String with values separated by the given delimiter, or a primitive type array; otherwise to simplify the caller's code, we just create a singleton collection iterator over a single value In case of primitive type arrays the returnedIterable
iterates over the corresponding Java primitive wrapper objects of the given elements inside thevalue
array. That's we get an autoboxing of the primitive types here for free as it's also the case in Java language itself.- Parameters:
value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuespattern
- whether the delimiter is a pattern- Returns:
- the iterable
- See Also:
-
typeCoerceContains
public static boolean typeCoerceContains(org.apache.camel.TypeConverter typeConverter, Object collectionOrArray, Object value, boolean ignoreCase) Returns true if the collection contains the specified value
-