org.geotoolkit.util
Class XArrays

Object
  extended by Static
      extended by XArrays

public final class XArrays
extends Static

Simple operations on arrays. This class provides a central place for inserting and deleting elements in an array, as well as resizing the array.

The resize methods provided in this class are very similar to the copyOf methods provided in Arrays since Java 6, except that they accept null arrays and do not copy anything if the given array already has the requested length.

Since:
2.0
Version:
3.20
Author:
Martin Desruisseaux (IRD, Geomatys)
See Also:
Arrays
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
static boolean[] EMPTY_BOOLEAN
          An empty array of boolean primitive type.
static byte[] EMPTY_BYTE
          An empty array of byte primitive type.
static char[] EMPTY_CHAR
          An empty array of char primitive type.
static double[] EMPTY_DOUBLE
          An empty array of double primitive type.
static float[] EMPTY_FLOAT
          An empty array of float primitive type.
static int[] EMPTY_INT
          An empty array of int primitive type.
static long[] EMPTY_LONG
          An empty array of long primitive type.
static short[] EMPTY_SHORT
          An empty array of short primitive type.
 
Method Summary
static boolean allEquals(double[] array, double value)
          Returns true if all values in the specified array are equal to the specified value, which may be Double.NaN.
static boolean allEquals(float[] array, float value)
          Returns true if all values in the specified array are equal to the specified value, which may be Float.NaN.
static
<T> T[]
append(T[] array, T element)
          Returns a copy of the given array with a single element appended at the end.
static
<T> T[]
concatenate(T[]... arrays)
          Returns the concatenation of all given arrays.
static boolean contains(Object[] array, Object value)
          Returns true if the specified array contains the specified value.
static boolean containsIdentity(Object[] array, Object value)
          Returns true if the specified array contains the specified reference.
static boolean containsIgnoreCase(String[] array, String value)
          Returns true if the specified array contains the specified value, ignoring case.
static float[] copyAsFloats(double[] data)
          Returns a copy of the given array where each value has been casted to the float type.
static int[] copyAsInts(double[] data)
          Returns a copy of the given array where each value has been rounded to the int type.
static boolean hasNaN(double[] array)
          Returns true if the specified array contains at least one NaN value.
static boolean hasNaN(float[] array)
          Returns true if the specified array contains at least one NaN value.
static boolean[] insert(boolean[] src, int srcOff, boolean[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static boolean[] insert(boolean[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static byte[] insert(byte[] src, int srcOff, byte[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static byte[] insert(byte[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static char[] insert(char[] src, int srcOff, char[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static char[] insert(char[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static double[] insert(double[] src, int srcOff, double[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static double[] insert(double[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static
<E> E[]
insert(E[] src, int srcOff, E[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static
<E> E[]
insert(E[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static float[] insert(float[] src, int srcOff, float[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static float[] insert(float[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static int[] insert(int[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static int[] insert(int[] src, int srcOff, int[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static long[] insert(long[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static long[] insert(long[] src, int srcOff, long[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static short[] insert(short[] array, int first, int length)
          Returns an array containing the same elements than the given array, with additional "spaces" in the given range.
static short[] insert(short[] src, int srcOff, short[] dst, int dstOff, int length)
          Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.
static boolean intersects(Object[] array1, Object[] array2)
          Returns true if at least one element in the first array is equals to an element in the second array.
static boolean isSorted(byte[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(char[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(double[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static
<E> boolean
isSorted(E[] array, Comparator<E> comparator, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(float[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(int[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(long[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean isSorted(short[] array, boolean strict)
          Returns true if all elements in the specified array are in increasing order.
static boolean[] remove(boolean[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static byte[] remove(byte[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static char[] remove(char[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static double[] remove(double[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static
<E> E[]
remove(E[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static float[] remove(float[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static int[] remove(int[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static long[] remove(long[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static short[] remove(short[] array, int first, int length)
          Returns an array containing the same elements than the given array except for the given range.
static boolean[] resize(boolean[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with false if necessary.
static byte[] resize(byte[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static char[] resize(char[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static double[] resize(double[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static
<E> E[]
resize(E[] array, int length)
          Returns an array containing the same elements as the given array but with the specified length, truncating or padding with null if necessary.
static float[] resize(float[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static int[] resize(int[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static long[] resize(long[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static short[] resize(short[] array, int length)
          Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.
static void reverse(Object[] entries)
          Reverses the order of elements in the given array.
static int[] union(int[] array1, int[] array2)
          Returns the union of two sorted arrays.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_DOUBLE

public static final double[] EMPTY_DOUBLE
An empty array of double primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_FLOAT

public static final float[] EMPTY_FLOAT
An empty array of float primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_LONG

public static final long[] EMPTY_LONG
An empty array of long primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_INT

public static final int[] EMPTY_INT
An empty array of int primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_SHORT

public static final short[] EMPTY_SHORT
An empty array of short primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_BYTE

public static final byte[] EMPTY_BYTE
An empty array of byte primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_CHAR

public static final char[] EMPTY_CHAR
An empty array of char primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20

EMPTY_BOOLEAN

public static final boolean[] EMPTY_BOOLEAN
An empty array of boolean primitive type. Such arrays are immutable and can be safely shared.

Since:
3.20
Method Detail

resize

public static <E> E[] resize(E[] array,
                             int length)
Returns an array containing the same elements as the given array but with the specified length, truncating or padding with null if necessary.

resize

public static double[] resize(double[] array,
                              int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(double[],int)

resize

public static float[] resize(float[] array,
                             int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(float[],int)

resize

public static long[] resize(long[] array,
                            int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(long[],int)

resize

public static int[] resize(int[] array,
                           int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(int[],int)

resize

public static short[] resize(short[] array,
                             int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(short[],int)

resize

public static byte[] resize(byte[] array,
                            int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(byte[],int)

resize

public static char[] resize(char[] array,
                            int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with zeros if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(char[],int)

resize

public static boolean[] resize(boolean[] array,
                               int length)
Returns an array containing the same elements as the given array but specified length, truncating or padding with false if necessary.

Parameters:
array - Array to resize, or null.
length - Length of the desired array.
Returns:
A new array of the requested length, or array if the given array is null or already have the requested length.
See Also:
Arrays.copyOf(boolean[],int)

remove

public static <E> E[] remove(E[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Type Parameters:
E - The type of array elements.
Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static double[] remove(double[] array,
                              int first,
                              int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static float[] remove(float[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static long[] remove(long[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static int[] remove(int[] array,
                           int first,
                           int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static short[] remove(short[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static byte[] remove(byte[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static char[] remove(char[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

remove

public static boolean[] remove(boolean[] array,
                               int first,
                               int length)
Returns an array containing the same elements than the given array except for the given range. If the length argument is 0, then this method returns the array reference unchanged (except if empty). Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array from which to remove elements.
first - Index of the first element to remove from the given array.
length - Number of elements to remove.
Returns:
Array with the same elements than the given array except for the removed elements, or array if length is 0.

insert

public static <E> E[] insert(E[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of null elements.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Type Parameters:
E - The type of array elements.
Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static double[] insert(double[] array,
                              int first,
                              int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static float[] insert(float[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static long[] insert(long[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static int[] insert(int[] array,
                           int first,
                           int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static short[] insert(short[] array,
                             int first,
                             int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static byte[] insert(byte[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static char[] insert(char[] array,
                            int first,
                            int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to zero.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static boolean[] insert(boolean[] array,
                               int first,
                               int length)
Returns an array containing the same elements than the given array, with additional "spaces" in the given range. These "spaces" will be made up of elements initialized to false.

If the length argument is 0, then this method returns the array reference unchanged. Otherwise this method creates a new array. In every cases, the given array is never modified.

Parameters:
array - Array in which to insert spaces.
first - Index where the first space should be inserted. All array elements having an index equal to or higher than index will be moved forward.
length - Number of spaces to insert.
Returns:
Array containing the array elements with the additional space inserted, or array if length is 0.

insert

public static <E> E[] insert(E[] src,
                             int srcOff,
                             E[] dst,
                             int dstOff,
                             int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Type Parameters:
E - The type of array elements.
Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static double[] insert(double[] src,
                              int srcOff,
                              double[] dst,
                              int dstOff,
                              int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static float[] insert(float[] src,
                             int srcOff,
                             float[] dst,
                             int dstOff,
                             int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static long[] insert(long[] src,
                            int srcOff,
                            long[] dst,
                            int dstOff,
                            int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static int[] insert(int[] src,
                           int srcOff,
                           int[] dst,
                           int dstOff,
                           int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static short[] insert(short[] src,
                             int srcOff,
                             short[] dst,
                             int dstOff,
                             int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static byte[] insert(byte[] src,
                            int srcOff,
                            byte[] dst,
                            int dstOff,
                            int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static char[] insert(char[] src,
                            int srcOff,
                            char[] dst,
                            int dstOff,
                            int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

insert

public static boolean[] insert(boolean[] src,
                               int srcOff,
                               boolean[] dst,
                               int dstOff,
                               int length)
Returns an array containing the same elements than the given array, with the content of an other array inserted at the given index.

If the length argument is 0, then this method returns the dst reference unchanged. Otherwise this method creates a new array. In every cases, the given arrays are never modified.

Parameters:
src - Array to entirely or partially insert into dst.
srcOff - Index of the first element of src to insert into dst.
dst - Array in which to insert src data.
dstOff - Index of the first element in dst where to insert src data. All elements of dst whose index is equal to or greater than dstOff will be moved forward.
length - Number of src elements to insert.
Returns:
Array which contains the merge of src and dst. This method returns directly dst when length is zero, but never return src.

append

public static <T> T[] append(T[] array,
                             T element)
Returns a copy of the given array with a single element appended at the end. This method should be invoked only on rare occasions. If many elements are to be added, use ArrayList instead.

Type Parameters:
T - The type of elements in the array.
Parameters:
array - The array to copy with a new element. The original array will not be modified.
element - The element to add (can be null).
Returns:
A copy of the given array with the given element appended at the end.
Since:
3.20
See Also:
concatenate(Object[][])

reverse

public static void reverse(Object[] entries)
Reverses the order of elements in the given array. This operation is performed in-place.

Parameters:
entries - The array in which to reverse the order of elements.
Since:
3.11

copyAsFloats

public static float[] copyAsFloats(double[] data)
Returns a copy of the given array where each value has been casted to the float type.

Parameters:
data - The array to copy, or null.
Returns:
A copy of the given array with values casted to the float type, or null if the given array was null.

copyAsInts

public static int[] copyAsInts(double[] data)
Returns a copy of the given array where each value has been rounded to the int type.

Parameters:
data - The array to copy, or null.
Returns:
A copy of the given array with values rounded to the int type, or null if the given array was null.

isSorted

public static <E> boolean isSorted(E[] array,
                                   Comparator<E> comparator,
                                   boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Type Parameters:
E - The type of array elements.
Parameters:
array - The array to test for order.
comparator - The comparator to use for comparing order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(double[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. Since NaN values are unordered, they may appears anywhere in the array; they will be ignored. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(float[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. Since NaN values are unordered, they may appears anywhere in the array; they will be ignored. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(long[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(int[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(short[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(byte[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

isSorted

public static boolean isSorted(char[] array,
                               boolean strict)
Returns true if all elements in the specified array are in increasing order. This method is useful in assertions.

Parameters:
array - The array to test for order.
strict - true if elements should be strictly sorted (i.e. equal elements are not allowed}, or false otherwise.
Returns:
true if all elements in the given array are sorted in increasing order.

allEquals

public static boolean allEquals(double[] array,
                                double value)
Returns true if all values in the specified array are equal to the specified value, which may be Double.NaN.

Parameters:
array - The array to check.
value - The expected value.
Returns:
true if all elements in the given array are equal to the given value.

allEquals

public static boolean allEquals(float[] array,
                                float value)
Returns true if all values in the specified array are equal to the specified value, which may be Float.NaN.

Parameters:
array - The array to check.
value - The expected value.
Returns:
true if all elements in the given array are equal to the given value.

hasNaN

public static boolean hasNaN(double[] array)
Returns true if the specified array contains at least one NaN value.

Parameters:
array - The array to check.
Returns:
true if the given array contains at least one NaN value.

hasNaN

public static boolean hasNaN(float[] array)
Returns true if the specified array contains at least one NaN value.

Parameters:
array - The array to check.
Returns:
true if the given array contains at least one NaN value.

containsIgnoreCase

public static boolean containsIgnoreCase(String[] array,
                                         String value)
Returns true if the specified array contains the specified value, ignoring case. This method should be used only for very small arrays.

Parameters:
array - The array to search in. May be null.
value - The value to search.
Returns:
true if the array is non-null and contains the given value, or false otherwise.

containsIdentity

public static boolean containsIdentity(Object[] array,
                                       Object value)
Returns true if the specified array contains the specified reference. The comparisons are performed using the == operator.

This method should be used only for very small arrays, or for searches to be performed only once, because it performs a linear search. If more than one search need to be done on the same array, consider using IdentityHashMap instead.

Parameters:
array - The array to search in. May be null and may contains null elements.
value - The value to search. May be null.
Returns:
true if the array is non-null and contains the value (which may be null), or false otherwise.
Since:
3.17

contains

public static boolean contains(Object[] array,
                               Object value)
Returns true if the specified array contains the specified value. The comparisons are performed using the Object.equals(Object) method.

This method should be used only for very small arrays, or for searches to be performed only once, because it performs a linear search. If more than one search need to be done on the same array, consider using HashSet instead.

Parameters:
array - The array to search in. May be null and may contains null elements.
value - The value to search. May be null.
Returns:
true if the array is non-null and contains the value (which may be null), or false otherwise.

intersects

public static boolean intersects(Object[] array1,
                                 Object[] array2)
Returns true if at least one element in the first array is equals to an element in the second array. The element doesn't need to be at the same index in both array.

This method should be used only for very small arrays since it may be very slow. If the arrays are large or if an array will be involved in more than one search, consider using HashSet instead.

Parameters:
array1 - The first array.
array2 - The second array.
Returns:
true if both array have at least one element in common.

concatenate

public static <T> T[] concatenate(T[]... arrays)
Returns the concatenation of all given arrays. This method performs the following checks:

Type Parameters:
T - The type of arrays.
Parameters:
arrays - The arrays to concatenate, or null.
Returns:
The concatenation of all non-null arrays (may be a direct reference to one of the given array if it can be returned with no change), or null.
Since:
3.07
See Also:
append(Object[], Object)

union

public static int[] union(int[] array1,
                          int[] array2)
Returns the union of two sorted arrays. The input arrays shall be sorted in strictly increasing order (for performance raison, this is verified only if assertions are enabled). The output array is the union of the input arrays without duplicated values, with elements in strictly increasing order.

Parameters:
array1 - The first array.
array2 - The second array.
Returns:
The union of the given array without duplicated values.
Since:
3.04


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.