org.nuiton.util
Class ObjectUtil

java.lang.Object
  extended by org.nuiton.util.ObjectUtil

public class ObjectUtil
extends java.lang.Object


Field Summary
protected static java.lang.Integer ZERO
           
protected static java.lang.Byte ZEROB
           
protected static java.lang.Character ZEROC
           
protected static java.lang.Double ZEROD
           
protected static java.lang.Float ZEROF
           
protected static java.lang.Long ZEROL
           
 
Method Summary
static java.lang.Object call(java.lang.Object o, java.lang.reflect.Method m, java.lang.String... params)
          Call method m with params as String.
protected static java.lang.Object convert(java.lang.String v, java.lang.Class<?> clazz)
           
static java.lang.Object create(java.lang.String classnameAndProperties)
          Create new object from string like org.nuiton.Toto(name=machine, int=10) where machine and int is properties on org.nuiton.Toto object.
static
<T> java.util.List<java.lang.reflect.Constructor<T>>
getConstructor(java.lang.Class<T> clazz, int paramNumber)
          Get all constructors that support paramNumber as parameters numbers.
static java.util.List<java.lang.reflect.Method> getMethod(java.lang.Class<?> clazz, java.lang.String methodName, boolean ignoreCase)
          Get all methods with name given in argument without check parameters
static java.lang.Object getNullValue(java.lang.Class<?> type)
          Obtains the null value for the given type (works too with primitive types).
static boolean isNullValue(boolean value)
           
static boolean isNullValue(byte value)
           
static boolean isNullValue(char value)
           
static boolean isNullValue(double value)
           
static boolean isNullValue(float value)
           
static boolean isNullValue(int value)
           
static boolean isNullValue(java.lang.Object value)
          Tests if the given value is null according to default value for primitive types if nedded.
static
<T> T
newInstance(java.lang.Class<T> clazz, java.lang.String... params)
          Create new instance of clazz, call constructor with params as String.
static java.lang.Object newInstance(java.lang.String constructorWithParams)
           
static java.lang.Object toObject(boolean b)
          Method toObject transform a boolean to a Boolean object
static java.lang.Object toObject(byte b)
          Method toObject transform a byte to a Byte Object
static java.lang.Object toObject(char c)
          Method toObject transform a char to a Character Object
static java.lang.Object toObject(double d)
          Method toObject transform a double to a Double object
static java.lang.Object toObject(float f)
          Method toObject transform a float to a Float Object
static java.lang.Object toObject(int i)
          Method toObject transform an int to an Integer object
static java.lang.Object toObject(long l)
          Method toObject transform a long to a Long object
static java.lang.Object toObject(java.lang.Object o)
          Method toObject
static java.lang.Object toObject(short s)
          Method toObject transform a short to a Short object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

protected static final java.lang.Integer ZERO

ZEROC

protected static final java.lang.Character ZEROC

ZEROF

protected static final java.lang.Float ZEROF

ZEROL

protected static final java.lang.Long ZEROL

ZEROD

protected static final java.lang.Double ZEROD

ZEROB

protected static final java.lang.Byte ZEROB
Method Detail

create

public static java.lang.Object create(java.lang.String classnameAndProperties)
                               throws java.lang.ClassNotFoundException,
                                      java.lang.InstantiationException,
                                      java.lang.IllegalAccessException,
                                      java.lang.reflect.InvocationTargetException,
                                      java.lang.NoSuchMethodException
Create new object from string like org.nuiton.Toto(name=machine, int=10) where machine and int is properties on org.nuiton.Toto object. Conversion between 10 in string and 10 as integer as automaticaly done For String property you can use ex:
  • name="my string with , in string"
  • name='my string with , in string'

    Parameters:
    classnameAndProperties -
    Returns:
    the instanciated object
    Throws:
    java.lang.ClassNotFoundException
    java.lang.IllegalAccessException
    java.lang.InstantiationException
    java.lang.NoSuchMethodException
    java.lang.reflect.InvocationTargetException

  • convert

    protected static java.lang.Object convert(java.lang.String v,
                                              java.lang.Class<?> clazz)

    call

    public static java.lang.Object call(java.lang.Object o,
                                        java.lang.reflect.Method m,
                                        java.lang.String... params)
                                 throws java.lang.IllegalAccessException,
                                        java.lang.IllegalArgumentException,
                                        java.lang.reflect.InvocationTargetException,
                                        java.lang.InstantiationException
    Call method m with params as String. Each param is converted to required type for method with beanutils converter

    Parameters:
    o - object where method must be call
    m - method to call
    params - parameters for method call
    Returns:
    returned method's value
    Throws:
    java.lang.IllegalAccessException
    java.lang.IllegalArgumentException
    java.lang.reflect.InvocationTargetException
    java.lang.InstantiationException

    getMethod

    public static java.util.List<java.lang.reflect.Method> getMethod(java.lang.Class<?> clazz,
                                                                     java.lang.String methodName,
                                                                     boolean ignoreCase)
    Get all methods with name given in argument without check parameters

    Parameters:
    clazz -
    methodName - method name to search
    ignoreCase - if true, ignore difference in method name case
    Returns:
    list of detected methods

    newInstance

    public static java.lang.Object newInstance(java.lang.String constructorWithParams)
                                        throws java.lang.ClassNotFoundException
    Throws:
    java.lang.ClassNotFoundException

    newInstance

    public static <T> T newInstance(java.lang.Class<T> clazz,
                                    java.lang.String... params)
                         throws java.lang.IllegalArgumentException
    Create new instance of clazz, call constructor with params as String. Each param is converted to required type for constructor with beanutils converter, first constructor that permit instanciation is used

    Type Parameters:
    T - type to instanciate
    Parameters:
    clazz - class to instanciate
    params - parameters for constructor call
    Returns:
    new instance of clazz
    Throws:
    java.lang.IllegalArgumentException

    getConstructor

    public static <T> java.util.List<java.lang.reflect.Constructor<T>> getConstructor(java.lang.Class<T> clazz,
                                                                                      int paramNumber)
    Get all constructors that support paramNumber as parameters numbers. Varargs is supported

    Type Parameters:
    T - le type de la classe a inspecter
    Parameters:
    clazz - la classe sur lequel rechercher le constructeur
    paramNumber - le nombre de parametre souhaite pour le constructeur, -1 indique que tous les constructeur sont souhaite.
    Returns:
    list of constructors

    toObject

    public static java.lang.Object toObject(java.lang.Object o)
    Method toObject

    Parameters:
    o - Object to transform
    Returns:
    the same object

    toObject

    public static java.lang.Object toObject(char c)
    Method toObject transform a char to a Character Object

    Parameters:
    c - the char to transform
    Returns:
    the Charactere object corresponding

    toObject

    public static java.lang.Object toObject(byte b)
    Method toObject transform a byte to a Byte Object

    Parameters:
    b - the byte to transform
    Returns:
    the byte object corresponding

    toObject

    public static java.lang.Object toObject(short s)
    Method toObject transform a short to a Short object

    Parameters:
    s - the short to transform
    Returns:
    the Short object corresponding

    toObject

    public static java.lang.Object toObject(int i)
    Method toObject transform an int to an Integer object

    Parameters:
    i - the int to transform
    Returns:
    the Integer Object corresponding

    toObject

    public static java.lang.Object toObject(long l)
    Method toObject transform a long to a Long object

    Parameters:
    l - the long to transform
    Returns:
    the Long Object corresponding

    toObject

    public static java.lang.Object toObject(float f)
    Method toObject transform a float to a Float Object

    Parameters:
    f - the float to transform
    Returns:
    the Float Object corresponding

    toObject

    public static java.lang.Object toObject(double d)
    Method toObject transform a double to a Double object

    Parameters:
    d - the double to transform
    Returns:
    the Double object corresponding

    toObject

    public static java.lang.Object toObject(boolean b)
    Method toObject transform a boolean to a Boolean object

    Parameters:
    b - the boolean to transform
    Returns:
    the Boolean object corresponding

    getNullValue

    public static java.lang.Object getNullValue(java.lang.Class<?> type)
    Obtains the null value for the given type (works too with primitive types).

    Parameters:
    type - the type to test
    Returns:
    the null value or default value for primitive types
    Since:
    1.1.5

    isNullValue

    public static boolean isNullValue(java.lang.Object value)
    Tests if the given value is null according to default value for primitive types if nedded.

    Parameters:
    value - the value to test
    Returns:
    true if value is null or default value on a primitive
    Since:
    1.1.5

    isNullValue

    public static boolean isNullValue(boolean value)

    isNullValue

    public static boolean isNullValue(byte value)

    isNullValue

    public static boolean isNullValue(int value)

    isNullValue

    public static boolean isNullValue(char value)

    isNullValue

    public static boolean isNullValue(float value)

    isNullValue

    public static boolean isNullValue(double value)


    Copyright © 2004-2010 CodeLutin. All Rights Reserved.