53 lines
2.5 KiB
Java
53 lines
2.5 KiB
Java
|
package project.utils;
|
||
|
|
||
|
import project.Besuch;
|
||
|
import project.Main;
|
||
|
import project.Ort;
|
||
|
import project.Person;
|
||
|
|
||
|
import java.io.BufferedReader;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStreamReader;
|
||
|
import java.time.LocalDateTime;
|
||
|
import java.time.format.DateTimeFormatter;
|
||
|
import java.util.Objects;
|
||
|
|
||
|
public class Parser {
|
||
|
private static db_new_entity new_entity = null;
|
||
|
|
||
|
public static void parse(String filename) {
|
||
|
try (BufferedReader bf = new BufferedReader(new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream(filename))))) {
|
||
|
String line;
|
||
|
while ((line = bf.readLine()) != null) {
|
||
|
if (line.toLowerCase().contains("new_entity")) {
|
||
|
if (line.toLowerCase().contains("start_date")) new_entity = db_new_entity.BESUCH;
|
||
|
else if (line.toLowerCase().contains("location_id")) new_entity = db_new_entity.ORT;
|
||
|
else if (line.toLowerCase().contains("person_id")) new_entity = db_new_entity.PERSON;
|
||
|
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (new_entity == db_new_entity.BESUCH) {
|
||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||
|
LocalDateTime start = LocalDateTime.parse(line.split(",")[0].replaceAll("\"", ""), formatter);
|
||
|
LocalDateTime end = LocalDateTime.parse(line.split(",")[1].replaceAll("\"", ""), formatter);
|
||
|
Person p = Main.persons.get(Integer.parseInt(line.split(",")[2].replaceAll("\"", "")));
|
||
|
Ort o = Main.orte.get(Integer.parseInt(line.split(",")[3].replaceAll("\"", "")));
|
||
|
Main.besuche.add(new Besuch(start, end, p, o));
|
||
|
} else if (new_entity == db_new_entity.ORT) {
|
||
|
int id = Integer.parseInt(line.split(",")[0].replaceAll("\"", ""));
|
||
|
String name = line.split(",")[1].replaceAll("\"", "");
|
||
|
boolean indoor = line.split(",")[2].replaceAll("\"", "").equals("in_door");
|
||
|
Main.orte.put(id, new Ort(id, name, indoor));
|
||
|
} else if (new_entity == db_new_entity.PERSON) {
|
||
|
int id = Integer.parseInt(line.split(",")[0].replaceAll("\"", ""));
|
||
|
String name = line.split(",")[1].replaceAll("\"", "");
|
||
|
Main.persons.put(id, new Person(id, name));
|
||
|
}
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|