public class ObjectHelper
extends java.lang.Object
| Constructor and Description |
|---|
ObjectHelper() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areAllNulls(java.lang.Object... elements)
Returns true if all elements are null.
|
static <T> T |
coalesce(T... values)
Returns the first non-null value
|
static <T extends java.lang.Comparable<T>> |
compare(T o1,
T o2)
Compares 2
Comparables, handling nulls |
static <S extends Bean,T extends Bean> |
copyProperties(S source,
T target)
It copies from source to target (apply a bean over another bean) traversing all source's properties.
If a property is not found in the target bean or has a different type then it's ignored. |
static <T> T |
defaultValue(T object,
T whenNull)
Returns the second parameter when the first is null
|
static boolean |
equalsOrBothNull(java.lang.Object first,
java.lang.Object second)
Returns true when either both objects are non null and equals or both null
|
static <T extends Bean> |
getHierarchyPath(T bean,
Property<T,T> parentProperty)
Returns a list with the path from the hierarchy root up to the given object, having the given parent property to
resolve an object's parent.
|
static <T extends Bean> |
getLevel(T bean,
Property<T,T> parentProperty)
Returns the level of a given hierarchical bean.
|
static int |
hashCode(java.lang.Object object)
Returns the hashCode of the given object, handling nulls (-1 if null)
|
static <T> T |
ifType(java.lang.Object object,
java.lang.Class<T> expectedType)
Returns the argument if it is an instance of the given class, otherwise null
|
static boolean |
isEmpty(java.lang.Object object)
Returns whether the given object is null or an empty string, collection, map or array
|
static <T extends Bean> |
isEmpty(T bean,
Property<?,? super T>... properties) |
static boolean |
isNotEmpty(java.lang.Object object)
Negated value of
isEmpty(Object) |
static boolean |
isNotOneOf(java.lang.Object element,
java.lang.Object... objects)
Returns true if element is not one of the given objects.
|
static boolean |
isOneOf(java.lang.Object element,
java.lang.Object... objects)
Returns true if element is one of the objects
If element or objects are null it returns false;
|
static void |
requireOneOf(java.lang.Object element,
java.lang.Object... objects) |
static void |
requireOneOf(java.util.function.Supplier<java.lang.String> errorMessageSupplier,
java.lang.Object element,
java.lang.Object... objects)
Checks if element is one of the objects
|
public static boolean areAllNulls(java.lang.Object... elements)
@SafeVarargs public static <T> T coalesce(T... values)
public static <T extends java.lang.Comparable<T>> int compare(T o1,
T o2)
Comparables, handling nullspublic static <S extends Bean,T extends Bean> void copyProperties(S source, T target)
java.lang.IllegalArgumentException - if source, target or both are null.public static <T> T defaultValue(T object,
T whenNull)
public static boolean equalsOrBothNull(java.lang.Object first,
java.lang.Object second)
public static <T extends Bean> java.util.List<T> getHierarchyPath(T bean, Property<T,T> parentProperty)
public static <T extends Bean> int getLevel(T bean, Property<T,T> parentProperty)
public static int hashCode(java.lang.Object object)
public static <T> T ifType(java.lang.Object object,
java.lang.Class<T> expectedType)
public static boolean isEmpty(java.lang.Object object)
@SafeVarargs public static <T extends Bean> boolean isEmpty(T bean, Property<?,? super T>... properties)
properties - list of Properties to be checked for empty/nullisEmpty(Object)).public static boolean isNotEmpty(java.lang.Object object)
isEmpty(Object)public static boolean isNotOneOf(java.lang.Object element,
java.lang.Object... objects)
public static boolean isOneOf(java.lang.Object element,
java.lang.Object... objects)
public static void requireOneOf(java.lang.Object element,
java.lang.Object... objects)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic static void requireOneOf(java.util.function.Supplier<java.lang.String> errorMessageSupplier,
java.lang.Object element,
java.lang.Object... objects)
throws java.lang.IllegalArgumentException
errorMessageSupplier - (Optional) Supplier to get the message in case of errorjava.lang.IllegalArgumentException - if element is not one of the given objects.