public class ObjectUtils extends Object
Constructor and Description |
---|
ObjectUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
castOrNull(Object o,
Class<T> c)
If the specified object is an instance of the specified class, casts it to that type.
|
static int |
compare(int i1,
int i2)
Compare two integers numerically.
|
static int |
compare(Object o1,
Object o2)
Compares two objects for equality.
|
static boolean |
eq(Object o1,
Object o2)
Tests two objects for equality, gracefully handling nulls.
|
static <T,U> boolean |
eq(T o1,
U o2,
BiPredicate<T,U> test)
Tests two objects for equality, gracefully handling nulls.
|
static <T> T |
firstNonEmpty(T... o)
Returns the first non-empty value in the list of objects.
|
static <T> T |
firstNonNull(T... t)
Returns the first non-null value in the specified array
|
static int |
firstNonZero(int... ints)
Returns the first non-zero value in the list of ints.
|
static Enum<?>[] |
getEnumConstants(Class<?> c)
Returns the enum names for the specified enum class.
|
static boolean |
isEmpty(Object o)
Returns
|
static boolean |
isNotEmpty(Object o)
Returns
|
static boolean |
ne(Object o1,
Object o2)
Tests two objects for equality, gracefully handling nulls.
|
static <T,U> boolean |
ne(T o1,
U o2,
BiPredicate<T,U> test)
Tests two objects for inequality, gracefully handling nulls.
|
static Object |
unwrap(Object o)
|
public ObjectUtils()
public static Enum<?>[] getEnumConstants(Class<?> c)
c
- The enum class.public static <T> T castOrNull(Object o, Class<T> c)
o
- The object to cast.c
- The class to cast to.public static int firstNonZero(int... ints)
ints
- The ints to check.@SafeVarargs public static <T> T firstNonEmpty(T... o)
o
- The objects to check.isEmpty(Object)
returns public static int compare(Object o1, Object o2)
Nulls are always considered less-than unless both are null.
o1
- Object 1.o2
- Object 2.Comparable
interface.public static final int compare(int i1, int i2)
i1
- Integer #1i2
- Integer #2public static <T,U> boolean eq(T o1, U o2, BiPredicate<T,U> test)
T
- Object 1 type.U
- Object 2 type.o1
- Object 1.o2
- Object 2.test
- The test to use for equality.public static boolean eq(Object o1, Object o2)
o1
- Object 1.o2
- Object 2.Object.equals(Object)
method.public static <T,U> boolean ne(T o1, U o2, BiPredicate<T,U> test)
T
- Object 1 type.U
- Object 2 type.o1
- Object 1.o2
- Object 2.test
- The test to use for equality.public static boolean ne(Object o1, Object o2)
o1
- Object 1.o2
- Object 2.Object.equals(Object)
method.public static Object unwrap(Object o)
Supplier
or Mutable
, returns the inner value, otherwise the same value.o
- The object to unwrap.public static boolean isEmpty(Object o)
Return
Object.toString()
.
o
- The object to test.public static boolean isNotEmpty(Object o)
Return
Object.toString()
.
o
- The object to test.@SafeVarargs public static <T> T firstNonNull(T... t)
t
- The values to check.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.