public final class ObjectUtil extends Object
| Modifier | Constructor and Description |
|---|---|
private |
ObjectUtil()
Forbid instances by this private constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> Comparator<T> |
createEqualsComparator()
Creates a
Comparator that can be used to compute the
equality of two given Objects. |
static boolean |
equals(Object first,
Object second)
Nullpointer save execution of
Object.equals(Object). |
static Field |
findField(Class<?> classInstance,
String fieldName)
|
static Method |
findMethod(Class<?> classInstance,
String methodName,
Class... parameterClasses)
|
static <T> T |
get(Object obj,
Class<?> classInstance,
String fieldName)
Returns the value from the field.
|
static <T> T |
get(Object obj,
Field field)
Returns the value from the field.
|
static <T> T |
get(Object obj,
String fieldName)
Returns the value from the field.
|
static Class<?> |
getClass(Object obj)
Nullpointer save execution of
Object.getClass(). |
static int |
hashCode(Object obj)
Nullpointer save execution of
Object.hashCode() |
static <T> T |
invoke(Object obj,
Method method,
Object... parameters)
Executes the method on the given
Object. |
static <T> T |
invoke(Object obj,
String methodName,
Object... parameters)
Executes the method on the given
Object. |
static void |
set(Object obj,
Class<?> classInstance,
String fieldName,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
Class<?> classInstance,
String fieldName,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
Class<?> classInstance,
String fieldName,
Object value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
Field field,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
Field field,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
Field field,
Object value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
String fieldName,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
String fieldName,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(Object obj,
String fieldName,
Object value)
Sets the value of the given field on the given
Object. |
static void |
sleep(int time)
Sleeps the current
Thread for the given time. |
static String |
toString(Object obj)
Nullpointer save execution of
Object.toString(). |
static void |
waitForThreads(Thread[] threads)
Waits until the given
Threads have terminated. |
public static <T> T get(Object obj, String fieldName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
T - The value type.obj - The object to read from.fieldName - The name of the field.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static <T> T get(Object obj, Class<?> classInstance, String fieldName) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
T - The value type.obj - The object to read from.classInstance - The class in that the field is declared.fieldName - The name of the field.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static <T> T get(Object obj, Field field) throws IllegalArgumentException, IllegalAccessException
T - The value type.obj - The object to read from.field - The Field to read.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, String fieldName, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Class<?> classInstance, String fieldName, Object value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.classInstance - The class in that the field is declared.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Field field, Object value) throws IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, String fieldName, boolean value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Class<?> classInstance, String fieldName, boolean value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.classInstance - The class in that the field is declared.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Field field, boolean value) throws IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, String fieldName, int value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Class<?> classInstance, String fieldName, int value) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.classInstance - The class in that the field is declared.fieldName - The name of the field.value - The value to write.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static void set(Object obj, Field field, int value) throws IllegalArgumentException, IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.public static Field findField(Class<?> classInstance, String fieldName) throws SecurityException, NoSuchFieldException
classInstance - The Class to search in.fieldName - The name of the field.Field.SecurityException - Occurred Exception.NoSuchFieldException - Occurred Exception.public static <T> T invoke(Object obj, String methodName, Object... parameters) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
Object.T - The return typeobj - The Object to execute on.methodName - parameters - The method parameters.NoSuchMethodException - Occurred Exception.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.InvocationTargetException - Occurred Exception.public static <T> T invoke(Object obj, Method method, Object... parameters) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
Object.T - The return typeobj - The Object to execute on.method - The Method to execute.parameters - The method parameters.IllegalArgumentException - Occurred Exception.IllegalAccessException - Occurred Exception.InvocationTargetException - Occurred Exception.public static Method findMethod(Class<?> classInstance, String methodName, Class... parameterClasses) throws NoSuchMethodException
classInstance - The Class to search in.methodName - The method name to search.parameterClasses - The parameter Classes.Method.NoSuchMethodException - Occurred Exceptionpublic static boolean equals(Object first, Object second)
Object.equals(Object).
The two objects are also equal if both references are nullpublic static String toString(Object obj)
Object.toString().obj - The object to execute to string on.null if the object is null.public static int hashCode(Object obj)
Object.hashCode()obj - The object to get the hashcode from.0 if the object was null.public static <T> Comparator<T> createEqualsComparator()
Comparator that can be used to compute the
equality of two given Objects. They are seen as equal
if equals(Object, Object) tells it. In this case
0 is returned in Comparator.compare(Object, Object).
If they are not equal Comparator.compare(Object, Object) returns
a value different to 0.Comparator.public static Class<?> getClass(Object obj)
Object.getClass().obj - The object to execute get class on.Class or null if the object is null.public static void waitForThreads(Thread[] threads)
Threads have terminated.threads - The Threads to wait for.public static void sleep(int time)
Thread for the given time.time - The time to sleep.