public final class ObjectHelper extends Object
Modifier and Type | Method and Description |
---|---|
static 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 |
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)
Deprecated.
|
static 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 value
Will default use comma for String separating String values.
|
static 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 value
This method does not allow empty values
|
static 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 value
|
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
|
static Iterable<String> |
createIterable(String value) |
static Iterable<String> |
createIterable(String value,
String delimiter) |
static Iterable<String> |
createIterable(String value,
String delimiter,
boolean allowEmptyValues) |
static Iterable<String> |
createIterable(String value,
String delimiter,
boolean allowEmptyValues,
boolean pattern) |
static Iterator<?> |
createIterator(Object value)
Creates an iterator over the value if the value is a
Stream , 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. |
static Iterator<?> |
createIterator(Object value,
String delimiter)
Creates an iterator over the value if the value is a
Stream , 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 |
static Iterator<?> |
createIterator(Object value,
String delimiter,
boolean allowEmptyValues)
Creates an iterator over the value if the value is a
Stream , 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 |
static Iterator<?> |
createIterator(Object value,
String delimiter,
boolean allowEmptyValues,
boolean pattern)
Creates an iterator over the value if the value is a
Stream , 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 |
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 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 as
RuntimeCamelException instances |
static boolean |
isFloatingNumber(String text)
Checks whether the text is a float point number
|
static boolean |
isNumber(String text)
Checks whether the text is an integer number
|
static <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 value
|
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.
|
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.
|
public static boolean typeCoerceEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue)
public static boolean typeCoerceEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue, boolean ignoreCase)
public static boolean typeCoerceNotEquals(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue)
public static int typeCoerceCompare(org.apache.camel.TypeConverter converter, Object leftValue, Object rightValue)
public static boolean isNumber(String text)
public static boolean isFloatingNumber(String text)
public static Object invokeMethod(Method method, Object instance, Object... parameters)
RuntimeCamelException
instancesmethod
- the method to invokeinstance
- the object instance (or null for static methods)parameters
- the parameters to the methodpublic static Object invokeMethodSafe(Method method, Object instance, Object... parameters) throws InvocationTargetException, IllegalAccessException
RuntimeCamelException
instancesmethod
- the method to invokeinstance
- the object instance (or null for static methods)parameters
- the parameters to the methodInvocationTargetException
IllegalAccessException
public static <T> T newInstance(Class<T> type)
public static <T> T newInstance(Class<?> actualType, Class<T> expectedType)
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 Object callWithTCCL(Callable<?> call, org.apache.camel.Exchange exchange) throws Exception
call
- the Callable instanceexchange
- the exchangeException
public static Object callWithTCCL(Callable<?> call, ClassLoader classloader) throws Exception
call
- the Callable instanceclassloader
- the class loaderException
public static Iterable<?> createIterable(Object value)
value
- the valuepublic static Iterable<?> createIterable(Object value, String delimiter)
value
- the valuedelimiter
- delimiter for separating String valuespublic static Iterable<String> createIterable(String value, String delimiter, boolean allowEmptyValues)
public static Iterable<String> createIterable(String value, String delimiter, boolean allowEmptyValues, boolean pattern)
public static Iterator<?> createIterator(Object value)
Stream
, 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 valuesvalue
- the valuepublic static Iterator<?> createIterator(Object value, String delimiter)
Stream
, 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 valuesvalue
- the valuedelimiter
- delimiter for separating String valuespublic static Iterator<?> createIterator(Object value, String delimiter, boolean allowEmptyValues)
Stream
, 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 returned Iterator
iterates over the corresponding Java primitive
wrapper objects of the given elements inside the value
array. That's we get an autoboxing of the
primitive types here for free as it's also the case in Java language itself.value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuespublic static Iterator<?> createIterator(Object value, String delimiter, boolean allowEmptyValues, boolean pattern)
Stream
, 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 returned Iterator
iterates over the corresponding Java primitive
wrapper objects of the given elements inside the value
array. That's we get an autoboxing of the
primitive types here for free as it's also the case in Java language itself.value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuespattern
- whether the delimiter is a patternpublic static Iterable<?> createIterable(Object value, String delimiter, boolean allowEmptyValues)
Iterable
iterates over the corresponding Java primitive
wrapper objects of the given elements inside the value
array. That's we get an autoboxing of the
primitive types here for free as it's also the case in Java language itself.value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuesIterable
public static Iterable<?> createIterable(Object value, String delimiter, boolean allowEmptyValues, boolean pattern)
Iterable
iterates over the corresponding Java primitive
wrapper objects of the given elements inside the value
array. That's we get an autoboxing of the
primitive types here for free as it's also the case in Java language itself.value
- the valuedelimiter
- delimiter for separating String valuesallowEmptyValues
- whether to allow empty valuespattern
- whether the delimiter is a patternIterable
@Deprecated public static boolean contains(Object collectionOrArray, Object value)
typeCoerceContains(TypeConverter, Object, Object, boolean)
Apache Camel