Package microsim.data

Class ExportToCSV

java.lang.Object
microsim.data.ExportToCSV

public class ExportToCSV extends Object
ExportToCSV class allows the exporting of data to *.csv files. This is a useful alternative to exporting to an output database, as it is faster and produces separate files for each class of object. Note that only numbers, enums or strings are exported to *.csv files.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExportToCSV(@Nullable Object target)
    Allows the exporting of all fields (including private and inherited fields) of an object to a *.csv file named after the object's class name.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Export data to the *.csv files named after the class of the target object (or if a collection of objects, the class of the collection's members).
    extractFieldNames(boolean createdNowFlag, @NonNull TreeSet<String> fieldNameSet)
    Goes over a set of field names, tries to add them to the buffer.

    Methods inherited from class java.lang.Object

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

    • ExportToCSV

      public ExportToCSV(@Nullable @Nullable Object target)
      Allows the exporting of all fields (including private and inherited fields) of an object to a *.csv file named after the object's class name. Note that only numbers, enums or strings are exported to *.csv files. The serialVersionUID of a class will also not be exported.
      Parameters:
      target - The object whose fields will be exported to a *.csv file with a name equal to the object's class name. If the target is a Collection of objects, each member of the collection will have their individual fields exported to the *.csv file, labelled by their id. Can be null.
      Implementation Requirements:
      No export happens when target is null, but the attempt is logged.
  • Method Details

    • extractFieldNames

      @Nullable public @Nullable LinkedHashSet<String> extractFieldNames(boolean createdNowFlag, @NonNull @NonNull TreeSet<String> fieldNameSet)
      Goes over a set of field names, tries to add them to the buffer. Also copies them to the LinkedHashSet.
      Parameters:
      createdNowFlag - Shows if there is a need to create headers, but only if there was no file there.
      fieldNameSet - A set of strings that correspond to field names.
      Returns:
      null if can't add to the buffer, a LinkedHashSet otherwise.
      Throws:
      NullPointerException - when fieldNameSet is null.
    • dumpToCSV

      public void dumpToCSV()
      Export data to the *.csv files named after the class of the target object (or if a collection of objects, the class of the collection's members).
      Implementation Requirements:
      Only numbers, enums or strings are exported to *.csv files.