Class ArrayUtil

java.lang.Object
org.seppiko.commons.utils.ArrayUtil

public class ArrayUtil extends Object
Array utility
Author:
Leonard Woo
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    allocate(int capacity, Class<T> type)
    It will have a backing array, and its array offset will be zero.
    static Object[]
    Get Supplier object with not null array.
    static <T> boolean
    isArray(T obj)
    Returns true if the provided reference is array, otherwise returns false.
    static boolean
    isEmpty(boolean[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(byte[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(double[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(float[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(int[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(long[] array)
    Returns true if the array is null, otherwise returns false.
    static boolean
    isEmpty(short[] array)
    Returns true if the array is null, otherwise returns false.
    static <T> boolean
    isEmpty(T[] array)
    Returns true if the array is null, otherwise returns false.
    static <T> boolean
    isNull(T[] obj)
    Returns true if the provided reference is null, otherwise returns false.
    static <T> boolean
    nonNull(T[] obj)
    Returns true if the provided reference is non-null, otherwise returns false.
    static <T> T[]
    swap(T[] oriTs, int a, int b)
    Swap T array index a and b.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isArray

      public static <T> boolean isArray(T obj)
      Returns true if the provided reference is array, otherwise returns false.
      Type Parameters:
      T - reference type.
      Parameters:
      obj - a reference to be checked against.
      Returns:
      true if the provided reference is array, otherwise false.
    • isEmpty

      public static <T> boolean isEmpty(T[] array)
      Returns true if the array is null, otherwise returns false.
      Type Parameters:
      T - reference type.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(boolean[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(byte[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(short[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(int[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(long[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(float[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isEmpty

      public static boolean isEmpty(double[] array)
      Returns true if the array is null, otherwise returns false.
      Parameters:
      array - a reference to be checked against.
      Returns:
      true if the provided array is null, otherwise false.
    • isNull

      public static <T> boolean isNull(T[] obj)
      Returns true if the provided reference is null, otherwise returns false.
      Type Parameters:
      T - reference type.
      Parameters:
      obj - a reference to be checked against null.
      Returns:
      true if the provided reference is null, otherwise false.
    • nonNull

      public static <T> boolean nonNull(T[] obj)
      Returns true if the provided reference is non-null, otherwise returns false.
      Type Parameters:
      T - reference type.
      Parameters:
      obj - a reference to be checked against null.
      Returns:
      true if the provided reference is non-null, otherwise false.
    • 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

      public static Object[] getSuppliers(Supplier<Object>[] suppliers) throws NullPointerException
      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 - the Class object representing the component type of the new array.
      Returns:
      the new array.
      Throws:
      IllegalArgumentException - if the type is Void.TYPE.
      NullPointerException - if the specified type parameter is null.