Package microsim.data
Class ExportToCSV
java.lang.Object
microsim.data.ExportToCSV
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
ConstructorDescriptionExportToCSV
(@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 TypeMethodDescriptionvoid
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).@Nullable LinkedHashSet<String>
extractFieldNames
(boolean createdNowFlag, @NonNull TreeSet<String> fieldNameSet) Goes over a set of field names, tries to add them to the buffer.
-
Constructor Details
-
ExportToCSV
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. TheserialVersionUID
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 aCollection
of objects, each member of the collection will have their individual fields exported to the*.csv
file, labelled by their id. Can benull
.- Implementation Requirements:
- No export happens when
target
isnull
, 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 theLinkedHashSet
.- 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, aLinkedHashSet
otherwise.- Throws:
NullPointerException
- whenfieldNameSet
isnull
.
-
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.
-