Package com.coti.tools
Class OpMat
- java.lang.Object
-
- com.coti.tools.OpMat
-
public class OpMat extends java.lang.Object
Class OpMat offers a list of static methods that deal with atomic and String
arrays; their purpose is to read from the keyboard, print to screen, import from disk
(CSV and columnar), export to disk (CSV and columnar), serialize (save) to disk,
read from disk, sum, multiply and join (only String arrays).
-
-
Constructor Summary
Constructors Constructor Description OpMat()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
exportToDisk(double[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports a double[][] to disk with delimited formatstatic void
exportToDisk(float[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports a float[][] to disk with delimited formatstatic void
exportToDisk(int[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports an int[][] to disk with delimited formatstatic void
exportToDisk(java.lang.String[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports a String[][] with delimited format and can throw an exceptionstatic java.lang.String[][]
importFromDisk(java.io.File f, java.lang.String delimiter)
This method imports from disk a String[][] written with delimited formatstatic double[][]
importFromDisk(java.io.File f, java.lang.String delimiter, double dummy)
This method imports a double[][] from a delimited filestatic float[][]
importFromDisk(java.io.File f, java.lang.String delimiter, float dummy)
This method imports a float[][] from a delimited filestatic int[][]
importFromDisk(java.io.File f, java.lang.String delimiter, int dummy)
This method imports an int[][] from a delimited filestatic void
inputMat(double[][] matrix)
This method reads from the keyboard a double[][]static void
inputMat(float[][] matrix)
This method reads from the keyboard a float[][]static void
inputMat(int[][] matrix)
This method reads from the keyboard an int[][]static void
inputMat(java.lang.String[][] matrix)
This method reads from the keyboard a String[][]static java.lang.String[][]
join(java.lang.String[][] a, java.lang.String[] b)
This method returns the join of a String[][] and a String[].static java.lang.String[][]
join(java.lang.String[][] a, java.lang.String[][] b)
This method returns the join of its two String[][] arguments.static double[][]
loadFromDisk(java.io.File f, double dummy)
This method reads from disk an double[][] written with binary formatstatic float[][]
loadFromDisk(java.io.File f, float dummy)
This method reads from disk an float[][] written with binary formatstatic int[][]
loadFromDisk(java.io.File f, int dummy)
This method reads from disk an int[][] written with binary formatstatic void
printToScreen(double[][] matrix)
This method prints to screen a double[][] with fixed (8.3) column and decimal widthsstatic void
printToScreen(float[][] matrix)
This method prints to screen a float[][] with fixed (8.3) column and decimal widthsstatic void
printToScreen(int[][] matrix)
This method prints to screen an int[][] with fixed (8) column widthsstatic void
printToScreen(java.lang.String[][] matrix)
This method prints to screen a String[][] with fixed column widths (20)static void
printToScreen2(java.lang.String[][] matrix)
This method prints to screen a String[][] with minimum (calculated but equal) column widthsstatic void
printToScreen3(java.lang.String[][] matrix)
This method prints to screen a String[][] with minimum and possibly different widths for each columnstatic double[][]
product(double[][] a, double[][] b)
This method returns the product of its two double[][] argumentsstatic float[][]
product(float[][] a, float[][] b)
This method returns the product of its two float[][] argumentsstatic int[][]
product(int[][] a, int[][] b)
This method returns the product of its two int[][] argumentsstatic void
saveToDisk(java.io.File f, double[][] matrix)
This method writes an double[][] to disk, with binary formatstatic void
saveToDisk(java.io.File f, float[][] matrix)
This method writes a float[][] to disk, with binary formatstatic void
saveToDisk(java.io.File f, int[][] matrix)
This method writes an int[][] to disk, with binary formatstatic double[][]
sum(double[][] a, double[][] b)
This method returns the sum of its two double[][] argumentsstatic float[][]
sum(float[][] a, float[][] b)
This method returns the sum of its two float[][] argumentsstatic int[][]
sum(int[][] a, int[][] b)
This method returns the sum of its two int[][] argumentsstatic double
sumMainDiagonal(double[][] matrix)
This method returns the sum of the items placed in the main diagonal for the given array.
-
-
-
Method Detail
-
inputMat
public static void inputMat(double[][] matrix) throws java.lang.Exception
This method reads from the keyboard a double[][]- Parameters:
matrix
- - the double[][] after reading- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
inputMat
public static void inputMat(float[][] matrix) throws java.lang.Exception
This method reads from the keyboard a float[][]- Parameters:
matrix
- - the float[][] after reading- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
inputMat
public static void inputMat(int[][] matrix) throws java.lang.Exception
This method reads from the keyboard an int[][]- Parameters:
matrix
- - the int[][] after reading- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
inputMat
public static void inputMat(java.lang.String[][] matrix) throws java.lang.Exception
This method reads from the keyboard a String[][]- Parameters:
matrix
- - the String[][] after reading- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen
public static void printToScreen(java.lang.String[][] matrix) throws java.lang.Exception
This method prints to screen a String[][] with fixed column widths (20)- Parameters:
matrix
- - the String[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen2
public static void printToScreen2(java.lang.String[][] matrix) throws java.lang.Exception
This method prints to screen a String[][] with minimum (calculated but equal) column widths- Parameters:
matrix
- - the String[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen3
public static void printToScreen3(java.lang.String[][] matrix) throws java.lang.Exception
This method prints to screen a String[][] with minimum and possibly different widths for each column- Parameters:
matrix
- - the String[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen
public static void printToScreen(double[][] matrix) throws java.lang.Exception
This method prints to screen a double[][] with fixed (8.3) column and decimal widths- Parameters:
matrix
- - the double[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen
public static void printToScreen(float[][] matrix) throws java.lang.Exception
This method prints to screen a float[][] with fixed (8.3) column and decimal widths- Parameters:
matrix
- - the float[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
printToScreen
public static void printToScreen(int[][] matrix) throws java.lang.Exception
This method prints to screen an int[][] with fixed (8) column widths- Parameters:
matrix
- - the int[][]- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
saveToDisk
public static void saveToDisk(java.io.File f, double[][] matrix) throws java.lang.Exception
This method writes an double[][] to disk, with binary format- Parameters:
f
- - the file to write tomatrix
- - an double[][]- Throws:
java.lang.Exception
- - thrown in case of IO error
-
saveToDisk
public static void saveToDisk(java.io.File f, float[][] matrix) throws java.lang.Exception
This method writes a float[][] to disk, with binary format- Parameters:
f
- - the file to write tomatrix
- - a float[][]- Throws:
java.lang.Exception
- - thrown in case of IO error
-
saveToDisk
public static void saveToDisk(java.io.File f, int[][] matrix) throws java.lang.Exception
This method writes an int[][] to disk, with binary format- Parameters:
f
- - the file to write tomatrix
- - an int[][]- Throws:
java.lang.Exception
- - thrown in case of IO error
-
loadFromDisk
public static double[][] loadFromDisk(java.io.File f, double dummy) throws java.lang.Exception
This method reads from disk an double[][] written with binary format- Parameters:
f
- - the file to read fromdummy
- - the necessary change in signature- Returns:
- - a double[][]
- Throws:
java.lang.Exception
- - in case of failure when reading
-
loadFromDisk
public static float[][] loadFromDisk(java.io.File f, float dummy) throws java.lang.Exception
This method reads from disk an float[][] written with binary format- Parameters:
f
- - the file to read fromdummy
- - the necessary change in signature- Returns:
- - a float[][]
- Throws:
java.lang.Exception
- - in case of failure when reading
-
loadFromDisk
public static int[][] loadFromDisk(java.io.File f, int dummy) throws java.lang.Exception
This method reads from disk an int[][] written with binary format- Parameters:
f
- - the file to read fromdummy
- - the necessary change in signature- Returns:
- - a int[][]
- Throws:
java.lang.Exception
- - in case of failure when reading
-
importFromDisk
public static java.lang.String[][] importFromDisk(java.io.File f, java.lang.String delimiter) throws java.lang.Exception
This method imports from disk a String[][] written with delimited format- Parameters:
f
- - the file to read fromdelimiter
- - the delimiter placed between consecutive fields- Returns:
- - a String[][]
- Throws:
java.lang.Exception
- - in case of failure when reading
-
importFromDisk
public static int[][] importFromDisk(java.io.File f, java.lang.String delimiter, int dummy) throws java.lang.Exception
This method imports an int[][] from a delimited file- Parameters:
f
- - Is the File to read fromdelimiter
- - the delimiter to be inserted between consecutive fieldsdummy
- - the necessary change in signature- Returns:
- an int[][]
- Throws:
java.lang.Exception
- in case of failure when reading or parsing
-
importFromDisk
public static float[][] importFromDisk(java.io.File f, java.lang.String delimiter, float dummy) throws java.lang.Exception
This method imports a float[][] from a delimited file- Parameters:
f
- - Is the File to read fromdelimiter
- - the delimiter to be inserted between consecutive fieldsdummy
- - the necessary change in signature- Returns:
- a float[][]
- Throws:
java.lang.Exception
- in case of failure when reading or parsing
-
importFromDisk
public static double[][] importFromDisk(java.io.File f, java.lang.String delimiter, double dummy) throws java.lang.Exception
This method imports a double[][] from a delimited file- Parameters:
f
- - Is the File to read fromdelimiter
- - the delimiter to be inserted between consecutive fieldsdummy
- - the necessary change in signature- Returns:
- a double[][]
- Throws:
java.lang.Exception
- in case of failure when reading or parsing
-
exportToDisk
public static void exportToDisk(java.lang.String[][] matrix, java.io.File f, java.lang.String delimiter) throws java.lang.Exception
This method exports a String[][] with delimited format and can throw an exception- Parameters:
matrix
- - the array that will be exportedf
- - the File that points to a filedelimiter
- - the delimiter (like \t, ",", "#" etc.) to be used- Throws:
java.lang.Exception
- - the exception produce if writing was not possible
-
exportToDisk
public static void exportToDisk(int[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports an int[][] to disk with delimited format- Parameters:
matrix
- - the array that will be exportedf
- - the File that points to a filedelimiter
- - the delimiter (like \t, ",", "#" etc.) to be used
-
exportToDisk
public static void exportToDisk(float[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports a float[][] to disk with delimited format- Parameters:
matrix
- - the array that will be exportedf
- - the File that points to a filedelimiter
- - the delimiter (like \t, ",", "#" etc.) to be used
-
exportToDisk
public static void exportToDisk(double[][] matrix, java.io.File f, java.lang.String delimiter)
This method exports a double[][] to disk with delimited format- Parameters:
matrix
- a double[][] to be written to a filef
- the file to write the table todelimiter
- the delimiter to be used when writing the table (CSV-like)
-
sum
public static int[][] sum(int[][] a, int[][] b)
This method returns the sum of its two int[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the sum of arrays a and b
-
sum
public static float[][] sum(float[][] a, float[][] b)
This method returns the sum of its two float[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the sum of arrays a and b
-
sum
public static double[][] sum(double[][] a, double[][] b)
This method returns the sum of its two double[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the sum of arrays a and b
-
product
public static float[][] product(float[][] a, float[][] b)
This method returns the product of its two float[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the product of arrays a and b
-
product
public static int[][] product(int[][] a, int[][] b)
This method returns the product of its two int[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the product of arrays a and b
-
product
public static double[][] product(double[][] a, double[][] b)
This method returns the product of its two double[][] arguments- Parameters:
a
- - first factorb
- - second factor- Returns:
- - the product of arrays a and b
-
sumMainDiagonal
public static double sumMainDiagonal(double[][] matrix) throws java.lang.Exception
This method returns the sum of the items placed in the main diagonal for the given array.- Parameters:
matrix
- - the double[][]- Returns:
- The sum of elements on the diagonal, fires exception on null array
- Throws:
java.lang.Exception
- - Thrown in case the we are provided with a null array
-
join
public static java.lang.String[][] join(java.lang.String[][] a, java.lang.String[][] b)
This method returns the join of its two String[][] arguments. Both arrays are supposed to be have an equal number of rows; otherwise an error message is shown and null is returned.- Parameters:
a
- - first joined arrayb
- - second joined array- Returns:
- - the result of joining both arrays. First array is on the left hand side, second array is on the right hand side.
-
join
public static java.lang.String[][] join(java.lang.String[][] a, java.lang.String[] b)
This method returns the join of a String[][] and a String[]. Both arrays are supposed to be have an equal number of rows; otherwise an error message is shown and null is returned.- Parameters:
a
- - first joined array (String[][])b
- - second joined array (String[])- Returns:
- - the result of joining both arrays. First array is on the left hand side, second array is on the right hand side.
-
-