public class ObjectUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
CLASS_METHOD_SEPARATOR
Used to know what is separator between class and method
|
protected static Integer |
ZERO |
protected static Byte |
ZEROB |
protected static Character |
ZEROC |
protected static Double |
ZEROD |
protected static Float |
ZEROF |
protected static Long |
ZEROL |
Modifier and Type | Method and Description |
---|---|
static Object |
call(Object o,
Method m,
String... params)
Call method m with params as String.
|
protected static Object |
choiceArgument(Class<?> clazz,
List args,
boolean nullIfMissing)
Permet de matcher un type d'argument attendu clazz parmi un ensemble
possible de candidat.
|
static <E extends Cloneable> |
clone(E e)
Clone object by introspection because Cloneable interface don't permit
to call clone :(.
|
protected static Object |
convert(String v,
Class<?> clazz) |
static Object |
create(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 <E> E |
deepClone(E e)
Use serialization/deserialization to do deep clone of object
|
static <T> List<Constructor<T>> |
getConstructor(Class<T> clazz,
int paramNumber)
Get all constructors that support paramNumber as parameters numbers.
|
static List<Method> |
getMethod(Class<?> clazz,
String methodName,
boolean ignoreCase)
Get all methods with name given in argument without check parameters.
|
static List<Method> |
getMethod(String name,
boolean ignoreCase)
List method that match name, name must be [package.]
|
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(Object value)
Tests if the given value is null according to default value for
primitive types if nedded.
|
static boolean |
isPrimitive(Class<?> clazz)
Verifie si la classe est de type primitif.
|
static <E> E |
newInstance(Class<E> clazz,
Collection<?> args,
boolean nullIfMissing)
Invoke constructor on clazz to create new instance.
|
static <T> T |
newInstance(Class<T> clazz,
String... params)
Create new instance of clazz, call constructor with params as String.
|
static Object |
newInstance(String constructorWithParams) |
public static final String CLASS_METHOD_SEPARATOR
protected static final Integer ZERO
protected static final Character ZEROC
protected static final Float ZEROF
protected static final Long ZEROL
protected static final Double ZEROD
protected static final Byte ZEROB
public static <E> E newInstance(Class<E> clazz, Collection<?> args, boolean nullIfMissing)
E
- FIXMEclazz
- class of object to instanciateargs
- all possible parameter that constructor can usednullIfMissing
- if no suitable class or object found in args,
use null value (no exception)IllegalArgumentException
- if something is wrong during instanciationprotected static Object choiceArgument(Class<?> clazz, List args, boolean nullIfMissing)
clazz
- le type recherchéargs
- la liste des arguments ou des typesnullIfMissing
- pour retourner nulle si l'argument n'est pas trouvépublic static Object create(String classnameAndProperties) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException
classnameAndProperties
- FIXMEClassNotFoundException
- FIXMEIllegalAccessException
- FIXMEInstantiationException
- FIXMENoSuchMethodException
- FIXMEInvocationTargetException
- FIXMEpublic static <E extends Cloneable> E clone(E e) throws CloneNotSupportedException
if (o instanceof Cloneable) { Object n = ((Cloneable)o).clone(); }
E
- FIXMEe
- object to cloneCloneNotSupportedException
- if some error occur during clonepublic static <E> E deepClone(E e) throws CloneNotSupportedException
E
- FIXMEe
- object to cloneCloneNotSupportedException
- if some error occur during clonepublic static Object call(Object o, Method m, String... params) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException
o
- object where method must be callm
- method to callparams
- parameters for method callIllegalAccessException
- FIXMEIllegalArgumentException
- FIXMEInvocationTargetException
- FIXMEInstantiationException
- FIXMEpublic static List<Method> getMethod(Class<?> clazz, String methodName, boolean ignoreCase)
clazz
- where to search methodmethodName
- method name to searchignoreCase
- if true, ignore difference in method name casepublic static List<Method> getMethod(String name, boolean ignoreCase)
name
- name of the methodignoreCase
- check exact method name if falsepublic static Object newInstance(String constructorWithParams) throws ClassNotFoundException
ClassNotFoundException
public static <T> T newInstance(Class<T> clazz, String... params) throws IllegalArgumentException
T
- type to instanciateclazz
- class to instanciateparams
- parameters for constructor callIllegalArgumentException
- FIXMEpublic static <T> List<Constructor<T>> getConstructor(Class<T> clazz, int paramNumber)
T
- le type de la classe a inspecterclazz
- la classe sur lequel rechercher le constructeurparamNumber
- le nombre de parametre souhaite pour le constructeur,
-1 indique que tous les constructeur sont souhaite.public static boolean isNullValue(Object value)
value
- the value to testtrue
if value is null or default value on a primitivepublic static boolean isNullValue(boolean value)
public static boolean isNullValue(byte value)
public static boolean isNullValue(int value)
public static boolean isNullValue(char value)
public static boolean isNullValue(float value)
public static boolean isNullValue(double value)
public static boolean isPrimitive(Class<?> clazz)
clazz
- nom de la classe a testerCopyright © 2004–2020 CodeLutin. All rights reserved.