Class ArrayMerger

java.lang.Object
org.bzdev.util.ArrayMerger

public class ArrayMerger extends Object
Class for interleaving arrays. This class contains only static methods. Given arrays a1, a2, a3, the method ArrayMerger.merge(a1, a2, a3) will produce an array whose elements are {a1[0], a2[0], a3[0], a1[1], a2[1], a3[1], a1[2], a2[2], a3[2], ...., a1[n], a2[n], a3[n]} when a1, a2, and a3 have lengths of n+1. Another method allows shorter arrays to be generated by providing a range of indices from which the elements of the arrays should be extracted. for example, ArrayMerger.merge(1, 3, a1, a2, a3) will produce an array whose elements are {a1[1], a2[1], a3[1], a1[2], a2[2], a3[2]}.

One use of this class is to combine the arrays of (one dimensional) control points that various splines can generate and create an array formatted as required by methods used by Path2D or Path3D and their subclasses.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    concat(byte[]... args)
    Concatenate byte arrays to produce a new array
    static char[]
    concat(char[]... args)
    Concatenate char arrays to produce a new array
    static double[]
    concat(double[]... args)
    Concatenate double arrays to produce a new array
    static float[]
    concat(float[]... args)
    Concatenate float arrays to produce a new array
    static int[]
    concat(int[]... args)
    Concatenate int arrays to produce a new array
    static long[]
    concat(long[]... args)
    Concatenate long arrays to produce a new array
    static short[]
    concat(short[]... args)
    Concatenate short arrays to produce a new array
    static byte[]
    merge(byte[]... args)
    Merge multiple arrays of byte.
    static char[]
    merge(char[]... args)
    Merge multiple arrays of char.
    static double[]
    merge(double[]... args)
    Merge multiple arrays of double.
    static float[]
    merge(float[]... args)
    Merge multiple arrays of float.
    static int[]
    merge(int[]... args)
    Merge multiple arrays of int.
    static byte[]
    merge(int start, int end, byte[]... args)
    Merge a range of elements from multiple arrays of byte.
    static char[]
    merge(int start, int end, char[]... args)
    Merge a range of elements from multiple arrays of char.
    static double[]
    merge(int start, int end, double[]... args)
    Merge a range of elements from multiple arrays of double.
    static float[]
    merge(int start, int end, float[]... args)
    Merge a range of elements from multiple arrays of float.
    static int[]
    merge(int start, int end, int[]... args)
    Merge a range of elements from multiple arrays of int.
    static long[]
    merge(int start, int end, long[]... args)
    Merge a range of elements from multiple arrays of long.
    static short[]
    merge(int start, int end, short[]... args)
    Merge a range of elements from multiple arrays of short.
    static long[]
    merge(long[]... args)
    Merge multiple arrays of long.
    static short[]
    merge(short[]... args)
    Merge multiple arrays of short.

    Methods inherited from class java.lang.Object

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

    • ArrayMerger

      public ArrayMerger()
  • Method Details

    • merge

      public static double[] merge(double[]... args) throws IllegalArgumentException
      Merge multiple arrays of double. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static double[] merge(int start, int end, double[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of double. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static int[] merge(int[]... args) throws IllegalArgumentException
      Merge multiple arrays of int. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static int[] merge(int start, int end, int[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of int. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static short[] merge(short[]... args) throws IllegalArgumentException
      Merge multiple arrays of short. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static short[] merge(int start, int end, short[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of short. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static long[] merge(long[]... args) throws IllegalArgumentException
      Merge multiple arrays of long. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static long[] merge(int start, int end, long[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of long. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static float[] merge(float[]... args) throws IllegalArgumentException
      Merge multiple arrays of float. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static float[] merge(int start, int end, float[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of float. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static char[] merge(char[]... args) throws IllegalArgumentException
      Merge multiple arrays of char. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static char[] merge(int start, int end, char[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of char. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • merge

      public static byte[] merge(byte[]... args) throws IllegalArgumentException
      Merge multiple arrays of byte. The elements are placed into the output array starting with the first element of the first argument, then the first element of the second argument, etc., until an element has been used from each argument array. This is then repeated for the second element of each argument array, etc.
      Parameters:
      args - the arrays to merge
      Returns:
      an array containing the elements of the argument arrays
      Throws:
      IllegalArgumentException
    • merge

      public static byte[] merge(int start, int end, byte[]... args) throws IllegalArgumentException
      Merge a range of elements from multiple arrays of byte. The elements are placed into the output array starting with the element whose index is 'start' for the first argument, then the element whose index is 'start' for the second argument, etc., until an element has been used from each argument array. This is then repeated for the next element of each argument array, etc. as long as the elements' indices are less than 'end'.
      Parameters:
      start - the starting offset into the arrays (inclusive)
      end - the ending offset into the arrays (exclusive)
      args - a variable number of arrays
      Returns:
      an array in which the elements of args are interleaved
      Throws:
      IllegalArgumentException
    • concat

      public static int[] concat(int[]... args) throws IllegalArgumentException
      Concatenate int arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static byte[] concat(byte[]... args) throws IllegalArgumentException
      Concatenate byte arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static short[] concat(short[]... args) throws IllegalArgumentException
      Concatenate short arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static long[] concat(long[]... args) throws IllegalArgumentException
      Concatenate long arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static float[] concat(float[]... args) throws IllegalArgumentException
      Concatenate float arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static char[] concat(char[]... args) throws IllegalArgumentException
      Concatenate char arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).
    • concat

      public static double[] concat(double[]... args) throws IllegalArgumentException
      Concatenate double arrays to produce a new array
      Parameters:
      args - the arrays
      Returns:
      the concatenation of the argument arrays
      Throws:
      IllegalArgumentException - the array size would be too large (this tests that the array size fits in a 32-bit integer; A JVM may impose lower limits).