org.apache.camel.util
Class ObjectHelper

java.lang.Object
  extended by org.apache.camel.util.ObjectHelper

public class ObjectHelper
extends Object

Version:
$Revision: 534560 $

Constructor Summary
ObjectHelper()
           
 
Method Summary
static String asString(Object[] objects)
          Turns the given object arrays into a meaningful string
static String className(Object value)
          Returns the type name of the given value
static int compare(Object a, Object b)
          A helper method for performing an ordered comparsion 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 boolean equals(Object a, Object b)
          A helper method for comparing objects for equality while handling nulls
static List<Method> findMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType)
          Returns a list of methods which are annotated with the given annotation
static String getSystemProperty(String name, String defaultValue)
          A helper method to access a system property, catching any security exceptions
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 isNotNullOrBlank(String text)
           
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 boolean matches(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 String name(Class type)
          Returns the type name of the given type or null if the type variable is null
static void notNull(Object value, String name)
           
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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectHelper

public ObjectHelper()
Method Detail

equals

public static boolean equals(Object a,
                             Object b)
A helper method for comparing objects for equality while handling nulls


compare

public static int compare(Object a,
                          Object b)
A helper method for performing an ordered comparsion on the objects handling nulls and objects which do not handle sorting gracefully


notNull

public static void notNull(Object value,
                           String name)

splitOnCharacter

public static String[] splitOnCharacter(String value,
                                        String needle,
                                        int count)

removeStartingCharacters

public static String removeStartingCharacters(String text,
                                              char ch)
Removes any starting characters on the given text which match the given character

Parameters:
text - the string
ch - the initial characters to remove
Returns:
either the original string or the new substring

contains

public static boolean contains(Object collectionOrArray,
                               Object value)
Returns true if the collection contains the specified value


matches

public static boolean matches(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


isNotNullOrBlank

public static boolean isNotNullOrBlank(String text)

getSystemProperty

public static String getSystemProperty(String name,
                                       String defaultValue)
A helper method to access a system property, catching any security exceptions

Parameters:
name - the name of the system property required
defaultValue - the default value to use if the property is not available or a security exception prevents access
Returns:
the system property value or the default value if the property is not available or security does not allow its access

name

public static String name(Class type)
Returns the type name of the given type or null if the type variable is null


className

public static String className(Object value)
Returns the type name of the given value


loadClass

public 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

Parameters:
name - the name of the class to load
Returns:
the class or null if it could not be loaded

loadClass

public 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

Parameters:
name - the name of the class to load
loader - the class loader to use after the thread context class loader
Returns:
the class or null if it could not be loaded

invokeMethod

public 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

Parameters:
method - the method to invoke
instance - the object instance (or null for static methods)
parameters - the parameters to the method
Returns:
the result of the method invocation

findMethodsWithAnnotation

public static List<Method> findMethodsWithAnnotation(Class<?> type,
                                                     Class<? extends Annotation> annotationType)
Returns a list of methods which are annotated with the given annotation

Parameters:
type - the type to reflect on
annotationType - the annotation type
Returns:
a list of the methods found

asString

public static String asString(Object[] objects)
Turns the given object arrays into a meaningful string

Parameters:
objects - an array of objects or null
Returns:
a meaningful string


Copyright © 2007 Apache Software Foundation. All Rights Reserved.