Class CakeCSVParser


  • public class CakeCSVParser
    extends Object
    A CSV Parser, that uses the csv package from the Apache group. It's possible, to read a csv file and create aggregate objects of the entries. For this, a suitable model has to be defined.

    Because the creation of the objects runs in parallel, the order of the objects in the object pool isn't deterministic.

    Author:
    Alexander Schultheis, Maximilian Hoffmann
    • Constructor Detail

      • CakeCSVParser

        public CakeCSVParser()
    • Method Detail

      • getFilename

        public String getFilename()
      • setFilename

        public void setFilename​(String filename)
      • createAggregateObjects

        public List<AggregateObject> createAggregateObjects​(String className,
                                                            Integer maximumExamples)
        Parses the CSV file and creates a list of aggregate objects. Thereby, the source CSV file contains a header row with the attribute names.
        Parameters:
        className - the name of the class every example for the CSV belongs to
        maximumExamples - the maximum number to process. Ignore of null
        Returns:
        the list of parsed CSV entries
        See Also:
        createAggregateObjects(String, Integer)
      • createAggregateObjects

        public List<AggregateObject> createAggregateObjects​(String className,
                                                            boolean containsHeaders,
                                                            Integer maximumExamples)
        Parses the CSV file and creates a list of aggregate objects. It can be set if the CSV file contains a header row with the attribute names. The choice of the parameter containsHeaders and the value of mappingFile determine the behavior of this method. If mappingFile is not set and the file contains no headers, an exception will be thrown. In contrast, if the file contains headers then those will be used to map the values to the correct attributes. If mappingFile is set and the file contains no headers, then the parser can only work properly if column numbers are mapped to attribute names. If the file contains header information and mappingFile is set then the parser will use the given mappings, either column number or column name mappings, during processing.
        Parameters:
        className - the name of the class every example for the CSV belongs to
        containsHeaders - if the CSV file to parse contains headers
        maximumExamples - the maximum number to process. Ignore of null
        Returns:
        the list of parsed CSV entries
      • setMappingFile

        public void setMappingFile​(String filename)
      • disableMapping

        public void disableMapping()
        Do not use a mapping file for processing the CSV file. The parser will only work in this configuration if the CSV file contains a header row and the column names in the header row are equal to the attribute names in the aggregate object.
      • getDelimiter

        public char getDelimiter()
      • setDelimiter

        public void setDelimiter​(char delimiter)