Package rife.tools

Class ArrayUtils

java.lang.Object
rife.tools.ArrayUtils

public final class ArrayUtils extends Object
General purpose class containing common array manipulation methods.
Since:
1.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean[]
    Creates an array of booleans from an array of objects.
    static byte[]
    Creates an array of bytes from an array of objects.
    static char[]
    Creates an array of chars from an array of objects.
    static double[]
    Creates an array of doubles from an array of objects.
    static float[]
    Creates an array of floats from an array of objects.
    static int[]
    Creates an array of ints from an array of objects.
    static long[]
    Creates an array of longs from an array of objects.
    static short[]
    Creates an array of shorts from an array of objects.
    static String[]
    createStringArray(boolean[] array)
    Creates a new string array containing formatted string values of the input boolean array.
    static String[]
    createStringArray(boolean[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input boolean array.
    static String[]
    createStringArray(byte[] array)
    Creates a new string array containing formatted string values of the input byte array.
    static String[]
    createStringArray(byte[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input byte array.
    static String[]
    createStringArray(char[] array)
    Creates a new string array containing formatted string values of the input char array.
    static String[]
    createStringArray(char[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input char array.
    static String[]
    createStringArray(double[] array)
    Creates a new string array containing formatted string values of the input double array.
    static String[]
    createStringArray(double[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input double array.
    static String[]
    createStringArray(float[] array)
    Creates a new string array containing formatted string values of the input float array.
    static String[]
    createStringArray(float[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input float array.
    static String[]
    createStringArray(int[] array)
    Creates a new string array containing formatted string values of the input int array.
    static String[]
    createStringArray(int[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input int array.
    static String[]
    createStringArray(long[] array)
    Creates a new string array containing formatted string values of the input long array.
    static String[]
    createStringArray(long[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input long array.
    static String[]
    createStringArray(short[] array)
    Creates a new string array containing formatted string values of the input short array.
    static String[]
    createStringArray(short[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input short array.
    static String[]
    Creates a new string array containing formatted string values of the input object array.
    static String[]
    createStringArray(Object[] array, ConstrainedProperty constrainedProperty)
    Creates a new string array containing formatted string values of the input object array.
    static String[]
    createStringArray(Object source, ConstrainedProperty constrainedProperty)
    Convert an Object to a textual representation in a String array.
    Determines the type of the array based on the object's class name.
    static boolean[]
    join(boolean[] first, boolean second)
    Joins a single boolean and a boolean array into a new array containing all elements.
    static boolean[]
    join(boolean[] first, boolean[] second)
    Joins two boolean arrays into a new array containing all elements from both arrays.
    static byte[]
    join(byte[] first, byte second)
    Joins a single byte and a byte array into a new array containing all elements.
    static byte[]
    join(byte[] first, byte[] second)
    Joins two byte arrays into a new array containing all elements from both arrays.
    static char[]
    join(char[] first, char second)
    Joins a single char and a char array into a new array containing all elements.
    static char[]
    join(char[] first, char[] second)
    Joins two char arrays into a new array containing all elements from both arrays.
    static double[]
    join(double[] first, double second)
    Joins a single double and a double array into a new array containing all elements.
    static double[]
    join(double[] first, double[] second)
    Joins two double arrays into a new array containing all elements from both arrays.
    static float[]
    join(float[] first, float second)
    Joins a single float and a float array into a new array containing all elements.
    static float[]
    join(float[] first, float[] second)
    Joins two float arrays into a new array containing all elements from both arrays.
    static int[]
    join(int[] first, int second)
    Joins a single int and an int array into a new array containing all elements.
    static int[]
    join(int[] first, int[] second)
    Joins two int arrays into a new array containing all elements from both arrays.
    static long[]
    join(long[] first, long second)
    Joins a single long and a long array into a new array containing all elements.
    static long[]
    join(long[] first, long[] second)
    Joins two long arrays into a new array containing all elements from both arrays.
    static short[]
    join(short[] first, short second)
    Joins a single short and a short array into a new array containing all elements.
    static short[]
    join(short[] first, short[] second)
    Joins two short arrays into a new array containing all elements from both arrays.
    static String[]
    join(String[] first, String second)
    Joins a single String and a String array into a new array containing all elements.
    static String[]
    join(String[] first, String[] second)
    Joins two String arrays into a new array containing all elements from both arrays.

    Methods inherited from class java.lang.Object

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

    • getArrayType

      public static ArrayUtils.ArrayType getArrayType(Object object)
      Determines the type of the array based on the object's class name.
      Parameters:
      object - the object to check if it is an array
      Returns:
      an ArrayType value indicating the type of the array, or NO_ARRAY if object is not an array
      Throws:
      NullPointerException - if object is null
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(Object source, ConstrainedProperty constrainedProperty)
      Convert an Object to a textual representation in a String array.

      Note that array of type byte[] are explicitly not converted since that would result in many binary data to create OutOfMemoryError exceptions.

      Parameters:
      source - The Object to convert.
      Returns:
      The resulting String array; or

      null if source is null.

      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(Object[] array)
      Creates a new string array containing formatted string values of the input object array.
      Parameters:
      array - the input object array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input object array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(Object[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input object array.
      Parameters:
      array - the input object array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input object array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(boolean[] array)
      Creates a new string array containing formatted string values of the input boolean array.
      Parameters:
      array - the input boolean array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input boolean array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(boolean[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input boolean array.
      Parameters:
      array - the input boolean array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input boolean array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(byte[] array)
      Creates a new string array containing formatted string values of the input byte array.
      Parameters:
      array - the input byte array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input byte array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(byte[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input byte array.
      Parameters:
      array - the input byte array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input byte array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(char[] array)
      Creates a new string array containing formatted string values of the input char array.
      Parameters:
      array - the input char array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input char array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(char[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input char array.
      Parameters:
      array - the input char array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input char array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(short[] array)
      Creates a new string array containing formatted string values of the input short array.
      Parameters:
      array - the input short array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input short array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(short[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input short array.
      Parameters:
      array - the input short array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input short array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(int[] array)
      Creates a new string array containing formatted string values of the input int array.
      Parameters:
      array - the input int array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input int array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(int[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input int array.
      Parameters:
      array - the input int array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input int array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(long[] array)
      Creates a new string array containing formatted string values of the input long array.
      Parameters:
      array - the input long array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input long array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(long[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input long array.
      Parameters:
      array - the input long array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input long array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(float[] array)
      Creates a new string array containing formatted string values of the input float array.
      Parameters:
      array - the input float array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input float array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(float[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input float array.
      Parameters:
      array - the input float array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input float array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(double[] array)
      Creates a new string array containing formatted string values of the input double array.
      Parameters:
      array - the input double array, can be empty or null
      Returns:
      a new string array containing formatted string values of the input double array
      Since:
      1.0
    • createStringArray

      public static String[] createStringArray(double[] array, ConstrainedProperty constrainedProperty)
      Creates a new string array containing formatted string values of the input double array.
      Parameters:
      array - the input double array, can be empty or null
      constrainedProperty - the optional ConstrainedProperty object containing constraints for formatting the property value
      Returns:
      a new string array containing formatted string values of the input double array
      Since:
      1.0
    • createBooleanArray

      public static boolean[] createBooleanArray(Object[] array)
      Creates an array of booleans from an array of objects.
      Parameters:
      array - the array to create a boolean array from
      Returns:
      a new boolean array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createByteArray

      public static byte[] createByteArray(Object[] array)
      Creates an array of bytes from an array of objects.
      Parameters:
      array - the array to create a byte array from
      Returns:
      a new byte array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createCharArray

      public static char[] createCharArray(Object[] array)
      Creates an array of chars from an array of objects.
      Parameters:
      array - the array to create a char array from
      Returns:
      a new char array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createShortArray

      public static short[] createShortArray(Object[] array)
      Creates an array of shorts from an array of objects.
      Parameters:
      array - the array to create a short array from
      Returns:
      a new short array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createIntArray

      public static int[] createIntArray(Object[] array)
      Creates an array of ints from an array of objects.
      Parameters:
      array - the array to create an int array from
      Returns:
      a new int array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createLongArray

      public static long[] createLongArray(Object[] array)
      Creates an array of longs from an array of objects.
      Parameters:
      array - the array to create a long array from
      Returns:
      a new long array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createFloatArray

      public static float[] createFloatArray(Object[] array)
      Creates an array of floats from an array of objects.
      Parameters:
      array - the array to create a float array from
      Returns:
      a new float array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • createDoubleArray

      public static double[] createDoubleArray(Object[] array)
      Creates an array of doubles from an array of objects.
      Parameters:
      array - the array to create a double array from
      Returns:
      a new double array that contains the converted values of the original array, or null if the original array is null
      Since:
      1.0
    • join

      public static String[] join(String[] first, String[] second)
      Joins two String arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first String array to join
      second - the second String array to join
      Returns:
      a new String array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static String[] join(String[] first, String second)
      Joins a single String and a String array into a new array containing all elements.
      Parameters:
      first - the String array to which to append the second String
      second - the String to append to the first array
      Returns:
      a new String array with every element of the input array and the appended String, or a new array containing only the second String if the input array is null
      Since:
      1.0
    • join

      public static byte[] join(byte[] first, byte[] second)
      Joins two byte arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first byte array to join
      second - the second byte array to join
      Returns:
      a new byte array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static byte[] join(byte[] first, byte second)
      Joins a single byte and a byte array into a new array containing all elements.
      Parameters:
      first - the byte array to which to append the second byte
      second - the byte to append to the first array
      Returns:
      a new byte array with every element of the input array and the appended byte, or a new array containing only the second byte if the input array is null
      Since:
      1.0
    • join

      public static char[] join(char[] first, char[] second)
      Joins two char arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first char array to join
      second - the second char array to join
      Returns:
      a new char array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static char[] join(char[] first, char second)
      Joins a single char and a char array into a new array containing all elements.
      Parameters:
      first - the char array to which to append the second char
      second - the char to append to the first array
      Returns:
      a new char array with every element of the input array and the appended char, or a new array containing only the second char if the input array is null
      Since:
      1.0
    • join

      public static short[] join(short[] first, short[] second)
      Joins two short arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first short array to join
      second - the second short array to join
      Returns:
      a new short array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static short[] join(short[] first, short second)
      Joins a single short and a short array into a new array containing all elements.
      Parameters:
      first - the short array to which to append the second short
      second - the short to append to the first array
      Returns:
      a new short array with every element of the input array and the appended short, or a new array containing only the second short if the input array is null
      Since:
      1.0
    • join

      public static int[] join(int[] first, int[] second)
      Joins two int arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first int array to join
      second - the second int array to join
      Returns:
      a new int array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static int[] join(int[] first, int second)
      Joins a single int and an int array into a new array containing all elements.
      Parameters:
      first - the int array to which to append the second int
      second - the int to append to the first array
      Returns:
      a new int array with every element of the input array and the appended int, or a new array containing only the second int if the input array is null
      Since:
      1.0
    • join

      public static long[] join(long[] first, long[] second)
      Joins two long arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first long array to join
      second - the second long array to join
      Returns:
      a new long array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static long[] join(long[] first, long second)
      Joins a single long and a long array into a new array containing all elements.
      Parameters:
      first - the long array to which to append the second long
      second - the long to append to the first array
      Returns:
      a new long array with every element of the input array and the appended long, or a new array containing only the second long if the input array is null
      Since:
      1.0
    • join

      public static float[] join(float[] first, float[] second)
      Joins two float arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first float array to join
      second - the second float array to join
      Returns:
      a new float array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static float[] join(float[] first, float second)
      Joins a single float and a float array into a new array containing all elements.
      Parameters:
      first - the float array to which to append the second float
      second - the float to append to the first array
      Returns:
      a new float array with every element of the input array and the appended float, or a new array containing only the second float if the input array is null
      Since:
      1.0
    • join

      public static double[] join(double[] first, double[] second)
      Joins two double arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first double array to join
      second - the second double array to join
      Returns:
      a new double array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static double[] join(double[] first, double second)
      Joins a single double and a double array into a new array containing all elements.
      Parameters:
      first - the double array to which to append the second double
      second - the double to append to the first array
      Returns:
      a new double array with every element of the input array and the appended double, or a new array containing only the second double if the input array is null
      Since:
      1.0
    • join

      public static boolean[] join(boolean[] first, boolean[] second)
      Joins two boolean arrays into a new array containing all elements from both arrays.
      Parameters:
      first - the first boolean array to join
      second - the second boolean array to join
      Returns:
      a new boolean array with every element of both input arrays, or null if both inputs are null
      Since:
      1.0
    • join

      public static boolean[] join(boolean[] first, boolean second)
      Joins a single boolean and a boolean array into a new array containing all elements.
      Parameters:
      first - the boolean array to which to append the second boolean
      second - the boolean to append to the first array
      Returns:
      a new boolean array with every element of the input array and the appended boolean, or a new array containing only the second boolean if the input array is null
      Since:
      1.0