public class ArrayUtils extends Object
All functions have been implemented with extreme caution in order to provide a maximum performance.
| Constructor and Description |
|---|
ArrayUtils() |
| Modifier and Type | Method and Description |
|---|---|
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. |
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 arraystrue 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 arraystrue 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 nulltrue 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 null0 to array.length - 1 if the element was found,
-1 otherwisepublic 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 nulltrue if the given object is member of the specified arraypublic static void swapArray(byte[] array)
bytes.array - the array of bytesIllegalArgumentException - if the given array is nullpublic static void swapArray(char[] array)
chars.array - the array of charsIllegalArgumentException - if the given array is nullpublic static void swapArray(short[] array)
shorts.array - the array of shortsIllegalArgumentException - if the given array is nullpublic static void swapArray(int[] array)
ints.array - the array of intsIllegalArgumentException - if the given array is nullpublic static void swapArray(long[] array)
longs.array - the array of longsIllegalArgumentException - if the given array is nullpublic static void swapArray(float[] array)
floats.array - the array of floatsIllegalArgumentException - if the given array is nullpublic static void swapArray(double[] array)
doubles.array - the array of doublesIllegalArgumentException - if the given array is nullpublic static void swapArray(Object[] array)
Objects.array - the array of ObjectsIllegalArgumentException - 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 typepublic static int[] recycleOrCreateArray(int[] array,
int length)
int array of the given length.array - an array which can possibly be recycledlength - the requested array lengthpublic static float[] recycleOrCreateArray(float[] array,
int length)
float array of the given length.array - an array which can possibly be recycledlength - the requested array lengthpublic static double[] recycleOrCreateArray(double[] array,
int length)
double array of the given length.array - an array which can possibly be recycledlength - the requested array lengthpublic static int[] addToArray(int[] array,
int value)
throws IllegalArgumentException
int[] with all ints and the new valueIllegalArgumentException - if the given array is nullpublic static int[] addArrays(int[] firstArray,
int[] secondArray)
throws IllegalArgumentException
int[] with all ints of both arraysIllegalArgumentException - if any of the given arrays are nullpublic static int[] createIntArray(int min,
int max)
min - the given minimummax - the given maximumCopyright © 2014–2017 European Space Agency (ESA). All rights reserved.