Class SubmissionMapper<T extends VilleSubmissionFields>
java.lang.Object
studentrepoloader.model.villecsv.mapper.SubmissionMapper<T>
- Type Parameters:
T
- A type that extendsVilleSubmissionFields
, usually a default record or data class.
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 apublic
or accessible constructor takingString[]
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 Summary
ConstructorsConstructorDescriptionSubmissionMapper
(ViLLeCsvFile csvFile, Class<? extends T> recordClass) Constructs a new SubmissionMapper for a specific CSV file and target record class. -
Method Summary
Modifier and TypeMethodDescriptionInstantiates and returns a list of submissions from the CSV file.
-
Constructor Details
-
SubmissionMapper
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:
This constructor will be called for each row parsed from the CSV.public YourSubmissionClass(String[] csvRow, ViLLeCsvFile sourceFile)
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 implementingT
with a valid constructor accepting(String[], ViLLeCsvFile)
.- Throws:
IllegalArgumentException
- if the required constructor is not found.
-
-
Method Details
-
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.
-