Class PZArrayUtil

java.lang.Object
zombie.util.list.PZArrayUtil

public class PZArrayUtil extends Object
  • 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

      public static <E> E pickRandom(List<E> collection)
      Pick a random element from the supplied List.
    • pickRandom

      public static <E> E pickRandom(Collection<E> collection)
      Pick a random element from the supplied Collection.
    • pickRandom

      public static <E> E pickRandom(Iterable<E> collection)
      Pick a random element from the supplied Iterable.
    • getSize

      public static <E> int getSize(Iterable<E> collection)
      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

      public static <E> void copy(ArrayList<E> target, ArrayList<E> source)
      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

      public static <E> void copy(ArrayList<E> target, ArrayList<E> source, ICloner<E> elementCloner)
      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

      public static <E> int indexOf(E[] collection, Predicate<E> comparer)
    • indexOf

      public static <E> int indexOf(List<E> collection, Predicate<E> comparer)
    • contains

      public static <E> boolean contains(E[] collection, Predicate<E> comparer)
    • contains

      public static <E> boolean contains(List<E> collection, Predicate<E> comparer)
    • contains

      public static <E> boolean contains(Collection<E> it, Predicate<E> comparer)
    • contains

      public static <E> boolean contains(Iterable<E> it, Predicate<E> comparer)
    • find

      public static <E> E find(List<E> collection, Predicate<E> comparer)
    • find

      public static <E> E find(Iterable<E> collection, Predicate<E> comparer)
    • listConvert

      public static <E, S> List<E> listConvert(List<S> source, Function<S,E> converter)
    • itConvert

      public static <E, S> Iterable<E> itConvert(Iterable<S> source, Function<S,E> converter)
    • listConvert

      public static <E, S> List<E> listConvert(List<S> source, List<E> dest, Function<S,E> converter)
    • listConvert

      public static <E, S, T1> List<E> listConvert(List<S> source, List<E> dest, T1 v1, PZArrayUtil.IListConverter1Param<S,E,T1> converter)
    • arrayToString

      public static String arrayToString(float[] list)
    • arrayToString

      public static String arrayToString(float[] list, String prefix, String suffix, String delimiter)
    • arrayToString

      public static <E> String arrayToString(E[] list)
    • arrayToString

      public static <E> String arrayToString(E[] list, String prefix, String suffix, String delimiter)
    • arrayToString

      public static <E> String arrayToString(Iterable<E> list, Function<E,String> toString)
    • arrayToString

      public static <E> String arrayToString(Iterable<E> list)
    • arrayToString

      public static <E> String arrayToString(Iterable<E> list, String prefix, String suffix, String delimiter)
    • arrayToString

      public static <E> String arrayToString(Iterable<E> list, Function<E,String> toString, String prefix, String suffix, String delimiter)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, int length)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, int length, Supplier<E> allocator)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, E[] reusableArray, int newLength)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, E[] reusableArray, int newLength, boolean growOnly)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, E[] reusableArray, int newLength, Supplier<E> newAllocator)
    • newInstance

      public static <E> E[] newInstance(Class<?> componentType, E[] reusableArray, int newLength, boolean growOnly, Supplier<E> newAllocator)
    • 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

      public static <L extends List<E>, E> L arrayCopy(L to, List<? extends E> from)
      Copies all elements from the source array to the target. Clears target before populating.
      Returns:
      The target array.
    • arrayCopy

      public static <E> E[] arrayCopy(E[] to, List<? extends E> from)
      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

      public static <L extends List<E>, E, S> L arrayConvert(L to, List<S> from, Function<S,E> converter)
      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

      public static <E> boolean isNullOrEmpty(List<E> list)
    • isNullOrEmpty

      public static <E> boolean isNullOrEmpty(Iterable<E> it)
    • getOrDefault

      public static <E> E getOrDefault(List<E> list, int i)
      Get the array value at index. Bounds-safe: Returns null value if out of bounds.
    • getOrDefault

      public static <E> E getOrDefault(List<E> list, int i, E defaultVal)
      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

      public static <E> E[] arrayPopulate(E[] arr, Supplier<E> supplier)
    • insertAt

      public static void insertAt(int[] arr, int insertAt, int val)
    • insertAt

      public static void insertAt(float[] arr, int insertAt, float val)
    • toArray

      public static <E> E[] toArray(List<E> list)
    • 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

      public static <E> void forEach(List<E> list, Consumer<? super E> consumer)
      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

      public static <E> void forEach(Iterable<E> it, Consumer<? super E> consumer)
      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

      public static <E> void forEach(E[] elements, Consumer<? super E> consumer)
      Iterate over specified array, invoke supplied consumer on each element. Null-safe
    • getOrCreate

      public static <K, V> V getOrCreate(HashMap<K,V> map, K key, Supplier<V> allocator)
    • sort

      public static <E> void sort(Stack<E> stack, Comparator<E> comparator)
    • sequenceEqual

      public static <E> boolean sequenceEqual(E[] a, List<? extends E> b)
    • sequenceEqual

      public static <E> boolean sequenceEqual(E[] a, List<? extends E> b, Comparator<E> comparator)
    • sequenceEqual

      public static <E> boolean sequenceEqual(List<? extends E> a, List<? extends E> b)
    • 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)