Package org.aksw.commons.util.obj
Class ObjectUtils
java.lang.Object
org.aksw.commons.util.obj.ObjectUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck if the given object can be assigned to given class.static <T> Tstatic <T> TcastAsOrNull(Class<T> clazz, Object o) static <T> TSupplier-based coalesce function as described in https://benjiweber.co.uk/blog/2013/12/08/null-coalescing-in-java-8/
Example usage:coalesce(obj::getName, obj::getId, () -> obj.hasFoo() ? obj.foo().toString() : "bar")static Class<?>Return an object's class - returns null for a null argumentstatic <T> TmergeNonNull(T a, T b, BinaryOperator<T> merger) If both arguments are non-null then invoke the merger with them and return its result.static <T> TmergeNonNull(T a, T b, BinaryOperator<T> combiner, Supplier<T> nullCase) Similar tomergeNonNull(Object, Object, BinaryOperator)but with an additional supplier if both arguments are null.static <T> TrequireNullOrEqual(T a, T b) A consistency check utility.static StringFor a given object derive a string of the form className@identityHashCodestatic StringtoStringWithIdentityHashCode(Object obj, String nullDefault) For a given object derive a string of the form className@identityHashCodestatic <T> Optional<T>
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
getClass
Return an object's class - returns null for a null argument -
toStringWithIdentityHashCode
For a given object derive a string of the form className@identityHashCode -
toStringWithIdentityHashCode
For a given object derive a string of the form className@identityHashCode -
canCastAs
Check if the given object can be assigned to given class. Also works for primitive types, e.g. int can be assigned to Long. -
tryCastAs
-
castAs
-
castAsOrNull
-
mergeNonNull
If both arguments are non-null then invoke the merger with them and return its result. If both arguments are null return null; Otherwise return the non-null argument. -
mergeNonNull
Similar tomergeNonNull(Object, Object, BinaryOperator)but with an additional supplier if both arguments are null. -
coalesce
Supplier-based coalesce function as described in https://benjiweber.co.uk/blog/2013/12/08/null-coalescing-in-java-8/
Example usage:coalesce(obj::getName, obj::getId, () -> obj.hasFoo() ? obj.foo().toString() : "bar")- Type Parameters:
T-- Parameters:
ts-- Returns:
-
requireNullOrEqual
public static <T> T requireNullOrEqual(T a, T b) A consistency check utility. If both given values are non-null then they must be equal otherwise an exception is raised. Returns the first non-null value (if present) otherwise null.
-