|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.esa.beam.util.ArrayUtils
public class ArrayUtils
A utility class providing a set of static functions frequently used when working with basic Java arrays.
All functions have been implemented with extreme caution in order to provide a maximum performance.
| Constructor Summary | |
|---|---|
ArrayUtils()
|
|
| Method Summary | |
|---|---|
static int[] |
addArrays(int[] firstArray,
int[] secondArray)
Gives a new int array who contains both, all ints form all the given arrays. |
static int[] |
addToArray(int[] array,
int value)
Gives a new int array who contains both, all ints form the given array and the given new value. |
static int[] |
createIntArray(int min,
int max)
Creates an int array which containes all values between the given min and the given max. |
static boolean |
equalArrays(double[] array1,
double[] array2,
double eps)
Indicates whether the given arrays arrays are "equal to" each other. |
static boolean |
equalArrays(float[] array1,
float[] array2,
float eps)
Indicates whether the given arrays arrays are "equal to" each other. |
static boolean |
equalArrays(Object[] array1,
Object[] array2)
Indicates whether the given objects arrays are "equal to" each other. |
static int |
getElementIndex(Object element,
Object[] array)
Returns the index of the specified object within the given object array. |
static boolean |
isMemberOf(Object element,
Object[] array)
Checks if the given object is member of the specified array. |
static double[] |
recycleOrCreateArray(double[] array,
int length)
Recycles or creates a new double array of the given length. |
static float[] |
recycleOrCreateArray(float[] array,
int length)
Recycles or creates a new float array of the given length. |
static int[] |
recycleOrCreateArray(int[] array,
int length)
Recycles or creates a new int array of the given length. |
static void |
swapArray(byte[] array)
Swaps the content of the given array of bytes. |
static void |
swapArray(char[] array)
Swaps the content of the given array of chars. |
static void |
swapArray(double[] array)
Swaps the content of the given array of doubles. |
static void |
swapArray(float[] array)
Swaps the content of the given array of floats. |
static void |
swapArray(int[] array)
Swaps the content of the given array of ints. |
static void |
swapArray(long[] array)
Swaps the content of the given array of longs. |
static void |
swapArray(Object array)
Swaps the content of the given array. |
static void |
swapArray(Object[] array)
Swaps the content of the given array of Objects. |
static void |
swapArray(short[] array)
Swaps the content of the given array of shorts. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ArrayUtils()
| Method Detail |
|---|
public static boolean equalArrays(float[] array1,
float[] array2,
float eps)
array1 - the first array, can be nullarray2 - the second array, can also be nulleps - the maximum allowed absolute difference between the elements in both arrays
true if each element in the first object array equals each element in the second, in fact in
the same order; false otherwise.
public static boolean equalArrays(double[] array1,
double[] array2,
double eps)
array1 - the first array, can be nullarray2 - the second array, can also be nulleps - the maximum allowed absolute difference between the elements in both arrays
true if each element in the first object array equals each element in the second, in fact in
the same order; false otherwise.
public static boolean equalArrays(Object[] array1,
Object[] array2)
This method should be used in place of the Object.equals if one ore both arguments can be
null and if an element-by-element comparision shall be performed, since this is what this method
does: for each element pair the ObjectUtils.equalObjects method is called.
array1 - the first object array, can be nullarray2 - the second object array, can also be null
true if each element in the first object array equals each element in the second, in fact in
the same order; false otherwise.
public static int getElementIndex(Object element,
Object[] array)
The method calls the ObjectUtils.equalObjects with the specified element on each of the array's
elements. If both are equal, the index is immediately returned.
element - the element to be searchedarray - the array in which to search the element, must not be null
0 to array.length - 1 if the element was found,
-1 otherwise
public static boolean isMemberOf(Object element,
Object[] array)
The method simply returns getElementIndex(element, array) >= 0.
element - the element to be searchedarray - the array in which to search the element, must not be null
true if the given object is member of the specified arraypublic static void swapArray(byte[] array)
bytes.
array - the array of bytes
IllegalArgumentException - if the given array is nullpublic static void swapArray(char[] array)
chars.
array - the array of chars
IllegalArgumentException - if the given array is nullpublic static void swapArray(short[] array)
shorts.
array - the array of shorts
IllegalArgumentException - if the given array is nullpublic static void swapArray(int[] array)
ints.
array - the array of ints
IllegalArgumentException - if the given array is nullpublic static void swapArray(long[] array)
longs.
array - the array of longs
IllegalArgumentException - if the given array is nullpublic static void swapArray(float[] array)
floats.
array - the array of floats
IllegalArgumentException - if the given array is nullpublic static void swapArray(double[] array)
doubles.
array - the array of doubles
IllegalArgumentException - if the given array is nullpublic static void swapArray(Object[] array)
Objects.
array - the array of Objects
IllegalArgumentException - if the given array is nullpublic static void swapArray(Object array)
array - the array, must be an instance of a native array type such as float[]
IllegalArgumentException - if the given array is null or does not have a native array type
public static int[] recycleOrCreateArray(int[] array,
int length)
int array of the given length.
array - an array which can possibly be recycledlength - the requested array length
public static float[] recycleOrCreateArray(float[] array,
int length)
float array of the given length.
array - an array which can possibly be recycledlength - the requested array length
public static double[] recycleOrCreateArray(double[] array,
int length)
double array of the given length.
array - an array which can possibly be recycledlength - the requested array length
public static int[] addToArray(int[] array,
int value)
throws IllegalArgumentException
int[] with all ints and the new value
IllegalArgumentException - if the given array is null
public static int[] addArrays(int[] firstArray,
int[] secondArray)
throws IllegalArgumentException
int[] with all ints of both arrays
IllegalArgumentException - if any of the given arrays are null
public static int[] createIntArray(int min,
int max)
min - the given minimummax - the given maximum
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||