Class 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 format
      static void exportToDisk​(float[][] matrix, java.io.File f, java.lang.String delimiter)
      This method exports a float[][] to disk with delimited format
      static void exportToDisk​(int[][] matrix, java.io.File f, java.lang.String delimiter)
      This method exports an int[][] to disk with delimited format
      static 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 exception
      static java.lang.String[][] importFromDisk​(java.io.File f, java.lang.String delimiter)
      This method imports from disk a String[][] written with delimited format
      static double[][] importFromDisk​(java.io.File f, java.lang.String delimiter, double dummy)
      This method imports a double[][] from a delimited file
      static float[][] importFromDisk​(java.io.File f, java.lang.String delimiter, float dummy)
      This method imports a float[][] from a delimited file
      static int[][] importFromDisk​(java.io.File f, java.lang.String delimiter, int dummy)
      This method imports an int[][] from a delimited file
      static 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 format
      static float[][] loadFromDisk​(java.io.File f, float dummy)
      This method reads from disk an float[][] written with binary format
      static int[][] loadFromDisk​(java.io.File f, int dummy)
      This method reads from disk an int[][] written with binary format
      static void printToScreen​(double[][] matrix)
      This method prints to screen a double[][] with fixed (8.3) column and decimal widths
      static void printToScreen​(float[][] matrix)
      This method prints to screen a float[][] with fixed (8.3) column and decimal widths
      static void printToScreen​(int[][] matrix)
      This method prints to screen an int[][] with fixed (8) column widths
      static 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 widths
      static void printToScreen3​(java.lang.String[][] matrix)
      This method prints to screen a String[][] with minimum and possibly different widths for each column
      static double[][] product​(double[][] a, double[][] b)
      This method returns the product of its two double[][] arguments
      static float[][] product​(float[][] a, float[][] b)
      This method returns the product of its two float[][] arguments
      static int[][] product​(int[][] a, int[][] b)
      This method returns the product of its two int[][] arguments
      static void saveToDisk​(java.io.File f, double[][] matrix)
      This method writes an double[][] to disk, with binary format
      static void saveToDisk​(java.io.File f, float[][] matrix)
      This method writes a float[][] to disk, with binary format
      static void saveToDisk​(java.io.File f, int[][] matrix)
      This method writes an int[][] to disk, with binary format
      static double[][] sum​(double[][] a, double[][] b)
      This method returns the sum of its two double[][] arguments
      static float[][] sum​(float[][] a, float[][] b)
      This method returns the sum of its two float[][] arguments
      static int[][] sum​(int[][] a, int[][] b)
      This method returns the sum of its two int[][] arguments
      static double sumMainDiagonal​(double[][] matrix)
      This method returns the sum of the items placed in the main diagonal for the given array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OpMat

        public OpMat()
    • 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 to
        matrix - - 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 to
        matrix - - 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 to
        matrix - - 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 from
        dummy - - 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 from
        dummy - - 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 from
        dummy - - 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 from
        delimiter - - 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 from
        delimiter - - the delimiter to be inserted between consecutive fields
        dummy - - 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 from
        delimiter - - the delimiter to be inserted between consecutive fields
        dummy - - 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 from
        delimiter - - the delimiter to be inserted between consecutive fields
        dummy - - 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 exported
        f - - the File that points to a file
        delimiter - - 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 exported
        f - - the File that points to a file
        delimiter - - 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 exported
        f - - the File that points to a file
        delimiter - - 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 file
        f - the file to write the table to
        delimiter - 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 factor
        b - - 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 factor
        b - - 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 factor
        b - - 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 factor
        b - - 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 factor
        b - - 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 factor
        b - - 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 array
        b - - 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.