public final class ObjectUtil
extends java.lang.Object
| Modifier | Constructor and Description |
|---|---|
private |
ObjectUtil()
Forbid instances by this private constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.Comparator<T> |
createEqualsComparator()
Creates a
Comparator that can be used to compute the
equality of two given Objects. |
static boolean |
equals(java.lang.Object first,
java.lang.Object second)
Nullpointer save execution of
Object.equals(Object). |
static java.lang.reflect.Field |
findField(java.lang.Class<?> classInstance,
java.lang.String fieldName)
Finds the
Field with the name inside the given Class. |
static java.lang.reflect.Method |
findMethod(java.lang.Class<?> classInstance,
java.lang.String methodName,
java.lang.Class... parameterClasses)
Finds the
Method in the given Class. |
static <T> T |
get(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName)
Returns the value from the field.
|
static <T> T |
get(java.lang.Object obj,
java.lang.reflect.Field field)
Returns the value from the field.
|
static <T> T |
get(java.lang.Object obj,
java.lang.String fieldName)
Returns the value from the field.
|
static java.lang.Class<?> |
getClass(java.lang.Object obj)
Nullpointer save execution of
Object.getClass(). |
static int |
hashCode(java.lang.Object obj)
Nullpointer save execution of
Object.hashCode() |
static <T> T |
invoke(java.lang.Object obj,
java.lang.reflect.Method method,
java.lang.Object... parameters)
Executes the method on the given
Object. |
static <T> T |
invoke(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object... parameters)
Executes the method on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
java.lang.Object value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.reflect.Field field,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.reflect.Field field,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.reflect.Field field,
java.lang.Object value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.String fieldName,
boolean value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.String fieldName,
int value)
Sets the value of the given field on the given
Object. |
static void |
set(java.lang.Object obj,
java.lang.String fieldName,
java.lang.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 java.lang.String |
toString(java.lang.Object obj)
Nullpointer save execution of
Object.toString(). |
static void |
waitForThreads(java.lang.Thread[] threads)
Waits until the given
Threads have terminated. |
public static <T> T get(java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
T - The value type.obj - The object to read from.fieldName - The name of the field.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static <T> T get(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.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.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static <T> T get(java.lang.Object obj,
java.lang.reflect.Field field)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
T - The value type.obj - The object to read from.field - The Field to read.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.String fieldName,
java.lang.Object value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
java.lang.Object value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.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.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.reflect.Field field,
java.lang.Object value)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.String fieldName,
boolean value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
boolean value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.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.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.reflect.Field field,
boolean value)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.String fieldName,
int value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.fieldName - The name of the field.value - The value to write.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.Class<?> classInstance,
java.lang.String fieldName,
int value)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException,
java.lang.IllegalArgumentException,
java.lang.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.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static void set(java.lang.Object obj,
java.lang.reflect.Field field,
int value)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException
Object.obj - The object to write to.field - The Field to write to.value - The value to write.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.public static java.lang.reflect.Field findField(java.lang.Class<?> classInstance,
java.lang.String fieldName)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException
Field with the name inside the given Class.classInstance - The Class to search in.fieldName - The name of the field.Field.java.lang.SecurityException - Occurred Exception.java.lang.NoSuchFieldException - Occurred Exception.public static <T> T invoke(java.lang.Object obj,
java.lang.String methodName,
java.lang.Object... parameters)
throws java.lang.NoSuchMethodException,
java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
Object.T - The return typeobj - The Object to execute on.methodName - parameters - The method parameters.java.lang.NoSuchMethodException - Occurred Exception.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.java.lang.reflect.InvocationTargetException - Occurred Exception.public static <T> T invoke(java.lang.Object obj,
java.lang.reflect.Method method,
java.lang.Object... parameters)
throws java.lang.IllegalArgumentException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
Object.T - The return typeobj - The Object to execute on.method - The Method to execute.parameters - The method parameters.java.lang.IllegalArgumentException - Occurred Exception.java.lang.IllegalAccessException - Occurred Exception.java.lang.reflect.InvocationTargetException - Occurred Exception.public static java.lang.reflect.Method findMethod(java.lang.Class<?> classInstance,
java.lang.String methodName,
java.lang.Class... parameterClasses)
throws java.lang.NoSuchMethodException
Method in the given Class.classInstance - The Class to search in.methodName - The method name to search.parameterClasses - The parameter Classes.Method.java.lang.NoSuchMethodException - Occurred Exceptionpublic static boolean equals(java.lang.Object first,
java.lang.Object second)
Object.equals(Object).
The two objects are also equal if both references are nullfirst - The first Object.second - The second Object.true objects are equal or both null, false otherwisepublic static java.lang.String toString(java.lang.Object obj)
Object.toString().obj - The object to execute to string on.null if the object is null.public static int hashCode(java.lang.Object obj)
Object.hashCode()obj - The object to get the hashcode from.0 if the object was null.public static <T> java.util.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 java.lang.Class<?> getClass(java.lang.Object obj)
Object.getClass().obj - The object to execute get class on.Class or null if the object is null.public static void waitForThreads(java.lang.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.