java.lang.Object
org.seppiko.commons.utils.ArrayUtil
Array Util
- Author:
- Leonard Woo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]It will have a backing array, and its array offset will be zero.static Object[]getSuppliers(Supplier<Object>[] suppliers) Get Supplier object with not null array.static <T> booleanisArray(T obj) Returnstrueif the provided reference is array, otherwise returnsfalse.static <T> booleanisEmpty(T[] array) Returnstrueif the array isnull, otherwise returnsfalse.static <T> booleanisNull(T[] obj) Returnstrueif the provided reference isnull, otherwise returnsfalse.static <T> booleannonNull(T[] obj) Returnstrueif the provided reference is non-null, otherwise returnsfalse.static <T> T[]swap(T[] oriTs, int a, int b) Swap T array index a and b.
-
Method Details
-
isArray
public static <T> boolean isArray(T obj) Returnstrueif the provided reference is array, otherwise returnsfalse.- Type Parameters:
T- reference type.- Parameters:
obj- a reference to be checked against.- Returns:
trueif the provided reference is array, otherwisefalse.
-
isEmpty
public static <T> boolean isEmpty(T[] array) Returnstrueif the array isnull, otherwise returnsfalse.- Type Parameters:
T- reference type.- Parameters:
array- a reference to be checked against.- Returns:
trueif the provided array isnull, otherwisefalse.
-
isNull
public static <T> boolean isNull(T[] obj) Returnstrueif the provided reference isnull, otherwise returnsfalse.- Type Parameters:
T- reference type.- Parameters:
obj- a reference to be checked againstnull.- Returns:
trueif the provided reference isnull, otherwisefalse.
-
nonNull
public static <T> boolean nonNull(T[] obj) Returnstrueif the provided reference is non-null, otherwise returnsfalse.- Type Parameters:
T- reference type.- Parameters:
obj- a reference to be checked againstnull.- Returns:
trueif the provided reference is non-null, otherwisefalse.
-
swap
public static <T> T[] swap(T[] oriTs, int a, int b) Swap T array index a and b.- Type Parameters:
T- Object type.- Parameters:
oriTs- origin T array.a- first index.b- second index.- Returns:
- swap result.
-
getSuppliers
Get Supplier object with not null array.- Parameters:
suppliers- supplier array.- Returns:
- object array.
- Throws:
NullPointerException- supplier array is null.
-
allocate
public static <T> T[] allocate(int capacity, Class<T> type) throws IllegalArgumentException, NullPointerException It will have a backing array, and its array offset will be zero.- Type Parameters:
T- Array component type.- Parameters:
capacity- the capacity of the new array.type- theClassobject representing the component type of the new array.- Returns:
- the new array.
- Throws:
IllegalArgumentException- if the capacity is less than 0 or exceeds 255.NullPointerException- if the specifiedclazzparameter isnull.
-