java.lang.Object
org.bzdev.util.ArrayMerger
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
concat
(byte[]... args) Concatenate byte arrays to produce a new arraystatic char[]
concat
(char[]... args) Concatenate char arrays to produce a new arraystatic double[]
concat
(double[]... args) Concatenate double arrays to produce a new arraystatic float[]
concat
(float[]... args) Concatenate float arrays to produce a new arraystatic int[]
concat
(int[]... args) Concatenate int arrays to produce a new arraystatic long[]
concat
(long[]... args) Concatenate long arrays to produce a new arraystatic short[]
concat
(short[]... args) Concatenate short arrays to produce a new arraystatic 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.
-
Constructor Details
-
ArrayMerger
public ArrayMerger()
-
-
Method Details
-
merge
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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).
-