java.lang.Object
org.glassfish.grizzly.utils.ArrayUtils
Set of utility methods to work with Arrays.
- Author:
- Alexey Stashok
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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> intReturn the element index in the array.static <T> T[]Removes the element from the array.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
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
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
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.
-