Class Csv


  • public final class Csv
    extends java.lang.Object
    Basic CSV parser. The Csv class provides very basic CSV file parsing and assumes that CSV files are in a strict format. CSV files are expected to conform to the following syntax: - First line contains only the number of rows to be read as an integer. - Second line is a strictly comma separated row of type strings, where each type string has no preceeding or following whitespace. An example of a type string would be: int,int,float,char This type string informs the parser that the rows of the table have four cells of which the first two are integers and the last two are floating point numbers. Only three type strings are supported: 'int', 'float' and 'char'. - Third line and onwards. These are the table rows. They are expected to conform to the type format specified in the type line (line 2). As well as this all rows are expected to have length equal to the type row. Cells in each row are strictly comma separated and contain no whitespace. Each cell is expected to be in a format that Java can parse using parseInt() for integer types, parseDouble() for floating point types, and char data types are expected to be a single character optionally enclosed in single or double quotation marks. An example of several CSV rows which adhere to the previously given type row: 1,16,3.900,'A' 1,17,2.700,'-' 1,18,2.100,'B' 2,19,4.500,'C' 2,20,1.050,'-' 2,21,0.150,'D'
    • Constructor Summary

      Constructors 
      Constructor Description
      Csv()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object[][] readFile​(java.lang.String path)
      Read a file at location 'path' and parse it as a CSV file.
      static int[][] readIntsFile​(java.lang.String path)
      A helper function that casts and returns a CSV file consisting entirely of ints on all rows and columns.
      • Methods inherited from class java.lang.Object

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

      • Csv

        public Csv()
    • Method Detail

      • readFile

        public static java.lang.Object[][] readFile​(java.lang.String path)
        Read a file at location 'path' and parse it as a CSV file.
        Parameters:
        path - The string path to the CSV file.
        Returns:
        A two dimensional object array where each row is one row from the CSV file and each sub array element is one cell from one row in the CSV file. The underlying objects are of the correct boxed type as specified in the type line of the CSV file and can be cast back to their type.
      • readIntsFile

        public static int[][] readIntsFile​(java.lang.String path)
        A helper function that casts and returns a CSV file consisting entirely of ints on all rows and columns. Useful for loading the atoms table.
        Parameters:
        path - The string path to the CSV file.
        Returns:
        A two dimensional ints array.