feat(creation): implement file-based collection strategy

- add file settings to FileFillStrategy
- read students from CSV using StudentCsvReader
- create collection from file data
- handle file reading errors
This commit is contained in:
2026-09-01 22:24:06 +04:00
parent bd5aef0c65
commit a98265b44e
@@ -1,19 +1,37 @@
package ru.project.ui.creation.file;
import java.io.IOException;
import java.nio.file.Path;
import ru.project.collection.MyLinkedList;
import ru.project.collection.MyList;
import ru.project.io.StudentCsvReader;
import ru.project.student.Student;
import ru.project.ui.creation.FillStrategy;
public class FileFillStrategy implements FillStrategy {
// private final FileFillSettings settings;
private final FileFillSettings settings;
public FileFillStrategy(FileFillSettings settings) {
// this.settings = settings;
this.settings = settings;
}
@Override
public MyList<Student> create() {
return null;
MyList<Student> collection = new MyLinkedList<>();
Path path = Path.of(settings.getAbsoluteFilePath());
try (StudentCsvReader reader = new StudentCsvReader(path)) {
while (reader.hasNext()) {
collection.add(reader.next());
}
} catch (IOException e) {
throw new RuntimeException("Не удалось прочитать коллекцию из файла.", e);
}
return collection;
}
}