Package org.apache.juneau.commons.utils
Class ObjectUtils
java.lang.Object
org.apache.juneau.commons.utils.ObjectUtils
Canonical home for object-level helpers: null/empty checks, equality, comparison,
coalescing, boolean folds, identity/stringify, small numeric helpers, and optionals.
Terse aliases for these methods live in Shorts.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor — this class is meant to be subclassed. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Number>
Tabs(T value) Absolute value across Number subtypes.static booleanallTrue(boolean... values) Boolean AND-fold (vacuously true when empty).static booleananyTrue(boolean... values) Boolean OR-fold (false when empty).static <T> Tcoalesce(T... t) Returns the first non-null value, ornull .static <T> Tcoalesce(T value, T defaultValue) Returns the value if non-null, else the default (coalesce).static intNull-tolerant natural-order compare (0 if types differ / not Comparable).static <T> Optional<T>Optional.empty()shorthand.static booleanString equality with optional case-insensitivity (null -safe; twonull values are equal).static <T> booleanequal(T o1, T o2) Null/array/annotation-aware equality.static <T,U> boolean equal(T o1, U o2, BiPredicate<T, U> test) Null-safe equality via a custom predicate.static booleanequalIgnoreCase(Object o1, Object o2) Case-insensitive equality of two objects' string forms (null -safe; twonull values are equal, onenull is not).static <T> booleanequalsAny(T o1, T... o2) Returnstrue if the first argument equals any of the varargs.static <T extends Comparable<T>>
booleangreaterThan(T o1, T o2) Returnstrue if o1 is greater than o2.static <T extends Comparable<T>>
booleangreaterThanOrEqual(T o1, T o2) Returnstrue if o1 is greater than or equal to o2.static intContent/annotation/array-aware hash.static String"SimpleQualifiedName@identityHashCode" for the object (unwrapping Optionals).static booleanisBetween(int n, int lower, int higher) Inclusive between.static booleanTrue if the object (String/Collection/Map/array/other) is null or empty.static booleanNull-safeBoolean.FALSEcheck.static booleanisNotEmpty(Object value) Inverse ofisEmpty(Object).static <T extends Number>
booleanisNotMinusOne(T value) True if the number is non-null and not -1.static booleanReturnstrue if the object is notnull .static booleanReturnstrue if all specified values arenull (or the array isnull ).static <T> booleanisNull(T value) Returnstrue if the object isnull .static booleanNull-safeBoolean.TRUEcheck.static <T extends Comparable<T>>
booleanlessThan(T o1, T o2) Returnstrue if o1 is less than o2.static <T extends Comparable<T>>
booleanlessThanOrEqual(T o1, T o2) Returnstrue if o1 is less than or equal to o2.static <T,R> R Returnsnull when the value isnull , else the mapper's result; the mapper is never called onnull .static <T extends Comparable<T>>
Tmax(T o1, T o2) Returns the maximum of two comparable values.static <T extends Comparable<T>>
Tmin(T o1, T o2) Returns the minimum of two comparable values.static booleannegate(boolean value) Boolean negation.static <T> booleannotEqual(T o1, T o2) Inverse ofequal(Object,Object).static <T,U> boolean notEqual(T o1, U o2, BiPredicate<T, U> test) Inverse ofequal(Object,Object,BiPredicate).static <T> TnullObject(Class<T> type) Returnsnull typed as the specified class (type-inference helper).static <T> Optional<T>optional(T t) Optional.ofNullable(Object)shorthand.static <T> Toptional.orElse(defaultValue)shorthand.static <T> TrequireNonNull(T value) Asserts non-null and returns the value.static intNull-safe size (0 for null; length/size for String/Collection/Map/array; else 1).static StringNull-safe toString (returnsnull fornull ).static booleanCoerces an object to a boolean (false if null).static ObjectUnwraps a Supplier/Holder/Optional to its inner value.
-
Constructor Details
-
ObjectUtils
protected ObjectUtils()Constructor — this class is meant to be subclassed.
-
-
Method Details
-
isNotNull
Returnstrue if the object is notnull . -
isNull
Returnstrue if the object isnull . -
isNull
Returnstrue if all specified values arenull (or the array isnull ). -
nullObject
Returnsnull typed as the specified class (type-inference helper). -
equal
Null/array/annotation-aware equality. -
equal
String equality with optional case-insensitivity (null -safe; twonull values are equal). -
equal
Null-safe equality via a custom predicate. -
equalsAny
Returnstrue if the first argument equals any of the varargs.
Returnsfalse if the varargs array isnull or empty. -
equalIgnoreCase
Case-insensitive equality of two objects' string forms (null -safe; twonull values are equal, onenull is not). -
notEqual
Inverse ofequal(Object,Object). -
notEqual
Inverse ofequal(Object,Object,BiPredicate). -
compare
Null-tolerant natural-order compare (0 if types differ / not Comparable). -
lessThan
Returnstrue if o1 is less than o2.- Type Parameters:
T- The comparable type.- Parameters:
o1- Object 1. Can benull .o2- Object 2. Can benull .- Returns:
true if o1 is less than o2. Anull value is considered less than any non-null value.
-
lessThanOrEqual
Returnstrue if o1 is less than or equal to o2.- Type Parameters:
T- The comparable type.- Parameters:
o1- Object 1. Can benull .o2- Object 2. Can benull .- Returns:
true if o1 is less than or equal to o2. Anull o1 is considered less than or equal to any value.
-
greaterThan
Returnstrue if o1 is greater than o2.- Type Parameters:
T- The comparable type.- Parameters:
o1- Object 1. Can benull .o2- Object 2. Can benull .- Returns:
true if o1 is greater than o2. Anull o1 is never considered greater than o2; a non-null o1 is considered greater than anull o2.
-
greaterThanOrEqual
Returnstrue if o1 is greater than or equal to o2.- Type Parameters:
T- The comparable type.- Parameters:
o1- Object 1. Can benull .o2- Object 2. Can benull .- Returns:
true if o1 is greater than or equal to o2. A non-null o1 is considered greater than or equal to anull o2; anull o1 is greater than or equal only to anull o2.
-
min
Returns the minimum of two comparable values.- Type Parameters:
T- The comparable type.- Parameters:
o1- Value 1. Can benull .o2- Value 2. Can benull .- Returns:
- The minimum value. If one argument is
null , the other is returned (which may itself benull if both arenull ).
-
max
Returns the maximum of two comparable values.- Type Parameters:
T- The comparable type.- Parameters:
o1- Value 1. Can benull .o2- Value 2. Can benull .- Returns:
- The maximum value. If one argument is
null , the other is returned (which may itself benull if both arenull ).
-
coalesce
Returns the value if non-null, else the default (coalesce). -
coalesce
Returns the first non-null value, ornull . -
mapOrNull
Returnsnull when the value isnull , else the mapper's result; the mapper is never called onnull .- Type Parameters:
T- The value type.R- The result type.- Parameters:
value- The value to map. Can benull .mapper- The mapping function.- Returns:
- The mapped value, or
null ifvalueisnull or the mapper returnsnull .
-
allTrue
Boolean AND-fold (vacuously true when empty). -
anyTrue
Boolean OR-fold (false when empty). -
negate
Boolean negation. -
isTrue
Null-safeBoolean.TRUEcheck. -
isFalse
Null-safeBoolean.FALSEcheck. -
toBoolean
Coerces an object to a boolean (false if null). -
stringify
Null-safe toString (returnsnull fornull ). -
identity
"SimpleQualifiedName@identityHashCode" for the object (unwrapping Optionals).
Returnsnull if the argument isnull (or an empty Optional). -
unwrap
Unwraps a Supplier/Holder/Optional to its inner value.
Returnsnull if the argument isnull or unwraps tonull . -
abs
Absolute value across Number subtypes.
Returnsnull if the argument isnull . -
isBetween
Inclusive between. -
isNotMinusOne
True if the number is non-null and not -1. -
hash
-
isEmpty
True if the object (String/Collection/Map/array/other) is null or empty. -
isNotEmpty
Inverse ofisEmpty(Object). -
optional
Optional.ofNullable(Object)shorthand. -
emptyOptional
Optional.empty()shorthand. -
orElse
optional.orElse(defaultValue)shorthand. -
requireNonNull
Asserts non-null and returns the value. -
size
Null-safe size (0 for null; length/size for String/Collection/Map/array; else 1).
-