Class SubmissionMapper<T extends VilleSubmissionFields>

java.lang.Object
studentrepoloader.model.villecsv.mapper.SubmissionMapper<T>
Type Parameters:
T - A type that extends VilleSubmissionFields, usually a default record or data class.

public class SubmissionMapper<T extends VilleSubmissionFields> extends Object
SubmissionMapper transforms rows from a parsed ViLLe CSV file into typed Java objects that implement the VilleSubmissionFields interface or its subinterfaces.

To use, you must provide:

  • a ViLLeCsvFile containing parsed CSV rows (excluding header)
  • a class that implements T and has a public or accessible constructor taking String[]

Example usage:


 var mapper = SubmissionMapper.of(csvFile, DefaultGitLabSubmission.class);
 List<DefaultGitLabSubmission> entries = mapper.getSubmissionList();
 

This design uses reflection for flexibility while enforcing structure via generics and constructor checks. The Class<T> is required at runtime to perform reflective instantiation due to Java's type erasure.

  • Constructor Details

    • SubmissionMapper

      public SubmissionMapper(ViLLeCsvFile csvFile, Class<? extends T> recordClass)
      Constructs a new SubmissionMapper for a specific CSV file and target record class.

      The given class must declare a public constructor with the following signature:

      
       public YourSubmissionClass(String[] csvRow, ViLLeCsvFile sourceFile)
       
      This constructor will be called for each row parsed from the CSV.

      The Class<T> is explicitly required to bypass Java’s type erasure and support reflective instantiation.

      Parameters:
      csvFile - Parsed ViLLe CSV file (including header and rows).
      recordClass - A class implementing T with a valid constructor accepting (String[], ViLLeCsvFile).
      Throws:
      IllegalArgumentException - if the required constructor is not found.
  • Method Details

    • getSubmissionList

      public List<T> getSubmissionList()
      Instantiates and returns a list of submissions from the CSV file. Each row is passed directly into the target type’s constructor.

      If the constructor throws (e.g., due to out-of-bounds access or invalid format), a RuntimeException will be raised.

      Returns:
      List of instantiated submission objects of type T.