Package org.apache.juneau.internal
Class ObjectUtils
java.lang.Object
org.apache.juneau.internal.ObjectUtils
Various generic object utility methods.
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TCasts an object to a specific type if it's an instance of that type.static <T> TcastOrNull(Object o, Class<T> c) If the specified object is an instance of the specified class, casts it to that type.static final intcompare(int i1, int i2) Compare two integers numerically.static intCompares two objects for equality.static <T> booleaneq(T[] o1, T[] o2) Tests two arrays for equality, gracefully handling nulls.static <T> booleaneq(T o1, T o2) Tests two objects for equality, gracefully handling nulls and arrays.static <T,U> boolean eq(T o1, U o2, BiPredicate<T, U> test) Tests two objects for equality, gracefully handling nulls.static <T> TfirstNonNull(T... t) Returns the first non-null value in the specified arraystatic StringConverts the specified object into an identifiable string of the form "Class[identityHashCode]"static booleanReturnstrue if the specified object is empty.static booleanisNotEmpty(Object value) Returnstrue if the specified object is notnull and not empty.static <T extends Number>
booleanisNotMinusOne(T value) Returnstrue if the specified number is notnull and not-1 .static <T> booleanisNotNull(T value) Returnstrue if the specified object is notnull .static booleanReturnstrue if the specified boolean is notnull and istrue .static booleanTests two objects for equality, gracefully handling nulls and arrays.static <T,U> boolean ne(T o1, U o2, BiPredicate<T, U> test) Tests two objects for inequality, gracefully handling nulls.static JsonMapSearches for allproperties() methods on the specified object and creates a combine map of them.static Object
-
Constructor Details
-
ObjectUtils
public ObjectUtils()
-
-
Method Details
-
castOrNull
If the specified object is an instance of the specified class, casts it to that type.- Type Parameters:
T- The class to cast to.- Parameters:
o- The object to cast.c- The class to cast to.- Returns:
- The cast object, or
null if the object wasn't an instance of the specified class.
-
compare
Compares two objects for equality.Nulls are always considered less-than unless both are null.
- Parameters:
o1- Object 1.o2- Object 2.- Returns:
-1 ,0 , or1 ifo1 is less-than, equal, or greater-thano2 .0 if objects are not of the same type or do not implement theComparableinterface.
-
compare
Compare two integers numerically.- Parameters:
i1- Integer #1i2- Integer #2- Returns:
- The value
0 if Integer #1 is equal to Integer #2; a value less than0 if Integer #1 numerically less than Integer #2; and a value greater than0 if Integer #1 is numerically greater than Integer #2 (signed comparison).
-
eq
Tests two objects for equality, gracefully handling nulls.- Type Parameters:
T- Object 1 type.U- Object 2 type.- Parameters:
o1- Object 1.o2- Object 2.test- The test to use for equality.- Returns:
true if both objects are equal based on the test.
-
eq
Tests two objects for equality, gracefully handling nulls and arrays.- Type Parameters:
T- The value types.- Parameters:
o1- Object 1.o2- Object 2.- Returns:
true if both objects are equal based on theObject.equals(Object)method.
-
eq
Tests two arrays for equality, gracefully handling nulls.- Type Parameters:
T- The value types.- Parameters:
o1- Array 1.o2- Array 2.- Returns:
true if both arrays are equal based on theObject.equals(Object)method on each element.
-
ne
Tests two objects for inequality, gracefully handling nulls.- Type Parameters:
T- Object 1 type.U- Object 2 type.- Parameters:
o1- Object 1.o2- Object 2.test- The test to use for equality.- Returns:
false if both objects are equal based on the test.
-
ne
Tests two objects for equality, gracefully handling nulls and arrays.- Parameters:
o1- Object 1.o2- Object 2.- Returns:
false if both objects are equal based on theObject.equals(Object)method.
-
unwrap
- Parameters:
o- The object to unwrap.- Returns:
- The unwrapped object.
-
isEmpty
Returnstrue if the specified object is empty.Return
true if the value is any of the following:null - An empty Collection
- An empty Map
- An empty array
- An empty CharSequence
- An empty String when serialized to a string using
Object.toString().
- Parameters:
o- The object to test.- Returns:
true if the specified object is empty.
-
firstNonNull
Returns the first non-null value in the specified array- Type Parameters:
T- The value types.- Parameters:
t- The values to check.- Returns:
- The first non-null value, or
null if the array is null or empty or contains onlynull values.
-
cast
Casts an object to a specific type if it's an instance of that type.- Type Parameters:
T- The type to cast to.- Parameters:
c- The type to cast to.o- The object to cast to.- Returns:
- The cast object, or
null if the object wasn't the specified type.
-
identity
Converts the specified object into an identifiable string of the form "Class[identityHashCode]"- Parameters:
o- The object to convert to a string.- Returns:
- An identity string.
-
toPropertyMap
Searches for allproperties() methods on the specified object and creates a combine map of them.- Parameters:
o- The object to return a property map of.- Returns:
- A new property map.
-
isNotNull
Returnstrue if the specified object is notnull .- Type Parameters:
T- The value type.- Parameters:
value- The value being checked.- Returns:
true if the specified object is notnull .
-
isTrue
Returnstrue if the specified boolean is notnull and istrue .- Parameters:
value- The value being checked.- Returns:
true if the specified boolean is notnull and istrue .
-
isNotMinusOne
Returnstrue if the specified number is notnull and not-1 .- Type Parameters:
T- The value types.- Parameters:
value- The value being checked.- Returns:
true if the specified number is notnull and not-1 .
-
isNotEmpty
Returnstrue if the specified object is notnull and not empty. Works on any of the following data types: String, CharSequence, Collection, Map, array. All other types are stringified and then checked as a String.- Parameters:
value- The value being checked.- Returns:
true if the specified object is notnull and not empty.
-