Package org.glassfish.grizzly.utils
Class ArrayUtils
- java.lang.Object
-
- org.glassfish.grizzly.utils.ArrayUtils
-
public final class ArrayUtils extends Object
Set of utility methods to work with Arrays.- Author:
- Alexey Stashok
-
-
Constructor Summary
Constructors Constructor Description ArrayUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T[]addUnique(T[] array, T element)Add unique element to the array.static <T> T[]addUnique(T[] array, T element, boolean replaceElementIfEquals)Add unique element to the array.static intbinarySearch(int[] a, int fromIndex, int toIndex, int key)static <T> intindexOf(T[] array, Object element)Return the element index in the array.static <T> T[]remove(T[] array, Object element)Removes the element from the array.
-
-
-
Method Detail
-
binarySearch
public static int binarySearch(int[] a, int fromIndex, int toIndex, int key)
-
addUnique
public static <T> T[] addUnique(T[] array, T element)Add unique element to the array.- Type Parameters:
T- type of the array element- Parameters:
array- arrayelement- element to add- Returns:
- array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.
-
addUnique
public static <T> T[] addUnique(T[] array, T element, boolean replaceElementIfEquals)Add unique element to the array.- Type Parameters:
T- type of the array element- Parameters:
array- arrayelement- element to addreplaceElementIfEquals- if passed element is equal to some element in the array then depending on this parameter it will be replaced or not with the passed element.- Returns:
- array, which will contain the new element. Either new array instance, if passed array didn't contain the element, or the same array instance, if the element is already present in the array.
-
remove
public static <T> T[] remove(T[] array, Object element)Removes the element from the array.- Type Parameters:
T- type of the array element- Parameters:
array- arrayelement- the element to remove- Returns:
- array, which won't contain the element. Either new array instance, if passed array contains the element, or the same array instance, if the element wasn't present in the array. null will be returned if the last element was removed from the passed array.
-
indexOf
public static <T> int indexOf(T[] array, Object element)Return the element index in the array.- Type Parameters:
T- type of the array element- Parameters:
array- arrayelement- the element to look for.- Returns:
- element's index, or -1 if element wasn't found.
-
-