Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.util
Class ArrayUtil

    java.lang.Object
      umontreal.iro.lecuyer.util.ArrayUtil

    public class ArrayUtil

extends Object

Provides static utility methods to resize and test arrays.

Method Summary
`static boolean` | `allDifferent(byte... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static boolean` | `allDifferent(double... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static boolean` | `allDifferent(float... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static boolean` | `allDifferent(int... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static boolean` | `allDifferent(long... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static boolean` | `allDifferent(short... a)` Determines if the elements in the array `a` are all different, and returns the result of the test.
`static void` | `checkRectangularMatrix(Object m)` Determines if the given object `m` is a rectangular matrix.
`static double[][]` | `copy(double[][] M)` Copies the array M and returns the copy.
`static
`<T> T`
` | `deepClone(T array)` Equivalent to `boolean) deepClone (array, false)` .
`static
`<T> T`
` | `deepClone(T array, boolean cloneElements)` Constructs and returns a deep clone of the array `array`.
`static int` | `getMinDigits(double... a)` Returns the minimal number of digits after the decimal point required for the numbers in the array `a` to be rounded without different values becoming equal.
`static int` | `getMinDigits(float... a)` Returns the minimal number of digits after the decimal point required for the numbers in the array `a` to be rounded without different values becoming equal.
`static boolean[][]` | `getTranspose(boolean[][] m)` Returns the transpose of a matrix `m`.
`static byte[][]` | `getTranspose(byte[][] m)` Returns the transpose of a matrix `m`.
`static char[][]` | `getTranspose(char[][] m)` Returns the transpose of a matrix `m`.
`static double[][]` | `getTranspose(double[][] m)` Returns the transpose of a matrix `m`.
`static float[][]` | `getTranspose(float[][] m)` Returns the transpose of a matrix `m`.
`static int[][]` | `getTranspose(int[][] m)` Returns the transpose of a matrix `m`.
`static long[][]` | `getTranspose(long[][] m)` Returns the transpose of a matrix `m`.
`static short[][]` | `getTranspose(short[][] m)` Returns the transpose of a matrix `m`.
`static
`<T> T[][]`
` | `getTranspose(T[][] m)` Returns the transpose of a matrix `m`.
`static byte` | `max(byte... a)` Returns the value of the greatest element in the array `a`.
`static double` | `max(double... a)` Returns the value of the greatest element in the array `a`.
`static float` | `max(float... a)` Returns the value of the greatest element in the array `a`.
`static int` | `max(int... a)` Returns the value of the greatest element in the array `a`.
`static long` | `max(long... a)` Returns the value of the greatest element in the array `a`.
`static short` | `max(short... a)` Returns the value of the greatest element in the array `a`.
`static
`<T extends Comparable<T>> T`
` | `max(T... a)` Returns the value of the greatest element in the array `a`.
`static boolean[]` | `merge(boolean[]... arrays)`
`static byte[]` | `merge(byte[]... arrays)`
`static char[]` | `merge(char[]... arrays)`
`static double[]` | `merge(double[]... arrays)`
`static float[]` | `merge(float[]... arrays)`
`static int[]` | `merge(int[]... arrays)` Merges the given arrays into a single array, and returned the constructed array.
`static long[]` | `merge(long[]... arrays)`
`static short[]` | `merge(short[]... arrays)`
`static
`<T> T[]`
` | `merge(T[]... arrays)`
`static byte` | `min(byte... a)` Returns the value of the smallest element in the array `a`.
`static double` | `min(double... a)` Returns the value of the smallest element in the array `a`.
`static float` | `min(float... a)` Returns the value of the smallest element in the array `a`.
`static int` | `min(int... a)` Returns the value of the smallest element in the array `a`.
`static long` | `min(long... a)` Returns the value of the smallest element in the array `a`.
`static short` | `min(short... a)` Returns the value of the smallest element in the array `a`.
`static
`<T extends Comparable<T>> T`
` | `min(T... a)` Returns the value of the smallest element in the array `a`.
`static boolean[]` | `resizeArray(boolean[] oldArray, int newLength)`
`static byte[]` | `resizeArray(byte[] oldArray, int newLength)`
`static char[]` | `resizeArray(char[] oldArray, int newLength)`
`static double[][]` | `resizeArray(double[][] oldArray, int newRowLen, int newColLen, double x)` Resize array `oldArray` to `newRowLen` rows and `newColLen` columns.
`static double[]` | `resizeArray(double[] oldArray, int newLength)`
`static float[]` | `resizeArray(float[] oldArray, int newLength)`
`static int[][]` | `resizeArray(int[][] oldArray, int newRowLen, int newColLen)` Resize array `oldArray` to `newRowLen` rows and `newColLen` columns.
`static int[]` | `resizeArray(int[] oldArray, int newLength)`
`static long[]` | `resizeArray(long[] oldArray, int newLength)`
`static short[]` | `resizeArray(short[] oldArray, int newLength)`
`static
`<T> T[]`
` | `resizeArray(T[] oldArray, int newLength)` Resizes an array `oldArray` to the length `newLength`, and returns a reference to an array with the appropriate length.
`static double[][]` | `resizeRow(double[][] array, int row, int len)` Resize row `row` of array `array` to have `len` elements.
`static int[][]` | `resizeRow(int[][] array, int row, int len)` Resize row `row` of array `array` to have `len` elements.
`static double[]` | `round(int maxDigits, double... a)` Roudns each number in `a` to `maxDigits` digits.
`static float[]` | `round(int maxDigits, float... a)` Roudns each number in `a` to `maxDigits` digits.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### resizeArray

    public static byte[] resizeArray(byte[] oldArray,
                                     int newLength)

### resizeArray

    public static short[] resizeArray(short[] oldArray,
                                      int newLength)

### resizeArray

    public static int[] resizeArray(int[] oldArray,
                                    int newLength)

### resizeArray

    public static int[][] resizeArray(int[][] oldArray,
                                      int newRowLen,
                                      int newColLen)

  Resize array `oldArray` to `newRowLen` rows and `newColLen` columns. If the new lengths are smaller than the old lengths, the last elements of the arrays are lost. If the new lengths are greater than the old lengths, new elements having the default value `t` are appended to the array. Returns a reference to the new array.

  Parameters:
    `oldArray` - old array
    `newRowLen` - new number of rows
    `newColLen` - new number of columns
  Returns:
    resized array

### resizeRow

    public static int[][] resizeRow(int[][] array,
                                    int row,
                                    int len)

  Resize row `row` of array `array` to have `len` elements. The other rows of `array` are unchanged. If the new length `len` is greater than the old length, new elements having the default value 0 are appended to row `row`. If `row` is greater or equal to the old number of rows, the array is extended to have `row + 1` rows. The new rows have length 0, except for row `row` which has length `len`.

  Returns a reference to the resized array.

  Parameters:
    `array` - old array
    `row` - row index
    `len` - new length of row `row`
  Returns:
    resized array

### resizeArray

    public static long[] resizeArray(long[] oldArray,
                                     int newLength)

### resizeArray

    public static char[] resizeArray(char[] oldArray,
                                     int newLength)

### resizeArray

    public static boolean[] resizeArray(boolean[] oldArray,
                                        int newLength)

### resizeArray

    public static float[] resizeArray(float[] oldArray,
                                      int newLength)

### resizeArray

    public static double[] resizeArray(double[] oldArray,
                                       int newLength)

### resizeArray

    public static double[][] resizeArray(double[][] oldArray,
                                         int newRowLen,
                                         int newColLen,
                                         double x)

  Resize array `oldArray` to `newRowLen` rows and `newColLen` columns. If the new lengths are smaller than the old lengths, the last elements of the arrays are lost. If the new lengths are greater than the old lengths, new elements having the default value `x` are appended to the array. Returns a reference to the new array.

  Parameters:
    `oldArray` - old array
    `newRowLen` - new number of rows
    `newColLen` - new number of columns
    `x` - default value of the new elements
  Returns:
    resized array

### resizeRow

    public static double[][] resizeRow(double[][] array,
                                       int row,
                                       int len)

  Resize row `row` of array `array` to have `len` elements. The other rows of `array` are unchanged. If the new length `len` is greater than the old length, new elements having the default value 0 are appended to row `row`. If `row` is greater or equal to the old number of rows, the array is extended to have `row + 1` rows. The new rows have length 0, except for row `row` which has length `len`.

  Returns a reference to the resized array.

  Parameters:
    `array` - old array
    `row` - row index
    `len` - new length of row `row`
  Returns:
    resized array

### resizeArray

    public static <T> T[] resizeArray(T[] oldArray,
                                      int newLength)

  Resizes an array `oldArray` to the length `newLength`, and returns a reference to an array with the appropriate length. If the length of `oldArray` corresponds to `newLength`, the method returns the old array reference. Otherwise, a new array is constructed, and the elements are copied from the old array, using `System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)`. If the new length is smaller than the old length, the last elements of the array are lost. If the new length is greater than the old length, new elements having the default value (`null`, `0`, or `false`, depending on the type of array) are appended to the array.

  Parameters:
    `oldArray` - the old array to be resized.
    `newLength` - the required length of the returned array.
  Returns:
    the old array or a resized copy of the old array.
  Throws:
    `NullPointerException` - if `oldArray` is `null`.
    `IllegalArgumentException` - if `oldArray` does not correspond to an array.
    `NegativeArraySizeException` - if `newLength` is negative.

### checkRectangularMatrix

    public static void checkRectangularMatrix(Object m)

  Determines if the given object `m` is a rectangular matrix. To be a rectangular matrix, the object must be an array of arrays of any primitive or non-array reference type. Each of the arrays must be non-`null` and have the same length.

  Parameters:
    `m` - the object to be tested.
  Throws:
    `NullPointerException` - if `m` or one of its elements are `null`.
    `IllegalArgumentException` - if the object is not a rectangular matrix.

### deepClone

    public static <T> T deepClone(T array,
                                  boolean cloneElements)

  Constructs and returns a deep clone of the array `array`. If the given object corresponds to a one-dimensional array, the method clones the array. It also clones the elements in the array if `cloneElements` is `true`. If the given array is multi-dimensional, the method creates a new array of the same length, and recursively calls itself to clone nested arrays.

  If `cloneElements` is `true`, the elements in the given array must be arrays, primitive elements, or objects implementing the `Cloneable` interface.

  This method is equivalent to `array.clone()` if the given array is one-dimensional, and `cloneElements` is `false`.

  Type Parameters:
    `T` - the type of the array.
  Parameters:
    `array` - the array to clone.
    `cloneElements` - determines if elements in the array are cloned.
  Returns:
    the cloned array.
  Throws:
    `IllegalArgumentException` - if the class of the given object is not an array.

### deepClone

    public static <T> T deepClone(T array)

  Equivalent to `boolean) deepClone (array, false)` .

  Type Parameters:
    `T` - the type of the array.
  Parameters:
    `array` - the array to clone.
  Returns:
    the cloned array.

### getTranspose

    public static byte[][] getTranspose(byte[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static short[][] getTranspose(short[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static int[][] getTranspose(int[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static long[][] getTranspose(long[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static float[][] getTranspose(float[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static double[][] getTranspose(double[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static char[][] getTranspose(char[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static boolean[][] getTranspose(boolean[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### getTranspose

    public static <T> T[][] getTranspose(T[][] m)

  Returns the transpose of a matrix `m`. This method assumes that `m` is rectangular and has dimensions a×b. It creates a matrix of dimensions b×a, and stores element (i, j) of `m` in its element (j, i).

  Parameters:
    `m` - the matrix to be transposed.
  Returns:
    the transposed matrix.
  Throws:
    `NullPointerException` - if `m` is `null`, or `m[i]` is `null` for at least one index `i`.

### min

    public static byte min(byte... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static short min(short... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static int min(int... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static long min(long... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static float min(float... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static double min(double... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### min

    public static <T extends Comparable<T>> T min(T... a)

  Returns the value of the smallest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimum.

### max

    public static byte max(byte... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static short max(short... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static int max(int... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static long max(long... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static float max(float... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static double max(double... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### max

    public static <T extends Comparable<T>> T max(T... a)

  Returns the value of the greatest element in the array `a`.

  Parameters:
    `a` - the tested array.
  Returns:
    the maximum.

### allDifferent

    public static boolean allDifferent(byte... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### allDifferent

    public static boolean allDifferent(short... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### allDifferent

    public static boolean allDifferent(int... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### allDifferent

    public static boolean allDifferent(long... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### allDifferent

    public static boolean allDifferent(float... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### allDifferent

    public static boolean allDifferent(double... a)

  Determines if the elements in the array `a` are all different, and returns the result of the test.

  Parameters:
    `a` - the tested array.
  Returns:
    `true` if and only if all elements are different.

### round

    public static float[] round(int maxDigits,
                                float... a)

  Roudns each number in `a` to `maxDigits` digits.

  Parameters:
    `maxDigits` - the maximal number of digits.
    `a` - the array.
  Returns:
    the resulting array.

### round

    public static double[] round(int maxDigits,
                                 double... a)

  Roudns each number in `a` to `maxDigits` digits.

  Parameters:
    `maxDigits` - the maximal number of digits.
    `a` - the array.
  Returns:
    the resulting array.

### getMinDigits

    public static int getMinDigits(float... a)

  Returns the minimal number of digits after the decimal point required for the numbers in the array `a` to be rounded without different values becoming equal. For example, this method returns 2 when given the array `{ 1.26, 1.28, 1.26, 1.27 }` but 1 for the array `{ 1.26, 1.42 }`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimal number of digits.

### getMinDigits

    public static int getMinDigits(double... a)

  Returns the minimal number of digits after the decimal point required for the numbers in the array `a` to be rounded without different values becoming equal. For example, this method returns 2 when given the array `{ 1.26, 1.28, 1.26, 1.27 }` but 1 for the array `{ 1.26, 1.42 }`.

  Parameters:
    `a` - the tested array.
  Returns:
    the minimal number of digits.

### merge

    public static int[] merge(int[]... arrays)

  Merges the given arrays into a single array, and returned the constructed array.

  Parameters:
    `arrays` - the arrays to be merged together.
  Returns:
    the merged array.

### merge

    public static byte[] merge(byte[]... arrays)

### merge

    public static short[] merge(short[]... arrays)

### merge

    public static long[] merge(long[]... arrays)

### merge

    public static float[] merge(float[]... arrays)

### merge

    public static double[] merge(double[]... arrays)

### merge

    public static char[] merge(char[]... arrays)

### merge

    public static boolean[] merge(boolean[]... arrays)

### merge

    public static <T> T[] merge(T[]... arrays)

### copy

    public static double[][] copy(double[][] M)

  Copies the array M and returns the copy.

  Parameters:
    `M` -
  Returns:
    copy of M

Overview | Package | Class | Tree | Deprecated | Index | Help
| ContactCenters V. 0.9.9.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

To submit a bug or ask questions, send an e-mail to Richard Simard.