Class CSVEncoder

Object
CSVEncoder

public class CSVEncoder extends Object
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 Details

    • path

      private String path
      The path for which the CSV file should be written at.
    • headerLine

      private String headerLine
      Represents the header row.
    • encodables

      private ArrayList<CSVEncodable> 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

      public void encode() throws IOException
      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

      public static String encodeBoolean(boolean bool)
      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

      public static String encodeListOfStrings(List<String> strings)
      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.