com.intel.langutil
Class ArrayUtils
- java.lang.Object
-
- com.intel.langutil.ArrayUtils
-
public final class ArrayUtils extends java.lang.Object
This class provides basic array utilities, such as: array copy, array compare, fill array, etc.
-
-
Constructor Summary
Constructors Constructor and Description ArrayUtils()
-
Method Summary
Methods Modifier and Type Method and Description static void
checkBooleanArrayRange(boolean[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception.static void
checkByteArrayRange(byte[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception.static void
checkIntArrayRange(int[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception.static void
checkShortArrayRange(short[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception.static boolean
compareBooleanArray(boolean[] sourceArray, int sourceIndex, boolean[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.static boolean
compareByteArray(byte[] sourceArray, int sourceIndex, byte[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.static boolean
compareIntArray(int[] sourceArray, int sourceIndex, int[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.static boolean
compareShortArray(short[] sourceArray, int sourceIndex, short[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.static void
copyBooleanArray(boolean[] sourceArray, int sourceIndex, boolean[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.static void
copyByteArray(byte[] sourceArray, int sourceIndex, byte[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.static void
copyIntArray(int[] sourceArray, int sourceIndex, int[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.static void
copyShortArray(short[] sourceArray, int sourceIndex, short[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.static void
fillBooleanArray(boolean[] array, int index, int length, boolean value)
Fills the provided array using the provided value.static void
fillByteArray(byte[] array, int index, int length, byte value)
Fills the provided array using the provided value.static void
fillIntArray(int[] array, int index, int length, int value)
Fills the provided array using the provided value.static void
fillShortArray(short[] array, int index, int length, short value)
Fills the provided array using the provided value.static int
findInBooleanArray(boolean[] subArray, int subArrayIndex, int subArrayLength, boolean[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.static int
findInByteArray(byte[] subArray, int subArrayIndex, int subArrayLength, byte[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.static int
findInIntArray(int[] subArray, int subArrayIndex, int subArrayLength, int[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.static int
findInShortArray(short[] subArray, int subArrayIndex, int subArrayLength, short[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.
-
-
-
Method Detail
-
copyIntArray
public static final void copyIntArray(int[] sourceArray, int sourceIndex, int[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of data to copy
-
copyByteArray
public static final void copyByteArray(byte[] sourceArray, int sourceIndex, byte[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of data to copy
-
copyShortArray
public static final void copyShortArray(short[] sourceArray, int sourceIndex, short[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of data to copy
-
copyBooleanArray
public static final void copyBooleanArray(boolean[] sourceArray, int sourceIndex, boolean[] destinationArray, int destinationIndex, int length)
Copies the data from the source array into the destination array.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of data to copy
-
fillIntArray
public static final void fillIntArray(int[] array, int index, int length, int value)
Fills the provided array using the provided value.- Parameters:
array
- the array to be filledindex
- index in the input arraylength
- the length of the array range to be filledvalue
- the value to fill the array with
-
fillByteArray
public static final void fillByteArray(byte[] array, int index, int length, byte value)
Fills the provided array using the provided value.- Parameters:
array
- the array to be filledindex
- index in the input arraylength
- the length of the array range to be filledvalue
- the value to fill the array with
-
fillShortArray
public static final void fillShortArray(short[] array, int index, int length, short value)
Fills the provided array using the provided value.- Parameters:
array
- the array to be filledindex
- index in the input arraylength
- the length of the array range to be filledvalue
- the value to fill the array with
-
fillBooleanArray
public static final void fillBooleanArray(boolean[] array, int index, int length, boolean value)
Fills the provided array using the provided value.- Parameters:
array
- the array to be filledindex
- index in the input arraylength
- the length of the array range to be filledvalue
- the value to fill the array with
-
compareIntArray
public static final boolean compareIntArray(int[] sourceArray, int sourceIndex, int[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of the data to be compared- Returns:
true
if the data in the arrays is identical,false
otherwise.
-
compareByteArray
public static final boolean compareByteArray(byte[] sourceArray, int sourceIndex, byte[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of the data to be compared- Returns:
true
if the data in the arrays is identical,false
otherwise.
-
compareShortArray
public static final boolean compareShortArray(short[] sourceArray, int sourceIndex, short[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of the data to be compared- Returns:
true
if the data in the arrays is identical,false
otherwise.
-
compareBooleanArray
public static final boolean compareBooleanArray(boolean[] sourceArray, int sourceIndex, boolean[] destinationArray, int destinationIndex, int length)
Compares the data in the two provided arrays.- Parameters:
sourceArray
- source arraysourceIndex
- index in the source arraydestinationArray
- destination arraydestinationIndex
- index in the destination arraylength
- the length of the data to be compared- Returns:
true
if the data in the arrays is identical,false
otherwise.
-
checkIntArrayRange
public static final void checkIntArrayRange(int[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception. The array limit is defined as: index + length- Parameters:
array
- the array to checkindex
- index in the arraylength
- length in the array- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the provided index + the provided length exceed the array rangejava.lang.NullPointerException
- if the array is null
-
checkByteArrayRange
public static final void checkByteArrayRange(byte[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception. The array limit is defined as: index + length- Parameters:
array
- the array to checkindex
- index in the arraylength
- length in the array- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the provided index + the provided length exceed the array rangejava.lang.NullPointerException
- if the array is null
-
checkShortArrayRange
public static final void checkShortArrayRange(short[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception. The array limit is defined as: index + length- Parameters:
array
- the array to checkindex
- index in the arraylength
- length in the array- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the provided index + the provided length exceed the array rangejava.lang.NullPointerException
- if the array is null
-
checkBooleanArrayRange
public static final void checkBooleanArrayRange(boolean[] array, int index, int length)
Verifies that the provided array parameters are within the array limits, otherwise throws an exception. The array limit is defined as: index + length- Parameters:
array
- the array to checkindex
- index in the arraylength
- length in the array- Throws:
java.lang.ArrayIndexOutOfBoundsException
- if the provided index + the provided length exceed the array rangejava.lang.NullPointerException
- if the array is null
-
findInIntArray
public static final int findInIntArray(int[] subArray, int subArrayIndex, int subArrayLength, int[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.- Parameters:
subArray
- the sub-array to findsubArrayIndex
- index in the sub-arraysubArrayLength
- length of the sub-arraydestinationArray
- the destination array to search indestinationIndex
- index in the destination arraydestinationLength
- length of the destination array range to search in- Returns:
- If the sub-array is found, returns the index of its first occurrence in the destination array. Otherwise, returns -1.
-
findInByteArray
public static final int findInByteArray(byte[] subArray, int subArrayIndex, int subArrayLength, byte[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.- Parameters:
subArray
- the sub-array to findsubArrayIndex
- index in the sub-arraysubArrayLength
- length of the sub-arraydestinationArray
- the destination array to search indestinationIndex
- index in the destination arraydestinationLength
- length of the destination array range to search in- Returns:
- If the sub-array is found, returns the index of its first occurrence in the destination array. Otherwise, returns -1.
-
findInShortArray
public static final int findInShortArray(short[] subArray, int subArrayIndex, int subArrayLength, short[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.- Parameters:
subArray
- the sub-array to findsubArrayIndex
- index in the sub-arraysubArrayLength
- length of the sub-arraydestinationArray
- the destination array to search indestinationIndex
- index in the destination arraydestinationLength
- length of the destination array range to search in- Returns:
- If the sub-array is found, returns the index of its first occurrence in the destination array. Otherwise, returns -1.
-
findInBooleanArray
public static final int findInBooleanArray(boolean[] subArray, int subArrayIndex, int subArrayLength, boolean[] destinationArray, int destinationIndex, int destinationLength)
Finds the provided sub-array in the destination array.- Parameters:
subArray
- the sub-array to findsubArrayIndex
- index in the sub-arraysubArrayLength
- length of the sub-arraydestinationArray
- the destination array to search indestinationIndex
- index in the destination arraydestinationLength
- length of the destination array range to search in- Returns:
- If the sub-array is found, returns its index in the destination array. Otherwise, returns -1.
-
-