Class XArray
realloc.- Since:
- 2.0
- Author:
- Martin Desruisseaux (IRD)
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallEquals(double[] array, double value) Returnstrueif all values in the specified array are equals to the specified value, which may beDouble.NaN.static booleanallEquals(float[] array, float value) Returnstrueif all values in the specified array are equals to the specified value, which may beFloat.NaN.static booleanReturnstrueif the specified array contains the specified value.static booleancontainsIgnoreCase(String[] array, String value) Returnstrueif the specified array contains the specified value, ignoring case.static booleanhasNaN(double[] array) Returnstrueif the specified array contains at least oneNaNvalue.static booleanhasNaN(float[] array) Returnstrueif the specified array contains at least oneNaNvalue.static boolean[]insert(boolean[] src, int src_pos, boolean[] dst, int dst_pos, int length) Inserts a table slice into another table.static boolean[]insert(boolean[] array, int index, int length) Inserts spaces into the middle of an array.static byte[]insert(byte[] src, int src_pos, byte[] dst, int dst_pos, int length) Inserts a table slice into another table.static byte[]insert(byte[] array, int index, int length) Inserts spaces into the middle of an array.static char[]insert(char[] src, int src_pos, char[] dst, int dst_pos, int length) Inserts a table slice into another table.static char[]insert(char[] array, int index, int length) Inserts spaces into the middle of an array.static double[]insert(double[] src, int src_pos, double[] dst, int dst_pos, int length) Inserts a table slice into another table.static double[]insert(double[] array, int index, int length) Inserts spaces into the middle of an array.static float[]insert(float[] src, int src_pos, float[] dst, int dst_pos, int length) Inserts a table slice into another table.static float[]insert(float[] array, int index, int length) Inserts spaces into the middle of an array.static int[]insert(int[] array, int index, int length) Inserts spaces into the middle of an array.static int[]insert(int[] src, int src_pos, int[] dst, int dst_pos, int length) Inserts a table slice into another table.static long[]insert(long[] array, int index, int length) Inserts spaces into the middle of an array.static long[]insert(long[] src, int src_pos, long[] dst, int dst_pos, int length) Inserts a table slice into another table.static short[]insert(short[] array, int index, int length) Inserts spaces into the middle of an array.static short[]insert(short[] src, int src_pos, short[] dst, int dst_pos, int length) Inserts a table slice into another table.static <E> E[]insert(E[] array, int index, int length) Inserts spaces into the middle of an array.static <E> E[]insert(E[] src, int src_pos, E[] dst, int dst_pos, int length) Inserts a table slice into another table.static booleanintersects(Object[] array1, Object[] array2) Returnstrueif at least one element in the first array is equals to an element in the second array.static booleanisSorted(byte[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(char[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(double[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(float[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(int[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(long[] array) Returnstrueif all elements in the specified array are in increasing order.static booleanisSorted(short[] array) Returnstrueif all elements in the specified array are in increasing order.static <T> booleanisSorted(T[] array, Comparator<T> comparator) Returnstrueif all elements in the specified array are in increasing order.static booleanisStrictlySorted(int[] array) Returnstrueif all elements in the specified array are in strictly increasing order.static boolean[]remove(boolean[] array, int index, int length) Removes elements from the middle of an array.static byte[]remove(byte[] array, int index, int length) Removes elements from the middle of an array.static char[]remove(char[] array, int index, int length) Removes elements from the middle of an array.static double[]remove(double[] array, int index, int length) Removes elements from the middle of an array.static float[]remove(float[] array, int index, int length) Removes elements from the middle of an array.static int[]remove(int[] array, int index, int length) Removes elements from the middle of an array.static long[]remove(long[] array, int index, int length) Removes elements from the middle of an array.static short[]remove(short[] array, int index, int length) Removes elements from the middle of an array.static <E> E[]remove(E[] array, int index, int length) Removes elements from the middle of an array.static boolean[]resize(boolean[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static byte[]resize(byte[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static char[]resize(char[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static double[]resize(double[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static float[]resize(float[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static int[]resize(int[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static long[]resize(long[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static short[]resize(short[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.static <E> E[]resize(E[] array, int length) Returns an array containing the same elements as the givenarraybut with the specifiedlength, truncating or padding withnullif necessary.static StringReturns a string representation of an array of numbers.
-
Method Details
-
resize
public static <E> E[] resize(E[] array, int length) Returns an array containing the same elements as the givenarraybut with the specifiedlength, truncating or padding withnullif necessary.-
If the given
lengthis longer than the length of the givenarray, then the returned array will contain all the elements ofarrayat index i <array.length. Elements at index i >=array.lengthare initialized tonull. -
If the given
lengthis shorter than the length of the givenarray, then the returned array will contain only the elements ofarrayat index i <length. Remainding elements are not copied. -
If the given
lengthis equals to the length of the givenarray, thenarrayis returned unchanged. No copy is performed. This behavior is what make this method different thanArrays#copyOf.
- Type Parameters:
E- The array elements.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length. - See Also:
-
Arrays#copyOf(Object[],int)
-
-
resize
public static double[] resize(double[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static float[] resize(float[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static long[] resize(long[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static int[] resize(int[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static short[] resize(short[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static byte[] resize(byte[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static char[] resize(char[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
resize
public static boolean[] resize(boolean[] array, int length) Returns an array containing the same elements as the givenarraybut specifiedlength, truncating or padding with zeros if necessary.- Parameters:
array- Array to copy.length- Length of the desired array.- Returns:
- A new array of the requested length, or
arrayif the original array already have the requested length.
-
remove
public static <E> E[] remove(E[] array, int index, int length) Removes elements from the middle of an array.- Type Parameters:
E- The type of array elements.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static double[] remove(double[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static float[] remove(float[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static long[] remove(long[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static int[] remove(int[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static short[] remove(short[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static byte[] remove(byte[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static char[] remove(char[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
remove
public static boolean[] remove(boolean[] array, int index, int length) Removes elements from the middle of an array.- Parameters:
array- Array from which to remove elements.index- Index of the first element to remove from the givenarray.length- Number of elements to remove.- Returns:
- Array with the same elements than the given
arrayexcept for the removed elements, orarrayiflengthis 0.
-
insert
public static <E> E[] insert(E[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized tonull.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static double[] insert(double[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static float[] insert(float[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static long[] insert(long[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static int[] insert(int[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static short[] insert(short[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static byte[] insert(byte[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static char[] insert(char[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized to zeros.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static boolean[] insert(boolean[] array, int index, int length) Inserts spaces into the middle of an array. These "spaces" will be made up of elements initialized tofalse.- Parameters:
array- Array in which to insert spaces.index- Index where the first space should be inserted. Allarrayelements having an index equal to or higher thanindexwill be moved forward.length- Number of spaces to insert.- Returns:
- Array containing the
arrayelements with the additional space inserted, orarrayiflengthis 0.
-
insert
public static <E> E[] insert(E[] src, int src_pos, E[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static double[] insert(double[] src, int src_pos, double[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static float[] insert(float[] src, int src_pos, float[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static long[] insert(long[] src, int src_pos, long[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static int[] insert(int[] src, int src_pos, int[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static short[] insert(short[] src, int src_pos, short[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static byte[] insert(byte[] src, int src_pos, byte[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static char[] insert(char[] src, int src_pos, char[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
insert
public static boolean[] insert(boolean[] src, int src_pos, boolean[] dst, int dst_pos, int length) Inserts a table slice into another table. Thesrctable will be entirely or partially inserted into thedsttable.- Parameters:
src- Tablea to insert intodst.src_pos- Index of the first data item ofsrcto insert intodst.dst- Table in which to insertsrcdata.dst_pos-dstindex in which to insertsrcdata. All elements ofdstwhose index is equal to or greater thandst_poswill be moved forward.length- Number ofsrcdata items to insert.- Returns:
- Table which contains the combination of
srcanddst. This method can directly returndst, but neversrc. It most often returns a newly created table.
-
isSorted
Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(char[] array) Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(byte[] array) Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(short[] array) Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(int[] array) Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(long[] array) Returnstrueif all elements in the specified array are in increasing order. This method is usefull in assertions. -
isSorted
public static boolean isSorted(float[] array) Returnstrueif all elements in the specified array are in increasing order. SinceNaNvalues are unordered, they may appears anywhere in the array; they will be ignored. This method is usefull in assertions. -
isSorted
public static boolean isSorted(double[] array) Returnstrueif all elements in the specified array are in increasing order. SinceNaNvalues are unordered, they may appears anywhere in the array; they will be ignored. This method is usefull in assertions. -
isStrictlySorted
public static boolean isStrictlySorted(int[] array) Returnstrueif all elements in the specified array are in strictly increasing order. This method is usefull in assertions. -
allEquals
public static boolean allEquals(float[] array, float value) Returnstrueif all values in the specified array are equals to the specified value, which may beFloat.NaN. -
allEquals
public static boolean allEquals(double[] array, double value) Returnstrueif all values in the specified array are equals to the specified value, which may beDouble.NaN. -
hasNaN
public static boolean hasNaN(float[] array) Returnstrueif the specified array contains at least oneNaNvalue. -
hasNaN
public static boolean hasNaN(double[] array) Returnstrueif the specified array contains at least oneNaNvalue. -
containsIgnoreCase
Returnstrueif 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 benull.value- The value to search.- Returns:
trueif the array contains the value.
-
contains
Returnstrueif the specified array contains the specified value. This method should be used only for very small arrays, or for search 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 usingHashSetinstead.- Parameters:
array- The array to search in. May benulland may contains null elements.value- The value to search. May benull.- Returns:
trueif the array contains the value.
-
intersects
Returnstrueif 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
HashSetinstead. -
toString
Returns a string representation of an array of numbers. Current implementation supports only primitive or subclasses ofNumber.- Parameters:
array- The array to format.locale- The locale for formatting.- Returns:
- The formatted array.
-