Package sc2002.FCS1.grp2
Class CSVEncoder
Object
CSVEncoder
Use this class to write CSV files for each supported types (such as the users and projects).
Encodable classes must subscribe to
CSVEncodable interface, in order to use for this class.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArrayList<CSVEncodable> Each row of data that should be written in the CSV file.private StringRepresents the header row.private StringThe path for which the CSV file should be written at. -
Constructor Summary
ConstructorsConstructorDescriptionCSVEncoder(String fileName, String headerLine, ArrayList<CSVEncodable> encodables) Construct using this constructor if CSV file is expected at the default location. -
Method Summary
Modifier and TypeMethodDescriptionvoidencode()Call this method to write the CSV file with the respective data at path.static StringencodeBoolean(boolean bool) Encode Booleans In caps, as it seems Excel does it this way.static StringencodeListOfStrings(List<String> strings) Encode a list of strings to be represented within a CSV cell.
-
Field Details
-
path
The path for which the CSV file should be written at. -
headerLine
Represents the header row. -
encodables
Each row of data that should be written in the CSV file.
-
-
Constructor Details
-
CSVEncoder
CSVEncoder(String fileName, String headerLine, ArrayList<CSVEncodable> encodables) Construct using this constructor if CSV file is expected at the default location. (bin/sc2002/FCS1/grp2/files)- Parameters:
fileName- The name of the file.encodables- Data that represents each row of the CSV file to be written.
-
-
Method Details
-
encode
Call this method to write the CSV file with the respective data at path.- Throws:
IOException- if path provided could not be used to write the file, for whatever reason.
-
encodeBoolean
Encode Booleans In caps, as it seems Excel does it this way.- Parameters:
bool- The boolean- Returns:
- encoded boolean ready for a CSV cell.
-
encodeListOfStrings
Encode a list of strings to be represented within a CSV cell.- Parameters:
strings- list of strings.- Returns:
- a string, accurately formatted for future decodes.
-