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
byte s. |
static void |
swapArray(char[] array)
Swaps the content of the given array of
char s. |
static void |
swapArray(double[] array)
Swaps the content of the given array of
double s. |
static void |
swapArray(float[] array)
Swaps the content of the given array of
float s. |
static void |
swapArray(int[] array)
Swaps the content of the given array of
int s. |
static void |
swapArray(long[] array)
Swaps the content of the given array of
long s. |
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
Object s. |
static void |
swapArray(short[] array)
Swaps the content of the given array of
short s. |
public static boolean equalArrays(float[] array1, float[] array2, float eps)
array1
- the first array, can be null
array2
- the second array, can also be null
eps
- 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 null
array2
- the second array, can also be null
eps
- 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 null
array2
- 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
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 null
true
if the given object is member of the specified arraypublic static void swapArray(byte[] array)
byte
s.array
- the array of byte
sIllegalArgumentException
- if the given array is null
public static void swapArray(char[] array)
char
s.array
- the array of char
sIllegalArgumentException
- if the given array is null
public static void swapArray(short[] array)
short
s.array
- the array of short
sIllegalArgumentException
- if the given array is null
public static void swapArray(int[] array)
int
s.array
- the array of int
sIllegalArgumentException
- if the given array is null
public static void swapArray(long[] array)
long
s.array
- the array of long
sIllegalArgumentException
- if the given array is null
public static void swapArray(float[] array)
float
s.array
- the array of float
sIllegalArgumentException
- if the given array is null
public static void swapArray(double[] array)
double
s.array
- the array of double
sIllegalArgumentException
- if the given array is null
public static void swapArray(Object[] array)
Object
s.array
- the array of Object
sIllegalArgumentException
- if the given array is null
public 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 null
public static int[] addArrays(int[] firstArray, int[] secondArray) throws IllegalArgumentException
int[]
with all ints of both arraysIllegalArgumentException
- if any of the given arrays are null
public static int[] createIntArray(int min, int max)
min
- the given minimummax
- the given maximumCopyright © 2014–2022 European Space Agency (ESA). All rights reserved.