Package org.apache.bval.util
Class ObjectUtils
- java.lang.Object
-
- org.apache.bval.util.ObjectUtils
-
public final class ObjectUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Annotation[]
EMPTY_ANNOTATION_ARRAY
static Class<?>[]
EMPTY_CLASS_ARRAY
static String[]
EMPTY_STRING_ARRAY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T[]
arrayAdd(T[] array, T objectToAdd)
static boolean
arrayContains(Object[] array, Object objectToFind)
Checks if the object is in the given array.static <T> T
defaultIfNull(T object, T defaultValue)
Returns a default value if the object passed isnull
.static int
hashCode(Object o)
Get hashcode ofo
, taking into account array values.static int
indexOf(Object[] array, Object objectToFind)
static boolean
isEmptyArray(Object array)
-
-
-
Field Detail
-
EMPTY_CLASS_ARRAY
public static final Class<?>[] EMPTY_CLASS_ARRAY
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
-
EMPTY_ANNOTATION_ARRAY
public static final Annotation[] EMPTY_ANNOTATION_ARRAY
-
-
Method Detail
-
defaultIfNull
public static <T> T defaultIfNull(T object, T defaultValue)
Returns a default value if the object passed is
null
.ObjectUtils.defaultIfNull(null, null) = null ObjectUtils.defaultIfNull(null, "") = "" ObjectUtils.defaultIfNull(null, "zz") = "zz" ObjectUtils.defaultIfNull("abc", *) = "abc" ObjectUtils.defaultIfNull(Boolean.TRUE, *) = Boolean.TRUE
- Type Parameters:
T
- the type of the object- Parameters:
object
- theObject
to test, may benull
defaultValue
- the default value to return, may benull
- Returns:
object
if it is notnull
, defaultValue otherwise
-
isEmptyArray
public static boolean isEmptyArray(Object array)
-
arrayContains
public static boolean arrayContains(Object[] array, Object objectToFind)
Checks if the object is in the given array.
The method returns
false
if anull
array is passed in.- Parameters:
array
- the array to search throughobjectToFind
- the object to find- Returns:
true
if the array contains the object
-
arrayAdd
public static <T> T[] arrayAdd(T[] array, T objectToAdd)
-
hashCode
public static int hashCode(Object o)
Get hashcode ofo
, taking into account array values.- Parameters:
o
-- Returns:
int
- See Also:
Arrays
,Objects.hashCode(Object)
-
-