Package org.esa.snap.core.util
Class ArrayUtils
- java.lang.Object
- 
- org.esa.snap.core.util.ArrayUtils
 
- 
 public class ArrayUtils extends Object 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. - Version:
- $Revision$ $Date$
 
- 
- 
Constructor SummaryConstructors Constructor Description ArrayUtils()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method 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 booleanequalArrays(double[] array1, double[] array2, double eps)Indicates whether the given arrays arrays are "equal to" each other.static booleanequalArrays(float[] array1, float[] array2, float eps)Indicates whether the given arrays arrays are "equal to" each other.static booleanequalArrays(Object[] array1, Object[] array2)Indicates whether the given objects arrays are "equal to" each other.static intgetElementIndex(Object element, Object[] array)Returns the index of the specified object within the given object array.static booleanisMemberOf(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 newdoublearray of the given length.static float[]recycleOrCreateArray(float[] array, int length)Recycles or creates a newfloatarray of the given length.static int[]recycleOrCreateArray(int[] array, int length)Recycles or creates a newintarray of the given length.static voidswapArray(byte[] array)Swaps the content of the given array ofbytes.static voidswapArray(char[] array)Swaps the content of the given array ofchars.static voidswapArray(double[] array)Swaps the content of the given array ofdoubles.static voidswapArray(float[] array)Swaps the content of the given array offloats.static voidswapArray(int[] array)Swaps the content of the given array ofints.static voidswapArray(long[] array)Swaps the content of the given array oflongs.static voidswapArray(short[] array)Swaps the content of the given array ofshorts.static voidswapArray(Object array)Swaps the content of the given array.static voidswapArray(Object[] array)Swaps the content of the given array ofObjects.
 
- 
- 
- 
Method Detail- 
equalArrayspublic static boolean equalArrays(float[] array1, float[] array2, float eps)Indicates whether the given arrays arrays are "equal to" each other.- Parameters:
- 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 arrays
- Returns:
- trueif each element in the first object array equals each element in the second, in fact in the same order;- falseotherwise.
 
 - 
equalArrayspublic static boolean equalArrays(double[] array1, double[] array2, double eps)Indicates whether the given arrays arrays are "equal to" each other.- Parameters:
- 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 arrays
- Returns:
- trueif each element in the first object array equals each element in the second, in fact in the same order;- falseotherwise.
 
 - 
equalArrayspublic static boolean equalArrays(Object[] array1, Object[] array2) Indicates whether the given objects arrays are "equal to" each other.This method should be used in place of the Object.equalsif one ore both arguments can benulland if an element-by-element comparision shall be performed, since this is what this method does: for each element pair theObjectUtils.equalObjectsmethod is called.- Parameters:
- array1- the first object array, can be- null
- array2- the second object array, can also be- null
- Returns:
- trueif each element in the first object array equals each element in the second, in fact in the same order;- falseotherwise.
 
 - 
getElementIndexpublic static int getElementIndex(Object element, Object[] array) Returns the index of the specified object within the given object array.The method calls the ObjectUtils.equalObjectswith the specified element on each of the array's elements. If both are equal, the index is immediately returned.- Parameters:
- element- the element to be searched
- array- the array in which to search the element, must not be- null
- Returns:
- the array index in the range 0toarray.length - 1if the element was found,-1otherwise
 
 - 
isMemberOfpublic static boolean isMemberOf(Object element, Object[] array) Checks if the given object is member of the specified array.The method simply returns getElementIndex(element, array) >= 0.- Parameters:
- element- the element to be searched
- array- the array in which to search the element, must not be- null
- Returns:
- trueif the given object is member of the specified array
 
 - 
swapArraypublic static void swapArray(byte[] array) Swaps the content of the given array ofbytes.- Parameters:
- array- the array of- bytes
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(char[] array) Swaps the content of the given array ofchars.- Parameters:
- array- the array of- chars
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(short[] array) Swaps the content of the given array ofshorts.- Parameters:
- array- the array of- shorts
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(int[] array) Swaps the content of the given array ofints.- Parameters:
- array- the array of- ints
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(long[] array) Swaps the content of the given array oflongs.- Parameters:
- array- the array of- longs
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(float[] array) Swaps the content of the given array offloats.- Parameters:
- array- the array of- floats
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(double[] array) Swaps the content of the given array ofdoubles.- Parameters:
- array- the array of- doubles
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(Object[] array) Swaps the content of the given array ofObjects.- Parameters:
- array- the array of- Objects
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
swapArraypublic static void swapArray(Object array) Swaps the content of the given array.- Parameters:
- array- the array, must be an instance of a native array type such as- float[]
- Throws:
- IllegalArgumentException- if the given array is- nullor does not have a native array type
 
 - 
recycleOrCreateArraypublic static int[] recycleOrCreateArray(int[] array, int length)Recycles or creates a newintarray of the given length.- Parameters:
- array- an array which can possibly be recycled
- length- the requested array length
- Returns:
- if the given array is not null and has exactly the requested length the given array is returned, otherwise a new array is created
 
 - 
recycleOrCreateArraypublic static float[] recycleOrCreateArray(float[] array, int length)Recycles or creates a newfloatarray of the given length.- Parameters:
- array- an array which can possibly be recycled
- length- the requested array length
- Returns:
- if the given array is not null and has exactly the requested length the given array is returned, otherwise a new array is created
 
 - 
recycleOrCreateArraypublic static double[] recycleOrCreateArray(double[] array, int length)Recycles or creates a newdoublearray of the given length.- Parameters:
- array- an array which can possibly be recycled
- length- the requested array length
- Returns:
- if the given array is not null and has exactly the requested length the given array is returned, otherwise a new array is created
 
 - 
addToArraypublic static int[] addToArray(int[] array, int value) throws IllegalArgumentExceptionGives a new int array who contains both, all ints form the given array and the given new value. The given value was added to the end of array- Returns:
- new int[]with all ints and the new value
- Throws:
- IllegalArgumentException- if the given array is- null
 
 - 
addArrayspublic static int[] addArrays(int[] firstArray, int[] secondArray) throws IllegalArgumentExceptionGives a new int array who contains both, all ints form all the given arrays. The given second array was added to the end of th first array.- Returns:
- new int[]with all ints of both arrays
- Throws:
- IllegalArgumentException- if any of the given arrays are- null
 
 - 
createIntArraypublic static int[] createIntArray(int min, int max)Creates an int array which containes all values between the given min and the given max. If min and max are equal an int[] which only contains one value was returned.- Parameters:
- min- the given minimum
- max- the given maximum
- Returns:
- an int array which containes all values between the given min and the given max.
 
 
- 
 
-