Class ArrayUtils
java.lang.Object
jmt.framework.data.ArrayUtils
Assorted array mangling stuff.
resizemethods return a resized copy of an array, preserving data where possible and padding with a specified valuecopymethods perform a deep copy of an array. They come in two flavors: one that copies into an existing array (that must have been properly initialized) and one that creates the copy from scratchdeletemethods delete an element in an array, returning a reduced-size copy in which following elements have been shifted to fill the gap. For multidim arrays shallow copy is performed when possible - ie do not assume the new array to be independent from the old onetoCSVandfromCSVmethods input/output single rows as Strings of comma-separated values.toStringmethods return a somewhat useful String representation of an array.
NOTE: fromCSV uses the new regex String splitting methods introduced in 1.4. For use in pre-1.4 JDKs it must be rewritten using StringTokenizer.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]copy(double[] array) static voidcopy(double[] from, double[] to) static int[]copy(int[] array) static voidcopy(int[] from, int[] to) static String[]static voidstatic double[][]copy2(double[][] array) static voidcopy2(double[][] from, double[][] to) static voidcopy2to3(double[][] source, double[][][] dest, int k) Copies a 2D array in a 3D one.static double[][][]copy3(double[][][] array) static voidcopy3(double[][][] from, double[][][] to) static double[][][]copy3per2(double[][][] array3, double[][] factor) static double[]delete(double[] arr, int idx) static int[]delete(int[] arr, int idx) static String[]static double[][]delete2_1(double[][] arr, int idx) static double[][]delete2_2(double[][] arr, int idx) static double[][][]delete3_1(double[][][] arr, int idx) static double[][][]delete3_2(double[][][] arr, int idx) static double[][][]delete3_3(double[][][] arr, int idx) static booleanequals2(double[][] arr1, double[][] arr2) static booleanequals3(double[][][] arr1, double[][][] arr2) static double[]extract1(double[][] array, int index2) for each i result[i] = array[i][index2]static double[][]extract13(double[][][] array, int index2) for each i,j result[i][j] = array[i][index2][j-1]static booleanstatic double[]Extract a double[] given a string separated by ';'static booleanfromCSV3_2(double[][][] array, int index1, int index3, String str) static voidinsert1(double[][] result, double[] array, int index2) for each i result[i][index2] = array[i]static double[][]makeFilled(int len1, int len2, double val) create an empty double[len1][len2]static double[]multiply(double[] source, double num) Given an array A and a number n returns the product A*n
Author: Bertoli Marcostatic double[]prepend0(double[] array) array[n]->result[n+1], where result[0]=0 and for i=(0..n-1) result[i]=array[i-1]static double[]resize(double[] array, int newsize, double padding) Resizes an array, preserving data and padding as neededstatic int[]resize(int[] array, int newsize, int padding) Resizes an array, preserving data and padding as neededstatic String[]Resizes an array, preserving data and padding as neededstatic <T> T[]resize(T[] array, int newsize) Resizes an array, preserving data and padding as neededstatic double[][]resize2(double[][] array, int newsize1, int newsize2, double padding) Resizes a 2-dimensional array preserving data and padding as neededstatic double[][][]resize3var(double[][][] array, int newsize1, int newsize2, int[] newsize3, double padding) Resizes a 3-dimensional array with variable sizes preserving data and padding as neededstatic StringtoCSV(double[] array) static StringtoCSV3_2(double[][][] array, int index1, int index3) static int[]toInt(double[] arr) for each i result[i]=(int)array[i]static StringtoString(double[] array) static StringtoString(int[] array) static Stringstatic StringtoString2(double[][] array) static StringtoString3(double[][][] array)
-
Method Details
-
resize
public static int[] resize(int[] array, int newsize, int padding) Resizes an array, preserving data and padding as needed -
resize
public static <T> T[] resize(T[] array, int newsize) Resizes an array, preserving data and padding as needed -
resize
public static double[] resize(double[] array, int newsize, double padding) Resizes an array, preserving data and padding as needed -
resize
-
resize2
public static double[][] resize2(double[][] array, int newsize1, int newsize2, double padding) Resizes a 2-dimensional array preserving data and padding as needed -
resize3var
public static double[][][] resize3var(double[][][] array, int newsize1, int newsize2, int[] newsize3, double padding) Resizes a 3-dimensional array with variable sizes preserving data and padding as needed -
copy
-
copy
public static double[] copy(double[] array) -
copy
public static int[] copy(int[] array) -
copy2
public static double[][] copy2(double[][] array) - Returns:
- a deep copy of
array
-
copy3
public static double[][][] copy3(double[][][] array) - Returns:
- a deep copy of
array
-
copy3per2
public static double[][][] copy3per2(double[][][] array3, double[][] factor) -
copy
-
copy
public static void copy(double[] from, double[] to) -
copy
public static void copy(int[] from, int[] to) -
copy2
public static void copy2(double[][] from, double[][] to) -
copy3
public static void copy3(double[][][] from, double[][][] to) -
delete
-
delete
public static int[] delete(int[] arr, int idx) -
delete
public static double[] delete(double[] arr, int idx) -
delete2_1
public static double[][] delete2_1(double[][] arr, int idx) -
delete2_2
public static double[][] delete2_2(double[][] arr, int idx) -
delete3_1
public static double[][][] delete3_1(double[][][] arr, int idx) -
delete3_2
public static double[][][] delete3_2(double[][][] arr, int idx) -
delete3_3
public static double[][][] delete3_3(double[][][] arr, int idx) -
extract13
public static double[][] extract13(double[][][] array, int index2) for each i,j result[i][j] = array[i][index2][j-1] -
extract1
public static double[] extract1(double[][] array, int index2) for each i result[i] = array[i][index2] -
makeFilled
public static double[][] makeFilled(int len1, int len2, double val) create an empty double[len1][len2] -
insert1
public static void insert1(double[][] result, double[] array, int index2) for each i result[i][index2] = array[i] -
toInt
public static int[] toInt(double[] arr) for each i result[i]=(int)array[i] -
toCSV
-
toCSV3_2
-
fromCSV
-
fromCSV
Extract a double[] given a string separated by ';'- Parameters:
str- input string- Returns:
- double array
Author: Bertoli Marco
-
fromCSV3_2
-
equals2
public static boolean equals2(double[][] arr1, double[][] arr2) -
equals3
public static boolean equals3(double[][][] arr1, double[][][] arr2) -
toString
-
toString
-
toString
-
toString2
-
toString3
-
prepend0
public static double[] prepend0(double[] array) array[n]->result[n+1], where result[0]=0 and for i=(0..n-1) result[i]=array[i-1] -
copy2to3
public static void copy2to3(double[][] source, double[][][] dest, int k) Copies a 2D array in a 3D one. Given source[i][j] elements are copied in position dest[i][j][k] where k is a given index.
Author: Bertoli Marco- Parameters:
source- source 2D arraydest- destination 3D arrayk- third coordinate to be left unchanged
-
multiply
public static double[] multiply(double[] source, double num) Given an array A and a number n returns the product A*n
Author: Bertoli Marco- Parameters:
source- source array Anum- number to be multiplied n- Returns:
- a new array with multiplied value
-