Package zombie.util.list
Class PZArrayUtil
java.lang.Object
zombie.util.list.PZArrayUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final float[]
static final int[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic float[]
add
(float[] array, float val) static <E> E[]
add
(E[] array, E val) static int[]
arrayAdd
(int[] in_out_a, int[] b) static <L extends List<E>,
E, S>
LarrayConvert
(L to, List<S> from, Function<S, E> converter) Convert all elements in the source array, and add them to the target.static float[]
arrayCopy
(float[] to, float[] from, int startIdx, int endIdx) static int[]
arrayCopy
(int[] to, int[] from, int startIdx, int endIdx) static <E> E[]
Copies all elements from the source array to the target.static <E,
S extends E>
E[]arrayCopy
(E[] to, S[] from) Copies all elements from the source array to the target.static <E,
S extends E>
E[]arrayCopy
(E[] to, S[] from, int startIdx, int endIdx) static <L extends List<E>,
E>
LCopies all elements from the source array to the target.static <E> E[]
arrayPopulate
(E[] arr, Supplier<E> supplier) static float[]
arraySet
(float[] arr, float val) static int[]
arraySet
(int[] arr, int val) static <E> E[]
arraySet
(E[] arr, E val) static String
arrayToString
(float[] list) static String
arrayToString
(float[] list, String prefix, String suffix, String delimiter) static <E> String
arrayToString
(E[] list) static <E> String
arrayToString
(E[] list, String prefix, String suffix, String delimiter) static <E> String
arrayToString
(Iterable<E> list) static <E> String
arrayToString
(Iterable<E> list, String prefix, String suffix, String delimiter) static <E> String
arrayToString
(Iterable<E> list, Function<E, String> toString) static <E> String
arrayToString
(Iterable<E> list, Function<E, String> toString, String prefix, String suffix, String delimiter) static float[]
clone
(float[] src) static <E> E[]
clone
(E[] src) static <E> E[]
concat
(E[] arrayA, E[] arrayB) Concatenate two arrays.static boolean
contains
(float[] arr, int count, float val) static boolean
contains
(int[] arr, int count, int val) static <E> boolean
static <E> boolean
static <E> boolean
contains
(Collection<E> it, Predicate<E> comparer) static <E> boolean
static <E> void
Perform a shallow copy of the source array into the target array.static <E> void
Perform a copy of the source array into the target array, using the supplied ICloner.static <E> E
static <E> E
static <E> void
Iterate over specified array, invoke supplied consumer on each element.static <E> void
Iterate over specified Iterable, invoke supplied consumer on each element.static <E> void
Iterate over specified list, invoke supplied consumer on each element.static <E> E
getElementAt
(Iterable<E> collection, int index) Get the specified element from the supplied Iterable.static <K,
V> V getOrCreate
(HashMap<K, V> map, K key, Supplier<V> allocator) static float
getOrDefault
(float[] list, int i, float defaultVal) Get the array value at index.static <E> E
getOrDefault
(E[] list, int i, E defaultVal) Get the array value at index.static <E> E
getOrDefault
(List<E> list, int i) Get the array value at index.static <E> E
getOrDefault
(List<E> list, int i, E defaultVal) Get the array value at index.static <E> int
Count the number of elements in the supplied Iterable.static int
indexOf
(float[] arr, int count, float val) static int
indexOf
(int[] arr, int count, int val) static <E> int
indexOf
(E[] arr, int count, E val) static <E> int
static <E> int
static void
insertAt
(float[] arr, int insertAt, float val) static void
insertAt
(int[] arr, int insertAt, int val) static boolean
isNullOrEmpty
(float[] array) static boolean
isNullOrEmpty
(int[] array) static <E> boolean
isNullOrEmpty
(E[] array) static <E> boolean
isNullOrEmpty
(Iterable<E> it) static <E> boolean
isNullOrEmpty
(List<E> list) static <E,
S> Iterable<E> static <E,
S> List<E> listConvert
(List<S> source, Function<S, E> converter) static <E,
S> List<E> listConvert
(List<S> source, List<E> dest, Function<S, E> converter) static <E,
S, T1> List<E> listConvert
(List<S> source, List<E> dest, T1 v1, PZArrayUtil.IListConverter1Param<S, E, T1> converter) static <E> E[]
newInstance
(Class<?> componentType, int length) static <E> E[]
newInstance
(Class<?> componentType, int length, Supplier<E> allocator) static <E> E[]
newInstance
(Class<?> componentType, E[] reusableArray, int newLength) static <E> E[]
newInstance
(Class<?> componentType, E[] reusableArray, int newLength, boolean growOnly) static <E> E[]
newInstance
(Class<?> componentType, E[] reusableArray, int newLength, boolean growOnly, Supplier<E> newAllocator) static <E> E[]
newInstance
(Class<?> componentType, E[] reusableArray, int newLength, Supplier<E> newAllocator) static <E> E
pickRandom
(E[] collection) Pick a random element from the supplied Array.static <E> E
pickRandom
(Iterable<E> collection) Pick a random element from the supplied Iterable.static <E> E
pickRandom
(Collection<E> collection) Pick a random element from the supplied Collection.static <E> E
pickRandom
(List<E> collection) Pick a random element from the supplied List.static <E> boolean
sequenceEqual
(E[] a, List<? extends E> b) static <E> boolean
sequenceEqual
(E[] a, List<? extends E> b, Comparator<E> comparator) static <E> boolean
sequenceEqual
(List<? extends E> a, List<? extends E> b) static <E> boolean
sequenceEqual
(List<? extends E> a, List<? extends E> b, Comparator<E> comparator) static <E> void
sort
(Stack<E> stack, Comparator<E> comparator) static <E> E[]
-
Field Details
-
emptyIntArray
public static final int[] emptyIntArray -
emptyFloatArray
public static final float[] emptyFloatArray
-
-
Constructor Details
-
PZArrayUtil
public PZArrayUtil()
-
-
Method Details
-
pickRandom
public static <E> E pickRandom(E[] collection) Pick a random element from the supplied Array. -
pickRandom
Pick a random element from the supplied List. -
pickRandom
Pick a random element from the supplied Collection. -
pickRandom
Pick a random element from the supplied Iterable. -
getSize
Count the number of elements in the supplied Iterable. -
getElementAt
public static <E> E getElementAt(Iterable<E> collection, int index) throws ArrayIndexOutOfBoundsException Get the specified element from the supplied Iterable.- Throws:
ArrayIndexOutOfBoundsException
-
copy
Perform a shallow copy of the source array into the target array. The target array's contents are replaced with that of the source array. -
copy
Perform a copy of the source array into the target array, using the supplied ICloner. The target array's contents first cleared, and then populated with elements generated using the ICloner.clone() function. -
indexOf
-
indexOf
-
contains
-
contains
-
contains
-
contains
-
find
-
find
-
listConvert
-
itConvert
-
listConvert
-
listConvert
public static <E,S, List<E> listConvertT1> (List<S> source, List<E> dest, T1 v1, PZArrayUtil.IListConverter1Param<S, E, T1> converter) -
arrayToString
-
arrayToString
-
arrayToString
-
arrayToString
-
arrayToString
-
arrayToString
-
arrayToString
-
arrayToString
-
newInstance
-
newInstance
-
newInstance
-
newInstance
public static <E> E[] newInstance(Class<?> componentType, E[] reusableArray, int newLength, boolean growOnly) -
newInstance
-
newInstance
-
add
public static float[] add(float[] array, float val) -
add
public static <E> E[] add(E[] array, E val) -
concat
public static <E> E[] concat(E[] arrayA, E[] arrayB) Concatenate two arrays. null-safe. Allows either A or B parameters to be null or empty. -
arrayCopy
public static <E,S extends E> E[] arrayCopy(E[] to, S[] from, int startIdx, int endIdx) -
arrayCopy
public static float[] arrayCopy(float[] to, float[] from, int startIdx, int endIdx) -
arrayCopy
public static int[] arrayCopy(int[] to, int[] from, int startIdx, int endIdx) -
arrayCopy
Copies all elements from the source array to the target. Clears target before populating.- Returns:
- The target array.
-
arrayCopy
Copies all elements from the source array to the target. Clears target before populating.- Returns:
- The target array.
-
arrayCopy
public static <E,S extends E> E[] arrayCopy(E[] to, S[] from) Copies all elements from the source array to the target. Clears target before populating.- Returns:
- The target array.
-
arrayConvert
Convert all elements in the source array, and add them to the target. Uses supplied converter function. Clears target before populating.- Returns:
- The target array.
-
clone
public static float[] clone(float[] src) -
clone
public static <E> E[] clone(E[] src) -
isNullOrEmpty
public static <E> boolean isNullOrEmpty(E[] array) -
isNullOrEmpty
public static boolean isNullOrEmpty(int[] array) -
isNullOrEmpty
public static boolean isNullOrEmpty(float[] array) -
isNullOrEmpty
-
isNullOrEmpty
-
getOrDefault
Get the array value at index. Bounds-safe: Returns null value if out of bounds. -
getOrDefault
Get the array value at index. Bounds-safe: Returns default value if out of bounds. -
getOrDefault
public static <E> E getOrDefault(E[] list, int i, E defaultVal) Get the array value at index. Bounds-safe: Returns default value if out of bounds. -
getOrDefault
public static float getOrDefault(float[] list, int i, float defaultVal) Get the array value at index. Bounds-safe: Returns default value if out of bounds. -
arraySet
public static int[] arraySet(int[] arr, int val) -
arraySet
public static float[] arraySet(float[] arr, float val) -
arraySet
public static <E> E[] arraySet(E[] arr, E val) -
arrayPopulate
-
insertAt
public static void insertAt(int[] arr, int insertAt, int val) -
insertAt
public static void insertAt(float[] arr, int insertAt, float val) -
toArray
-
indexOf
public static <E> int indexOf(E[] arr, int count, E val) -
indexOf
public static int indexOf(float[] arr, int count, float val) -
contains
public static boolean contains(float[] arr, int count, float val) -
indexOf
public static int indexOf(int[] arr, int count, int val) -
contains
public static boolean contains(int[] arr, int count, int val) -
forEach
Iterate over specified list, invoke supplied consumer on each element. Better GC awareness over List.forEach, avoids use of forEach and iterators. Null-safe -
forEach
Iterate over specified Iterable, invoke supplied consumer on each element. Better GC awareness over List.forEach, avoids use of forEach and iterators, if the iterable is of type List. Null-safe -
forEach
Iterate over specified array, invoke supplied consumer on each element. Null-safe -
getOrCreate
-
sort
-
sequenceEqual
-
sequenceEqual
-
sequenceEqual
-
sequenceEqual
public static <E> boolean sequenceEqual(List<? extends E> a, List<? extends E> b, Comparator<E> comparator) -
arrayAdd
public static int[] arrayAdd(int[] in_out_a, int[] b)
-