public final class ArrayTools extends Object
| Modifier and Type | Method and Description |
|---|---|
static int[] |
add(int[] array,
int element)
Adds an element in an array.
|
static int[] |
add(int[] array,
int element,
int pointer)
Adds an element in an array.
|
static <T> T[] |
add(T[] array,
T element)
Adds an element in an array.
|
static <T> T[] |
add(T[] array,
T[] other)
Appends an array to another.
|
static <T> T[] |
add(T[] array,
T element,
int pointer)
Adds an element in an array.
|
static void |
checkArrayBounds(int arrayLength,
int offset,
int length)
Checks the given range is included in the array (defined by its length).
|
static void |
checkBounds(byte[] bytes,
int offset,
int length)
Checks the given range is included in the given byte array.
|
static void |
checkBounds(int arrayLength,
int offset,
int length)
Checks the given range is included in the array (defined by its length).
|
static void |
checkStringBounds(int stringLength,
int offset,
int length)
Checks the given range is included in the array (defined by its length).
|
static byte[] |
concat(byte[] array1,
byte[] array2)
Concatenates two arrays.
|
static byte[] |
concatRanges(byte[] array1,
int offset1,
int length1,
byte[] array2,
int offset2,
int length2)
Concatenates two array ranges.
|
static boolean |
contains(int[] array,
int element)
Gets whether an array contains an element or not.
|
static boolean |
contains(int[] array,
int element,
int pointer)
Gets whether an array contains an element or not.
|
static <T> boolean |
contains(T[] array,
T element)
Gets whether an array contains an element or not.
|
static <T> boolean |
contains(T[] array,
T element,
int pointer)
Gets whether an array contains an element or not.
|
static <T> boolean |
containsEquals(T[] array,
T element)
Gets whether an array contains an element or not.
|
static <T> boolean |
containsEquals(T[] array,
T element,
int pointer)
Gets whether an array contains an element or not.
|
static <T> T[] |
createNewArray(T[] array,
int length)
Creates a new array with the same type as the given array.
|
static boolean |
equalsRanges(byte[] array1,
int offset1,
byte[] array2,
int offset2,
int length)
Returns whether two array ranges are equal.
|
static int |
getIndex(int[] array,
int element)
Gets the index of an element in an array.
|
static <T> int |
getIndex(T[] array,
T element)
Gets the index of an element in an array.
|
static <T> int |
getIndex(T[] array,
T element,
int pointer)
Gets the index of an element in an array.
|
static <T> int |
getIndexEquals(T[] array,
T element)
Gets the index of an element in an array.
|
static <T> int |
getIndexEquals(T[] array,
T element,
int pointer)
Gets the index of an element in an array.
|
static int[] |
grow(int[] array,
int index,
int count)
Grows an array by inserting a number of cells at an index.
|
static <T> T[] |
grow(T[] array,
int index,
int count)
Grows an array by inserting a number of cells at an index.
|
static <T> T[] |
insert(T[] array,
int index,
T element)
Inserts an element at an index in an array.
|
static <T> T[] |
insert(T[] array,
int index,
T element,
int pointer)
Inserts an element at an index in an array.
|
static int[] |
remove(int[] array,
int element)
Removes an element in an array.
|
static boolean |
remove(int[] array,
int element,
int pointer)
Removes an element in an array.
|
static <T> T[] |
remove(T[] array,
int index)
Removes an element at an index in an array.
|
static <T> T[] |
remove(T[] array,
T element)
Removes an element in an array.
|
static <T> boolean |
remove(T[] array,
T element,
int pointer)
Removes an element in an array.
|
static <T> T[] |
removeEquals(T[] array,
T element)
Removes an element in an array.
|
static <T> boolean |
removeEquals(T[] array,
T element,
int pointer)
Removes an element in an array.
|
static int[] |
shrink(int[] array,
int index,
int count)
Shrinks an array by removing a number of cells at an index.
|
static <T> T[] |
shrink(T[] array,
int index,
int count)
Shrinks an array by removing a number of cells at an index.
|
public static int[] add(int[] array,
int element)
add(int[], int, int)).array - the input array.element - the element to add.public static int[] add(int[] array,
int element,
int pointer)
The array returned could be different from the given one, it grows to pointer*2 only if the given
array is not large enough to add the given element (ptr == array.length).
array - the input array.element - the element to add.pointer - the index of the element to add.ArrayIndexOutOfBoundsException - if the pointer is greater than the array length.public static <T> T[] add(T[] array,
T element)
add(Object[], Object, int)).T - the type of array elements.array - the input array.element - the element to add.public static <T> T[] add(T[] array,
T[] other)
add(Object[], Object, int)).T - the type of array elements.array - the input array.other - the array to append.public static <T> T[] add(T[] array,
T element,
int pointer)
The array returned could be different from the given one, it grows to pointer*2 only if the given
array is not large enough to add the given element (pointer == array.length).
T - the type of array elements.array - the input array.element - the element to add.pointer - the index of the element to add.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static void checkArrayBounds(int arrayLength,
int offset,
int length)
arrayLength - the array length.offset - the offset of the range.length - the length of the range.ArrayIndexOutOfBoundsException - if the range is not included in the array.public static void checkBounds(byte[] bytes,
int offset,
int length)
bytes - the byte array.offset - the offset of the range.length - the length of the range.IndexOutOfBoundsException - if the range is not included in the array.public static void checkBounds(int arrayLength,
int offset,
int length)
arrayLength - the array length.offset - the offset of the range.length - the length of the range.IndexOutOfBoundsException - if the range is not included in the array.public static void checkStringBounds(int stringLength,
int offset,
int length)
stringLength - the string length.offset - the offset of the range.length - the length of the range.StringIndexOutOfBoundsException - if the range is not included in the array.public static byte[] concat(byte[] array1,
byte[] array2)
array1 - the first array.array2 - the second array.public static byte[] concatRanges(byte[] array1,
int offset1,
int length1,
byte[] array2,
int offset2,
int length2)
array1 - the array containing the first range.offset1 - the start index in the array of the first range.length1 - the length of the first range.array2 - the array containing the second range.offset2 - the offset in the array of the second range.length2 - the length of the second range.public static boolean contains(int[] array,
int element)
array - the array.element - the element to search.true if the element exists in the array, false otherwise.public static boolean contains(int[] array,
int element,
int pointer)
array - the array.element - the element to search.pointer - the index of the last element of the array.true if the element exists in the array, false otherwise.public static <T> boolean contains(T[] array,
T element)
The comparison between the elements is done using == operator.
T - the type of array elements.array - the array.element - the element to search.true if the element exists in the array, false otherwise.public static <T> boolean contains(T[] array,
T element,
int pointer)
The comparison between the elements is done using == operator.
T - the type of array elements.array - the array.element - the element to search.pointer - the index of the last element of the array.true if the element exists in the array, false otherwise.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static <T> boolean containsEquals(T[] array,
T element)
The comparison between the elements is done using Object.equals(Object).
T - the type of array elements.array - the array.element - the element to search.true if the element exists in the array, false otherwise.public static <T> boolean containsEquals(T[] array,
T element,
int pointer)
The comparison between the elements is done using Object.equals(Object).
T - the type of array elements.array - the array.element - the element to search.pointer - the index of the last element of the array.true if the element exists in the array, false otherwise.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static <T> T[] createNewArray(T[] array,
int length)
T - the type of array elements.array - the array.length - the length of the array to create.public static boolean equalsRanges(byte[] array1,
int offset1,
byte[] array2,
int offset2,
int length)
array1 - the array containing the first range.offset1 - the start index in the array of the first range.array2 - the array containing the second range.offset2 - the offset in the array of the second range.length - the length of the ranges.true if the array ranges are equal, false otherwise.public static int getIndex(int[] array,
int element)
array - the array.element - the element to search.-1 if not found.public static <T> int getIndex(T[] array,
T element)
The comparison between the elements is done using == operator.
T - the type of array elements.array - the array.element - the element to search.-1 if not found.public static <T> int getIndex(T[] array,
T element,
int pointer)
The comparison between the elements is done using == operator.
T - the type of array elements.array - the array.element - the element to search.pointer - the index of the last element of the array.-1 if not found.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static <T> int getIndexEquals(T[] array,
T element)
The comparison between the elements is done using Object.equals(Object).
T - the type of array elements.array - the array.element - the element to search.-1 if not found.public static <T> int getIndexEquals(T[] array,
T element,
int pointer)
The comparison between the elements is done using Object.equals(Object).
T - the type of array elements.array - the array.element - the element to search.pointer - the index of the last element of the array.-1 if not found.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static int[] grow(int[] array,
int index,
int count)
0.array - the input array.index - the index to insert the cells at in the array.count - the number of cells to insert.IllegalArgumentException - if the given count is negative.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static <T> T[] grow(T[] array,
int index,
int count)
null.T - the type of array elements.array - the input array.index - the index to insert the cells at in the array.count - the number of cells to insert.IllegalArgumentException - if the given count is negative.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static <T> T[] insert(T[] array,
int index,
T element)
insert(Object[], int, Object, int)).T - the type of array elements.array - the input array.index - the index in the array.element - the element to add.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static <T> T[] insert(T[] array,
int index,
T element,
int pointer)
The array returned could be different from the given one, it grows to pointer*2 only if the given
array is not large enough to add the given element (pointer == array.length).
T - the type of array elements.array - the input array.index - the index in the array.element - the element to add.pointer - the index of the element to add.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static int[] remove(int[] array,
int element)
If the array does not contain the given element, the returned array is the given array, otherwise, it is always a different one. If the array contains several times the given element, only the last added is removed.
The returned array size fit the number of elements (in opposition with remove(int[], int, int)).
array - the input array.element - the element to remove.public static boolean remove(int[] array,
int element,
int pointer)
If the array does not contain the given element, the given array is not modified and the method returns
false, otherwise it returns true.
If the array contains several times the given element, only the last added is removed.
array - the input array.element - the element to remove.pointer - the index of the last element of the array.true if the element has been removed, false otherwise.public static <T> T[] remove(T[] array,
int index)
The returned array size fit the number of elements.
T - the type of array elements.array - the input array.index - the index of the element to remove.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static <T> T[] remove(T[] array,
T element)
The comparison between the elements is done using == operator.
If the array does not contain the given element, the returned array is the given one, otherwise, it is always a different one. If the array contains several times the given element, only the last added is removed.
The returned array size fit the number of elements (in opposition with remove(Object[], Object, int)).
T - the type of array elements.array - the input array.element - the element to remove.public static <T> boolean remove(T[] array,
T element,
int pointer)
The comparison between the elements is done using == operator.
If the array does not contain the given element, the given array is not modified and the method returns
false, otherwise it returns true.
If the array contains several times the given element, only the last added is removed.
T - the type of array elements.array - the input array.element - the element to remove.pointer - the index of the last element of the array.true if the element has been removed, false otherwise.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static <T> T[] removeEquals(T[] array,
T element)
The comparison between the elements is done using Object.equals(Object).
If the array does not contain the given element, the returned array is the given one, otherwise, it is always a different one. If the array contains several times the given element, only the last added is removed.
The returned array size fit the number of elements (in opposition with remove(Object[], Object, int)).
T - the type of array elements.array - the input array.element - the element to remove.public static <T> boolean removeEquals(T[] array,
T element,
int pointer)
The comparison between the elements is done using Object.equals(Object).
If the array does not contain the given element, the given array is not modified and the method returns
false, otherwise it returns true.
If the array contains several times the given element, only the last added is removed.
T - the type of array elements.array - the input array.element - the element to remove.pointer - the index of the last element of the array.true if the element has been removed, false otherwise.ArrayIndexOutOfBoundsException - if the given pointer is greater than the array length.public static int[] shrink(int[] array,
int index,
int count)
array - the input array.index - the index of the cells to remove in the array.count - the number of cells to remove.IllegalArgumentException - if the given count is negative or greater than array length.IndexOutOfBoundsException - if the given index is not included in the resulting array.public static <T> T[] shrink(T[] array,
int index,
int count)
T - the type of array elements.array - the input array.index - the index of the cells to remove in the array.count - the number of cells to remove.IllegalArgumentException - if the given count is negative or greater than array length.IndexOutOfBoundsException - if the given index is not included in the resulting array.