|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ehcache.impl.internal.classes.commonslang.ArrayUtils
public class ArrayUtils
Operations on arrays, primitive arrays (like int[]
) and
primitive wrapper arrays (like Integer[]
).
This class tries to handle null
input gracefully.
An exception will not be thrown for a null
array input. However, an Object array that contains a null
element may throw an exception. Each method documents its behaviour.
#ThreadSafe#
Field Summary | |
---|---|
static java.lang.Class<?>[] |
EMPTY_CLASS_ARRAY
An empty immutable Class array. |
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY
An empty immutable Object array. |
Constructor Summary | |
---|---|
ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming. |
Method Summary | |
---|---|
static int |
getLength(java.lang.Object array)
Returns the length of the specified array. |
static boolean |
isEmpty(java.lang.Object[] array)
Checks if an array of Objects is empty or null . |
static boolean |
isSameLength(java.lang.Object[] array1,
java.lang.Object[] array2)
Checks whether two arrays are the same length, treating null arrays as length 0 . |
static java.lang.Class<?>[] |
nullToEmpty(java.lang.Class<?>[] array)
Defensive programming technique to change a null
reference to an empty one. |
static java.lang.Object[] |
nullToEmpty(java.lang.Object[] array)
Defensive programming technique to change a null
reference to an empty one. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
Object
array.
public static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
Class
array.
Constructor Detail |
---|
public ArrayUtils()
ArrayUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as ArrayUtils.clone(new int[] {2})
.
This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail |
---|
public static java.lang.Object[] nullToEmpty(java.lang.Object[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with
the empty public static
references in this class.
array
- the array to check for null
or empty
public static
empty array if null
or empty inputpublic static java.lang.Class<?>[] nullToEmpty(java.lang.Class<?>[] array)
Defensive programming technique to change a null
reference to an empty one.
This method returns an empty array for a null
input array.
As a memory optimizing technique an empty array passed in will be overridden with
the empty public static
references in this class.
array
- the array to check for null
or empty
public static
empty array if null
or empty inputpublic static boolean isSameLength(java.lang.Object[] array1, java.lang.Object[] array2)
Checks whether two arrays are the same length, treating
null
arrays as length 0
.
Any multi-dimensional aspects of the arrays are ignored.
array1
- the first array, may be null
array2
- the second array, may be null
true
if length of arrays matches, treating
null
as an empty arraypublic static int getLength(java.lang.Object array)
Returns the length of the specified array.
This method can deal with Object
arrays and with primitive arrays.
If the input array is null
, 0
is returned.
ArrayUtils.getLength(null) = 0 ArrayUtils.getLength([]) = 0 ArrayUtils.getLength([null]) = 1 ArrayUtils.getLength([true, false]) = 2 ArrayUtils.getLength([1, 2, 3]) = 3 ArrayUtils.getLength(["a", "b", "c"]) = 3
array
- the array to retrieve the length from, may be null
0
if the array is null
java.lang.IllegalArgumentException
- if the object argument is not an array.public static boolean isEmpty(java.lang.Object[] array)
Checks if an array of Objects is empty or null
.
array
- the array to test
true
if the array is empty or null
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |