public enum ArrayUtils extends Enum<ArrayUtils>
Modifier and Type | Method and Description |
---|---|
static BoolVar[] |
append(BoolVar[]... toAppend)
Append two Arrays
|
static int[] |
append(int[]... toAppend)
Append int arrays
|
static IntVar[] |
append(IntVar[]... toAppend)
Append two Arrays
|
static <T> T[] |
append(T[]... toAppend)
Append two Arrays
|
static int[] |
array(int lb,
int ub)
Creates an array of ints of consecutive values from lb (inclusive) to ub (inclusive as well),
i.e.
|
static int |
binarySearchInc(int[] a,
int fromIndex,
int toIndex,
int key,
boolean gq)
Adapted from
Arrays.binarySearch0(int[], int, int, int) ,
it returns the value greater or equal to key in an increasing order value array
If the key exists in a, it returns the index of key in a,
otherwise it returns the index of the closest value greater than key when gq is set to true,
or the index of the closest value smaller than key when gq is set to false. |
static BoolVar[] |
concat(BoolVar[] array,
BoolVar... elements)
Append elements at the end of another array
|
static int[] |
concat(int[] array,
int... elements)
Append elements at the end of another array
|
static IntVar[] |
concat(IntVar[] array,
IntVar... elements)
Append elements at the end of another array
|
static <T> T[] |
concat(T[] array,
T... elements)
Append elements at the end of another array
|
static <T> boolean |
contains(T[] array,
T obj) |
static int[] |
createNonRedundantSortedValues(gnu.trove.list.array.TIntArrayList values) |
static int[] |
flatten(int[][] matrix)
Flattens a matrix M[n][m] in an array F[n*m] such that F[i*n+j] = M[i][j].
|
static <T> T[] |
flatten(T[][] matrix)
Flattens a matrix M[n][m] in an array F[n*m] such that F[i*n+j] = M[i][j].
|
static <T> T[] |
flatten(T[][][] matrix)
Flattens a matrix M[n][m][p] in an array F[n*m*p] such that F[(i*n*m) + (j*m) + k] = M[i][j][k].
|
static <T> T[] |
flattenSubMatrix(int iMin,
int iLength,
int jMin,
int jLength,
T[][] matrix) |
static <T> T |
get(int index,
List<T>... arrays)
Returns the element in position index when considering all arrays appended altogether.
|
static <T> T |
get(int index,
T[]... arrays)
Returns the element in position index when considering all arrays appended altogether.
|
static double[] |
getColumn(double[][] array,
int c)
Returns the column c extracted from matrix array.
|
static int[] |
getColumn(int[][] array,
int c)
Returns the column c extracted from matrix array.
|
static <T> T[] |
getColumn(T[][] array,
int c)
Returns the column c extracted from matrix array.
|
static <T> T[] |
getColumn(T[][] array,
int c,
Class<? extends T[]> newType)
Returns the column c extracted from matrix array.
|
static void |
inverseSign(int[] tab)
Reverse all signs of the a given int table.
|
static <T> int |
length(T[]... arrays)
Sum the lengths of arrays
|
static int[] |
linspace(int begin,
int end)
Create an array of size (end - begin)
and assigns to the element i the value (i + begin).
|
static int[] |
mergeAndSortIfNot(int[] values)
Sorts the input array if it is not already sorted,
and removes multiple occurrences of the same value
|
static <T> void |
permutation(int[] permutation,
T[] tab)
Permutes elements from tab wrt to permutuation: tab[i] = tab[permutation[i]].
|
static <E> void |
randomPermutations(E[] tab,
long seed)
Permutes randomly elements from tab
|
static <E> void |
randomPermutations(E[] tab,
Random r)
Permutes randomly elements from tab
|
static void |
randomPermutations(int[] tab,
long seed)
Permutes randomly elements from tab
|
static void |
randomPermutations(int[] tab,
Random r)
Permutes randomly elements from tab
|
static void |
reverse(int[] tab)
Turns back to from the elements of tab from the middle position.
|
static <T> void |
reverse(T[] tab)
Turns back to from the elements of tab from the middle position.
|
static <T extends Comparable<T>> |
sort(Set<T> set)
Create an array of elements in set and sort them using
Arrays.sort(Object[]) |
static int[][][] |
swallowCopy(int[][][] arr)
Duplicates arr and returns the new copy
|
static int[][][][] |
swallowCopy(int[][][][] arr)
Duplicates arr and returns the new copy
|
static <T> T[] |
toArray(Class c,
List<T> list)
Returns an array composed of elements from list.
|
static <T> T[] |
toArray(List<T> list)
Creates an array from elements in list.
|
static <T> T[] |
toArray(T... elt)
Creates an array from vargs elt.
|
static <T> List<T> |
toList(T[] array)
Returns a list composed of elements from array.
|
static int[][] |
transpose(int[][] matrix)
Transposes a matrix M[n][m] in a matrix MT[m][n] such that MT[i][j] = M[j][i]
|
static <T> T[][] |
transpose(T[][] matrix)
Transposes a matrix M[n][m] in a matrix MT[m][n] such that MT[i][j] = M[j][i]
|
static ArrayUtils |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ArrayUtils[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
static int[] |
zeroToNShuffle(int nb)
Creates and returns an array of ints composed of unique values from 0 (inclusive) to nb (exclusive), in random order.
|
static int[] |
zeroToNShuffle(int nb,
long seed)
Creates and returns an array of ints composed of unique values from 0 (inclusive) to nb (exclusive), in random order.
|
public static ArrayUtils[] values()
for (ArrayUtils c : ArrayUtils.values()) System.out.println(c);
public static ArrayUtils valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static int[] array(int lb, int ub)
lb
- first element in the arrayub
- last element in the arrayNegativeArraySizeException
- if ubpublic static int[] linspace(int begin, int end)
begin
- first valueend
- last valueNegativeArraySizeException
- if begin > end is negativepublic static int[] getColumn(int[][] array, int c)
array
- double entry matrixc
- index of the column to getpublic static double[] getColumn(double[][] array, int c)
array
- double entry matrixc
- index of the column to getpublic static <T> T[] getColumn(T[][] array, int c)
T
- the class of the objects in the input matrixarray
- double entry matrixc
- index of the column to getpublic static <T> T[] getColumn(T[][] array, int c, Class<? extends T[]> newType)
T
- the class of the objects in the input matrixarray
- double entry matrixc
- index of the column to getnewType
- the class of the copy to be returned@SafeVarargs public static <T> int length(T[]... arrays)
T
- the class of the objects in the input arrayarrays
- list of arrayspublic static <T> boolean contains(T[] array, T obj)
T
- the class of the objects in the input arrayarray
- array of elementsobj
- element to find@SafeVarargs public static <T> T get(int index, T[]... arrays)
T
- the class of the objects in the input arraysindex
- position of the element to returnarrays
- list of arrays@SafeVarargs public static <T> T get(int index, List<T>... arrays)
T
- the class of the objects in the input listsindex
- position of the element to returnarrays
- list of arrayspublic static <T> T[] append(T[]... toAppend)
toAppend
- array of arrays to appendpublic static IntVar[] append(IntVar[]... toAppend)
toAppend
- array of arrays to appendpublic static BoolVar[] append(BoolVar[]... toAppend)
toAppend
- array of arrays to appendpublic static <T> T[] concat(T[] array, T... elements)
array
- array of arrays to appendelements
- elements to appendpublic static IntVar[] concat(IntVar[] array, IntVar... elements)
array
- array of arrays to appendelements
- elements to appendpublic static BoolVar[] concat(BoolVar[] array, BoolVar... elements)
array
- array of arrays to appendelements
- elements to appendpublic static int[] append(int[]... toAppend)
toAppend
- array of arrays to appendpublic static int[] concat(int[] array, int... elements)
array
- array of arrays to appendelements
- elements to appendpublic static void inverseSign(int[] tab)
tab
- array to inversepublic static void reverse(int[] tab)
tab
- array to reversepublic static <T> void reverse(T[] tab)
T
- the class of the objects in the input arraytab
- array to reversepublic static <T> void permutation(int[] permutation, T[] tab)
T
- the class of the objects in the input arraypermutation
- permutationtab
- array of intspublic static <T> List<T> toList(T[] array)
T
- the class of the objects in the input arrayarray
- array of elementspublic static <T> T[] toArray(Class c, List<T> list)
T
- the class of the objects in the input arrayc
- the class of the copy to be returnedlist
- list of elements@SafeVarargs public static <T> T[] toArray(T... elt)
T
- the class of the objects in the returned arrayelt
- elements to put in an arraypublic static <T> T[] toArray(List<T> list)
T
- the class of the objects in the returned arraylist
- elements to put in an arraypublic static <T> T[][] transpose(T[][] matrix)
T
- the class of the objects in the input matrixmatrix
- matrix to transposepublic static int[][] transpose(int[][] matrix)
matrix
- matrix to transposepublic static <T> T[] flatten(T[][] matrix)
T
- the class of the objects in the input matrixmatrix
- matrix to flattenpublic static <T> T[] flatten(T[][][] matrix)
T
- the class of the objects in the input matrixmatrix
- matrix to flattenpublic static <T> T[] flattenSubMatrix(int iMin, int iLength, int jMin, int jLength, T[][] matrix)
public static int[] flatten(int[][] matrix)
matrix
- matrix to flattenpublic static int[] createNonRedundantSortedValues(gnu.trove.list.array.TIntArrayList values)
public static <T extends Comparable<T>> T[] sort(Set<T> set)
Arrays.sort(Object[])
T
- the class of the objects in the input set.set
- set of elementspublic static int[][][][] swallowCopy(int[][][][] arr)
arr
- matrix to duplicatepublic static int[][][] swallowCopy(int[][][] arr)
arr
- matrix to duplicatepublic static int[] zeroToNShuffle(int nb)
nb
- upper value (exclusive)public static int[] zeroToNShuffle(int nb, long seed)
nb
- upper value (exclusive)seed
- seed for randomnesspublic static void randomPermutations(int[] tab, Random r)
tab
- array of intsr
- randomness generatorpublic static void randomPermutations(int[] tab, long seed)
tab
- array of intsseed
- seed for randomnesspublic static <E> void randomPermutations(E[] tab, Random r)
E
- the class of the objects in the input arraytab
- array of intsr
- randomness generatorpublic static <E> void randomPermutations(E[] tab, long seed)
E
- the class of the objects in the input arraytab
- array of intsseed
- seed for randomnesspublic static int binarySearchInc(int[] a, int fromIndex, int toIndex, int key, boolean gq)
Arrays.binarySearch0(int[], int, int, int)
,
it returns the value greater or equal to key in an increasing order value array
If the key exists in a, it returns the index of key in a,
otherwise it returns the index of the closest value greater than key when gq is set to true,
or the index of the closest value smaller than key when gq is set to false.a
- the values, increasingly orderedfromIndex
- starting index (inclusive)toIndex
- ending index (exclusive)key
- value to look forgq
- set to true to look for the value greater or equal to key,
false to look for the value smaller or equal to the keypublic static int[] mergeAndSortIfNot(int[] values)
values
- array of valuesCopyright © 2018. All rights reserved.