public class IntUtils extends Object
Provides extra functionality for int primitives.
| Modifier and Type | Method and Description | 
|---|---|
static int[] | 
arrayOf(int... values)
Generates an  
int[] from comma-separated values. | 
static Integer[] | 
asObjectArray(int[] array)
Converts from an  
int array to an Integer array. | 
static int[] | 
asPrimitiveArray(Integer[] array)
Converts from an  
Integer array to an int array. | 
static double | 
average(Collection<Integer> collection)
Returns the average value of a collection. 
 | 
static double | 
average(int[] array)
Returns the average value of an array. 
 | 
static <A> double | 
average(Map<A,Integer> map)
Returns the average of the map values. 
 | 
static double | 
averageNonZeros(int[] array)
Returns the average value only among non-zero values 
 | 
static int[] | 
concatenate(int[]... arrays)
Concatenates a series of arrays. 
 | 
static int[] | 
constantArray(int N,
             int value)
Returns an array filled with a given value. 
 | 
static <A> Map<A,Integer> | 
constantMap(Set<A> identifiers,
           int value)
Returns a map filled with a given value. 
 | 
static boolean | 
contains(int[] array,
        int value)
Checks if an input array contains a given value 
 | 
static boolean | 
containsAll(int[] container,
           int[] array)
Checks if an array contains all numbers from another one. 
 | 
static boolean | 
containsAny(int[] container,
           int[] array)
Checks whether any element of an array is present in another one. 
 | 
static <A extends Number> | 
convertArray2Map(Set<A> identifiers,
                int[] array)
Returns a map containing the association of each identifier with its corresponding
 value within the array (in linear order). 
 | 
static <A extends Number,B extends Number> | 
convertTable2Map(Set<A> rowIdentifiers,
                Set<B> columnIdentifiers,
                int[][] table)
Returns a map containing the association of each identifier pair with its corresponding
 value within the table (in linear order). 
 | 
static int[] | 
copy(int[] array)
Returns a deep copy of the input  
array. | 
static int[][] | 
copy(int[][] array)
Returns a deep copy of the input  
array. | 
static double[] | 
divide(int[] array,
      double value)
Divides all elements in an array by a scalar. 
 | 
static double[] | 
divide(int[] array1,
      int[] array2)
Divides two arrays element-to-element. 
 | 
static <A> Map<A,Double> | 
divide(Map<A,Integer> map,
      double value)
Divides all elements in a map by a scalar. 
 | 
static <A> Map<A,Double> | 
divide(Map<A,Integer> map1,
      Map<A,Integer> map2)
Returns the element-wise quotient of two maps. 
 | 
static double[] | 
divideNonSingular(int[] array1,
                 int[] array2)
Divides two arrays element-to-element, but when numerator and denominator = 0, returns 0 instead of a singularity (NaN) 
 | 
static int[] | 
find(int[] array,
    int value,
    Constants.SearchType searchType)
Returns the position(s) where a given value can be found into an array. 
 | 
static int | 
gcd(Collection<Integer> collection)
Computes the greatest common divisor of an input collection. 
 | 
static int | 
gcd(int[] array)
Computes the greatest absolute common divisor of an integer array. 
 | 
static int[] | 
intersect(int[]... arrays)
Returns the intersection vector of a series of input arrays. 
 | 
static String | 
join(int[] array,
    String separator)
Joins the elements in an input array using a given separator. 
 | 
static List<Integer> | 
listOf(int... values)
Returns a list of the comma-separated input values. 
 | 
static int[] | 
maxIndexes(int[] array,
          Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found. 
 | 
static <A> Set<A> | 
maxIndexes(Map<A,Integer> map,
          Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found. 
 | 
static int[][] | 
maxMinIndexes(int[] array,
             Constants.SearchType searchType)
Returns the position(s) in which the maximum/minimum values are found. 
 | 
static int[] | 
maxMinValues(Collection<Integer> collection)
Returns the maximum/minimum values of an input collection. 
 | 
static int[] | 
maxMinValues(int[] array)
Returns the maximum/minimum values of an input array. 
 | 
static <A> int[] | 
maxMinValues(Map<A,Integer> map)
Returns the maximum/minimum values of an input array. 
 | 
static int | 
maxValue(Collection<Integer> collection)
Returns the maximum value in the input collection. 
 | 
static int | 
maxValue(int[] array)
Returns the maximum value in the input array. 
 | 
static int | 
maxValue(int[][] array)
Returns the maximum value in the input array. 
 | 
static <A> int | 
maxValue(Map<A,Integer> map)
Returns the maximum value in the input array. 
 | 
static int[] | 
minIndexes(int[] array,
          Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found. 
 | 
static <A> Set<A> | 
minIndexes(Map<A,Integer> map,
          Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found. 
 | 
static int | 
minValue(Collection<Integer> collection)
Returns the minimum value in the input collection. 
 | 
static int | 
minValue(int[] array)
Returns the minimum value in the input array. 
 | 
static double | 
minValue(int[][] matrix)
Returns the minimum value in the input matrix. 
 | 
static <A> int | 
minValue(Map<A,Integer> map)
Returns the minimum value in the input map. 
 | 
static double[][] | 
mult(int[][] matrix,
    double value)
Multiplies all elements in a matrix by a scalar. 
 | 
static double[] | 
mult(int[] array,
    double value)
Multiplies all elements in an array by a scalar. 
 | 
static double[] | 
mult(int[] array1,
    int[] array2)
Multiplies two arrays element-to-element. 
 | 
static <A> Map<A,Double> | 
mult(Map<A,Integer> map,
    double value)
Multiplies all elements in an array by a scalar. 
 | 
static <A> Map<A,Double> | 
mult(Map<A,Integer> map1,
    Map<A,Integer> map2)
Returns the element-wise product of two maps. 
 | 
static int[] | 
ones(int N)
Returns an array filled with ones. 
 | 
static <A> Map<A,Integer> | 
ones(Set<A> identifiers)
Returns a map filled with ones. 
 | 
static void | 
reverse(int[] array)
Reverses the order of the elements of the input array (it will be overriden). 
 | 
static double | 
scalarProduct(int[] array1,
             int[] array2)
Scalar product of two vectors. 
 | 
static <A> double | 
scalarProduct(Map<A,Integer> map1,
             Map<A,Integer> map2)
Scalar product of two maps. 
 | 
static int[] | 
select(int[] array,
      int[] indexes)
Returns a set of selected elements from an input array. 
 | 
static int[] | 
selectColumn(int[][] array,
            int column)
Returns a column of a bidimensional input array. 
 | 
static int[] | 
selectRow(int[][] array,
         int row)
Returns a row of a bidimensional input array. 
 | 
static int[] | 
setdiff(int[]... arrays)
Returns the elements contained in the first array, but not any of the others. 
 | 
static Set<Integer> | 
setOf(int... values)
Returns a list of the comma-separated input values. 
 | 
static void | 
sort(int[] array,
    Constants.OrderingType orderingType)
Sorts the input array (it will be overriden). 
 | 
static int[] | 
sortIndexes(int[] array,
           Constants.OrderingType orderingType)
Sorts indexes of the  
array into ascending/descending order in a stable way. | 
static double | 
std(Collection<Integer> collection)
Returns the standard deviation of a collection using the Welford's method. 
 | 
static double | 
std(int[] array)
Returns the standard deviation of an array using the Welford's method. 
 | 
static <A> double | 
std(Map<A,Integer> map)
Returns the standard deviation of values of a map using the Welford's method. 
 | 
static int[] | 
substract(int[] array1,
         int[] array2)
Returns the element-wise substraction of two arrays. 
 | 
static double | 
sum(Collection<Integer> collection)
Returns the sum of all elements in the input collection. 
 | 
static double | 
sum(int[] array)
Returns the sum of all elements in the input array. 
 | 
static double | 
sum(int[][] matrix)
Returns the sum of all elements in the input matrix. 
 | 
static double[] | 
sum(int[] array1,
   int[] array2)
Returns the element-wise sum of two arrays. 
 | 
static <A> double | 
sum(Map<A,Integer> map)
Returns the sum of all elements in the input collection. 
 | 
static <A> Map<A,Double> | 
sum(Map<A,Integer> map1,
   Map<A,Integer> map2)
Returns the element-wise sum of two maps. 
 | 
static int[] | 
toArray(Collection<Integer> list)
Converts a collection ( 
List, Set...) of Integer objects to an int array. | 
static int[] | 
toArray(String[] list)
Converts an array of  
String with the values, into a int array. | 
static double[] | 
toDoubleArray(int[] array)
Converts an  
int array to a double array | 
static List<Integer> | 
toList(int[] array)
Converts from a  
int array to a list. | 
static long[] | 
toLongArray(int[] array)
Converts an  
int array to a long array | 
static String | 
toString(int[] array)
Converts the array into an String of space separated values. 
 | 
static int[] | 
union(int[]... arrays)
Returns an array with all elements in input arrays (no repetitions). 
 | 
static int[] | 
unique(int[] array)
Returns the same values of the input  
array but with no repetitions. | 
static int[] | 
zeros(int N)
Returns an array filled with zeros. 
 | 
static <A> Map<A,Integer> | 
zeros(Set<A> identifiers)
Returns a map filled with zeros. 
 | 
public static int[] arrayOf(int... values)
int[] from comma-separated values.values - Comma-separated int valuesint[]public static Integer[] asObjectArray(int[] array)
int array to an Integer array.array - int arrayInteger arraypublic static int[] asPrimitiveArray(Integer[] array)
Integer array to an int array.array - Integer arrayint arraypublic static double average(Collection<Integer> collection)
collection - Input collectioncollection is empty)public static double average(int[] array)
array - Input arrayarray is empty)public static <A> double average(Map<A,Integer> map)
A - Key typemap - Input mapmap is empty)public static double averageNonZeros(int[] array)
array - Input arraypublic static int[] concatenate(int[]... arrays)
arrays - List of arrayspublic static int[] constantArray(int N,
                                  int value)
N - Number of elementsvalue - Value for all elementsN with the given valuepublic static <A> Map<A,Integer> constantMap(Set<A> identifiers, int value)
A - Key typeidentifiers - Set of map keysvalue - Value for all elementspublic static boolean contains(int[] array,
                               int value)
array - Input arrayvalue - Value to searchtrue if value is present in array, and false otherwise. If array is empty, it will return falsepublic static boolean containsAll(int[] container,
                                  int[] array)
container - Container arrayarray - Array with elements to be checkedtrue if all elements in array are present in container, and false otherwise. If container is empty, it will return falsepublic static boolean containsAny(int[] container,
                                  int[] array)
intersection(array1, array2).length == 0.container - Container arrayarray - Array with elements to be checkedtrue if any element in array is present in container, and false otherwise. If container is empty, it will return falsepublic static <A extends Number> Map<A,Integer> convertArray2Map(Set<A> identifiers, int[] array)
A - Key typeidentifiers - Set of identifier in ascending iterator order (duplicated and null values are not allowed)array - Input arraypublic static <A extends Number,B extends Number> Map<Pair<A,B>,Integer> convertTable2Map(Set<A> rowIdentifiers, Set<B> columnIdentifiers, int[][] table)
A - Row key typeB - Column key typerowIdentifiers - Set of row identifiers in ascending iterator order (null values are not allowed)columnIdentifiers - Set of column identifiers in ascending iterator order (duplicated and null values are not allowed)table - Input tablepublic static int[] copy(int[] array)
array.array - Input arrayarraypublic static int[][] copy(int[][] array)
array.array - Input arrayarraypublic static double[] divide(int[] array,
                              double value)
array - Input arrayvalue - Scalarpublic static double[] divide(int[] array1,
                              int[] array2)
array1 - Numeratorarray2 - Denominatorpublic static <A> Map<A,Double> divide(Map<A,Integer> map, double value)
A - Key typemap - Input mapvalue - Scalarpublic static <A> Map<A,Double> divide(Map<A,Integer> map1, Map<A,Integer> map2)
A - Key typemap1 - Input map 1map2 - Input map 2public static double[] divideNonSingular(int[] array1,
                                         int[] array2)
array1 - Numeratorarray2 - Denominatorpublic static int[] find(int[] array,
                         int value,
                         Constants.SearchType searchType)
array - Input arrayvalue - Value to be searched forsearchType - Indicates whether the first, the last, or all occurrences are returnedpublic static int gcd(Collection<Integer> collection)
collection - Input collectiongcd(0, 0) is equal to zero and gcd([]) is equal to onepublic static int gcd(int[] array)
array - Input arraygcd(0, 0) is equal to zero and gcd([]) is equal to onepublic static int[] intersect(int[]... arrays)
arrays - Vector of input arrayspublic static String join(int[] array, String separator)
Arrays.toString().array - Input arrayseparator - SeparatorString representation of the input arraypublic static List<Integer> listOf(int... values)
values - Comma-separated input valuespublic static int[] maxIndexes(int[] array,
                               Constants.SearchType searchType)
array - Input arraysearchType - Indicates whether the first, the last, or all maximum positions are returnedpublic static <A> Set<A> maxIndexes(Map<A,Integer> map, Constants.SearchType searchType)
A - Key typemap - Input mapsearchType - Indicates whether the first, the last, or all maximum positions are returnedpublic static int[][] maxMinIndexes(int[] array,
                                    Constants.SearchType searchType)
Returns the position(s) in which the maximum/minimum values are found.
out[0] are the maximum positions, while out[1] are the minimum positions
array - Input arraysearchType - Indicates whether the first, the last, or all maximum positions are returnedpublic static int[] maxMinValues(Collection<Integer> collection)
collection - Input collectionpublic static int[] maxMinValues(int[] array)
array - Input arraypublic static <A> int[] maxMinValues(Map<A,Integer> map)
A - the map key typemap - Input mappublic static int maxValue(Collection<Integer> collection)
collection - Input collectionpublic static int maxValue(int[] array)
array - Input arraypublic static int maxValue(int[][] array)
array - Input arraypublic static <A> int maxValue(Map<A,Integer> map)
A - Key typemap - Input mappublic static int[] minIndexes(int[] array,
                               Constants.SearchType searchType)
array - Input arraysearchType - Indicates whether the first, the last, or all minimum positions are returnedpublic static <A> Set<A> minIndexes(Map<A,Integer> map, Constants.SearchType searchType)
A - Key typemap - Input mapsearchType - Indicates whether the first, the last, or all minimum positions are returnedpublic static int minValue(Collection<Integer> collection)
collection - Input collectionpublic static int minValue(int[] array)
array - Input arraypublic static double minValue(int[][] matrix)
matrix - Input matrixpublic static <A> int minValue(Map<A,Integer> map)
A - Key typemap - Input mappublic static double[][] mult(int[][] matrix,
                              double value)
matrix - Input arrayvalue - Scalarpublic static double[] mult(int[] array,
                            double value)
array - Input arrayvalue - Scalarpublic static double[] mult(int[] array1,
                            int[] array2)
array1 - Input array 1array2 - Input array 2public static <A> Map<A,Double> mult(Map<A,Integer> map, double value)
A - Key typemap - Input mapvalue - Scalarpublic static <A> Map<A,Double> mult(Map<A,Integer> map1, Map<A,Integer> map2)
A - Key typemap1 - Input map 1map2 - Input map 2public static int[] ones(int N)
N - Number of elementsNpublic static <A> Map<A,Integer> ones(Set<A> identifiers)
A - Key typeidentifiers - Set of map keyspublic static void reverse(int[] array)
array - Input arraypublic static double scalarProduct(int[] array1,
                                   int[] array2)
array1 - Input array 1array2 - Input array 2public static <A> double scalarProduct(Map<A,Integer> map1, Map<A,Integer> map2)
A - Key typemap1 - Input map 1map2 - Input map 2public static int[] select(int[] array,
                           int[] indexes)
array - Input arrayindexes - Position of elements to be selected.indexespublic static int[] selectColumn(int[][] array,
                                 int column)
array - Input arraycolumn - Columnpublic static int[] selectRow(int[][] array,
                              int row)
array - Input arrayrow - Rowpublic static int[] setdiff(int[]... arrays)
arrays - Input arrayspublic static Set<Integer> setOf(int... values)
values - Comma-separated input valuespublic static void sort(int[] array,
                        Constants.OrderingType orderingType)
array - Input arrayorderingType - Ascending or descendingpublic static int[] sortIndexes(int[] array,
                                Constants.OrderingType orderingType)
array into ascending/descending order in a stable way. Stable means that index order doesn't change if values are the same.array - Array to be sortedorderingType - Ascending or descendingpublic static double std(Collection<Integer> collection)
collection - Collection of numberscollection is emptypublic static double std(int[] array)
array - Input arraypublic static <A> double std(Map<A,Integer> map)
A - Key typemap - Input mappublic static int[] substract(int[] array1,
                              int[] array2)
array1 - Input array 1array2 - Input array 2public static double sum(Collection<Integer> collection)
collection - Input collectionpublic static double sum(int[] array)
array - Input arraypublic static double sum(int[][] matrix)
matrix - Input matrixpublic static double[] sum(int[] array1,
                           int[] array2)
array1 - Input array 1array2 - Input array 2public static <A> double sum(Map<A,Integer> map)
A - Key typemap - Input mappublic static <A> Map<A,Double> sum(Map<A,Integer> map1, Map<A,Integer> map2)
A - Key typemap1 - Input map 1map2 - Input map 2public static int[] toArray(Collection<Integer> list)
List, Set...) of Integer objects to an int array.list - Input listint arraypublic static int[] toArray(String[] list)
String with the values, into a int array. Uses Integer.parseInt to parse the number, an can raise the exceptions 
 that this method raiseslist - Input listpublic static double[] toDoubleArray(int[] array)
int array to a double arrayarray - Input arraydouble arraypublic static List<Integer> toList(int[] array)
int array to a list.array - Input arrayInteger objectspublic static long[] toLongArray(int[] array)
int array to a long arrayarray - Input arraylong arraypublic static String toString(int[] array)
array - Input arraypublic static int[] union(int[]... arrays)
arrays - Input arrayspublic static int[] unique(int[] array)
array but with no repetitions. There is no order guarantee.array - Input arrayarray but with no repetitionspublic static int[] zeros(int N)
N - Number of elementsNCopyright © 2018. All rights reserved.