Improved functions, fixed functions, refactoring
This commit is contained in:
parent
bc8a12661f
commit
0466ca60f6
@ -1,63 +0,0 @@
|
||||
package de.dhbw.contactdb;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Besuch {
|
||||
private LocalDateTime start;
|
||||
private LocalDateTime end;
|
||||
private Person person;
|
||||
private Ort ort;
|
||||
|
||||
public Besuch(String s) {
|
||||
|
||||
}
|
||||
|
||||
public Besuch(LocalDateTime start, LocalDateTime end, Person person, Ort ort) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.person = person;
|
||||
this.ort = ort;
|
||||
}
|
||||
|
||||
public LocalDateTime getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(LocalDateTime start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public LocalDateTime getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(LocalDateTime end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public Ort getOrt() {
|
||||
return ort;
|
||||
}
|
||||
|
||||
public void setOrt(Ort ort) {
|
||||
this.ort = ort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Besuch{" +
|
||||
"start=" + start +
|
||||
", end=" + end +
|
||||
", person=" + person +
|
||||
", ort=" + ort +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -4,103 +4,218 @@ import de.dhbw.contactdb.utils.Parser;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static HashMap<Integer, Person> persons = new HashMap<>();
|
||||
public static HashSet<Besuch> besuche = new HashSet<>();
|
||||
public static HashMap<Integer, Ort> orte = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Main class
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* Contains all persons from contacts2021.db
|
||||
*
|
||||
* @see de.dhbw.contactdb.utils.Parser
|
||||
*/
|
||||
public static HashMap<Integer, Person> persons = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Contains all places from contacts2021.db
|
||||
*
|
||||
* @see de.dhbw.contactdb.utils.Parser
|
||||
*/
|
||||
public static HashMap<Integer, Place> places = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Contains all visits from contacts2021.db
|
||||
*
|
||||
* @see de.dhbw.contactdb.utils.Parser
|
||||
*/
|
||||
public static HashSet<Visit> visits = new HashSet<>();
|
||||
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*
|
||||
* @param args String that contains program arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Parser.parse("/de/dhbw/contactdb/db/contacts2021.db");
|
||||
|
||||
if (args.length == 1) {
|
||||
if (args[0].contains("--personensuche")) {
|
||||
String s = args[0].split("=")[1].replaceAll("\"", "").toLowerCase();
|
||||
|
||||
System.out.println("Personensuche: " + s);
|
||||
|
||||
persons.forEach((key, value) -> {
|
||||
if (value.getName().toLowerCase().contains(s)) {
|
||||
System.out.println(value);
|
||||
}
|
||||
});
|
||||
searchForPerson(getSearchString(args[0]));
|
||||
} else if (args[0].contains("--ortssuche")) {
|
||||
String s = args[0].split("=")[1].replaceAll("\"", "").toLowerCase();
|
||||
|
||||
System.out.println("Ortssuche: " + s);
|
||||
|
||||
orte.forEach((key, value) -> {
|
||||
if (value.getName().toLowerCase().contains(s)) {
|
||||
System.out.println(value);
|
||||
}
|
||||
});
|
||||
searchForPlace(getSearchString(args[0]));
|
||||
} else if (args[0].contains("--kontaktpersonen")) {
|
||||
int id = Integer.parseInt(args[0].split("=")[1].replaceAll("\"", ""));
|
||||
int id = Integer.parseInt(getSearchString(args[0]));
|
||||
|
||||
System.out.println("Kontaktpersonen: " + id);
|
||||
|
||||
List<Person> kontaktpersonen = new ArrayList<>();
|
||||
besuche.forEach(value -> {
|
||||
if (value.getPerson().getId() == id) {
|
||||
if(value.getOrt().isIndoor()) {
|
||||
besuche.forEach(besuch -> {
|
||||
if(besuch.getOrt().getId() == value.getOrt().getId()) {
|
||||
if(!(besuch.getStart().isBefore(value.getStart()) && besuch.getEnd().isBefore(value.getStart())) && !besuch.getStart().isAfter(value.getEnd())) {
|
||||
kontaktpersonen.add(besuch.getPerson());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println(kontaktpersonen.stream()
|
||||
.map(Person::getName)
|
||||
System.out.println(getContactPersons(id).stream()
|
||||
.filter(visit -> visit.getPerson().getId() != id)
|
||||
.map(visit -> visit.getPerson().getName())
|
||||
.sorted()
|
||||
.distinct()
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
||||
} else if (args[0].contains("--besucher")) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
int id = Integer.parseInt(args[0].split("=")[1].split(",")[0].replaceAll("\"", ""));
|
||||
LocalDateTime d = LocalDateTime.parse(args[0].split("=")[1].split(",")[1].replaceAll("\"", ""), formatter);
|
||||
|
||||
System.out.println("Besucher: " + id + " " + d);
|
||||
|
||||
// TODO
|
||||
List<Person> kontaktpersonen = new ArrayList<>();
|
||||
besuche.forEach(value -> {
|
||||
if (value.getOrt().getId() == id) {
|
||||
if(value.getOrt().isIndoor()) {
|
||||
besuche.forEach(besuch -> {
|
||||
if(!(besuch.getStart().isBefore(value.getStart()) && besuch.getEnd().isBefore(value.getStart())) && !besuch.getStart().isAfter(value.getEnd())) {
|
||||
kontaktpersonen.add(besuch.getPerson());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Outdoor
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println(kontaktpersonen.stream()
|
||||
.map(Person::getName)
|
||||
System.out.println(getVisitors(args[0]).stream()
|
||||
.map(visit -> visit.getPerson().getName())
|
||||
.sorted()
|
||||
.distinct()
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
||||
} else {
|
||||
System.out.println("Invalid paramater! \nUsage [Option]=\"[Value]\"\n--personensuche\n--ortsuche\n--kontaktpersonen\n--besucher");
|
||||
argument_error();
|
||||
}
|
||||
} else {
|
||||
System.out.println("Invalid paramater! \nUsage [Option]=\"[Value]\"\n--personensuche\n--ortsuche\n--kontaktpersonen\n--besucher");
|
||||
argument_error();
|
||||
}
|
||||
// persons.forEach((key, value) -> System.out.println(key + " " + value));
|
||||
// besuche.forEach(System.out::println);
|
||||
// orte.forEach((key, value) -> System.out.println(key + " " + value));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints error message
|
||||
*
|
||||
* @author florian kaiser
|
||||
*/
|
||||
private static void argument_error() {
|
||||
System.out.println("Invalid parameter! \nUsage [Option]=\"[Value]\"\n--personensuche\n--ortssuche\n--kontaktpersonen\n--besucher");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches the HashMap places for a specific string
|
||||
* @param search String that contains search value
|
||||
*
|
||||
* @author florian kaiser
|
||||
*/
|
||||
public static void searchForPlace(String search) {
|
||||
places.forEach((key, value) -> {
|
||||
if (value.getName().toLowerCase().contains(search)) {
|
||||
System.out.println(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches the HashMap persons for a specific string
|
||||
* @param search String that contains search value
|
||||
*
|
||||
* @author florian kaiser
|
||||
*/
|
||||
public static void searchForPerson(String search) {
|
||||
persons.forEach((key, value) -> {
|
||||
if (value.getName().toLowerCase().contains(search)) {
|
||||
System.out.println(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists all persons that were at the same place at the same time as a specific person.
|
||||
* Only if the place is indoor
|
||||
*
|
||||
* @param id Contains the id of a person
|
||||
* @return List that contains visits
|
||||
*
|
||||
* @author florian kaiser
|
||||
*/
|
||||
public static List<Visit> getContactPersons(int id) {
|
||||
List<Visit> places_where_id_was_indoor;
|
||||
places_where_id_was_indoor = visits.stream()
|
||||
.filter(visit -> visit.getPlace().isIndoor())
|
||||
.filter(visit -> visit.getPerson().getId() == id)
|
||||
.toList();
|
||||
|
||||
List<Visit> contacts_of_id = new ArrayList<>();
|
||||
for (Visit filtered_b : places_where_id_was_indoor) {
|
||||
for (Visit b : visits) {
|
||||
if (b.isOverlapping(filtered_b.getStart(), filtered_b.getEnd()) && filtered_b.getPlace().getId() == b.getPlace().getId()) {
|
||||
contacts_of_id.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return contacts_of_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists all Persons that were at the same place (id) at the same time.
|
||||
* If the place is indoor, the contact persons of each person is added to the result too.
|
||||
*
|
||||
* @param s contains program argument (id of place and date string, separated by comma)
|
||||
* @return List that contains visits
|
||||
*
|
||||
* @author florian kaiser
|
||||
*/
|
||||
public static List<Visit> getVisitors(String s) {
|
||||
int id = Integer.parseInt(s.split("=")[1].split(",")[0].replaceAll("\"", ""));
|
||||
LocalDateTime d;
|
||||
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
d = LocalDateTime.parse(s.split("=")[1].split(",")[1].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e1) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
|
||||
d = LocalDateTime.parse(s.split("=")[1].split(",")[1].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e2) {
|
||||
argument_error();
|
||||
System.exit(-2);
|
||||
throw e1;
|
||||
}
|
||||
}
|
||||
|
||||
LocalDateTime finalD = d;
|
||||
List<Visit> place_date_visits = visits.stream()
|
||||
.filter(visit -> visit.getPlace().getId() == id)
|
||||
.filter(visit -> visit.isInTimePeriod(finalD))
|
||||
.toList();
|
||||
|
||||
List<Visit> all = new ArrayList<>();
|
||||
for (Visit visit : place_date_visits) {
|
||||
if (visit.getPlace().isIndoor()) {
|
||||
all.addAll(getContactPersons(visit.getPerson().getId()));
|
||||
} else {
|
||||
all.add(visit);
|
||||
}
|
||||
}
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts string from String.
|
||||
* Exits program if string is empty, blank or not available
|
||||
*
|
||||
* @param s Contains program argument
|
||||
* @return extracted string
|
||||
*/
|
||||
public static String getSearchString(String s) {
|
||||
try {
|
||||
s = s.split("=")[1].replaceAll("\"", "").toLowerCase();
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
argument_error();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
if (s.isEmpty() || s.isBlank()) {
|
||||
argument_error();
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package de.dhbw.contactdb;
|
||||
|
||||
public class Ort {
|
||||
private int id;
|
||||
private String name;
|
||||
private boolean indoor;
|
||||
|
||||
public Ort(String s) {
|
||||
|
||||
}
|
||||
|
||||
public Ort(int id, String name, boolean indoor) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.indoor = indoor;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isIndoor() {
|
||||
return indoor;
|
||||
}
|
||||
|
||||
public void setIndoor(boolean indoor) {
|
||||
this.indoor = indoor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Ort{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", indoor=" + indoor +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,34 +1,69 @@
|
||||
package de.dhbw.contactdb;
|
||||
|
||||
|
||||
/**
|
||||
* Person
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
*/
|
||||
public class Person {
|
||||
/**
|
||||
* ID of person
|
||||
*/
|
||||
private int id;
|
||||
|
||||
|
||||
/**
|
||||
* Name of person
|
||||
*/
|
||||
private String name;
|
||||
|
||||
public Person(String s) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id ID of person
|
||||
* @param name Name of person
|
||||
*/
|
||||
public Person(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #id}
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id {@link #id}
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #name}
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name {@link #name}
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
|
90
src/de/dhbw/contactdb/Place.java
Normal file
90
src/de/dhbw/contactdb/Place.java
Normal file
@ -0,0 +1,90 @@
|
||||
package de.dhbw.contactdb;
|
||||
|
||||
|
||||
/**
|
||||
* Main class
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
*/
|
||||
public class Place {
|
||||
/**
|
||||
* ID of place
|
||||
*/
|
||||
private int id;
|
||||
|
||||
|
||||
/**
|
||||
* name of place
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* is place indoor
|
||||
*/
|
||||
private final boolean indoor;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id ID of place
|
||||
* @param name Name of place
|
||||
* @param indoor is place indoor
|
||||
*/
|
||||
public Place(int id, String name, boolean indoor) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.indoor = indoor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #id}
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id {@link #id}
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #name}
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name {@link #name}
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #indoor}
|
||||
*/
|
||||
public boolean isIndoor() {
|
||||
return indoor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Ort{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", indoor=" + indoor +
|
||||
'}';
|
||||
}
|
||||
}
|
138
src/de/dhbw/contactdb/Visit.java
Normal file
138
src/de/dhbw/contactdb/Visit.java
Normal file
@ -0,0 +1,138 @@
|
||||
package de.dhbw.contactdb;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* Main class
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
*/
|
||||
public class Visit {
|
||||
/**
|
||||
* start date of visit
|
||||
*/
|
||||
private LocalDateTime start;
|
||||
|
||||
|
||||
/**
|
||||
* end date of visit
|
||||
*/
|
||||
private LocalDateTime end;
|
||||
|
||||
|
||||
/**
|
||||
* person who visits
|
||||
*/
|
||||
private Person person;
|
||||
|
||||
|
||||
/**
|
||||
* place where person is
|
||||
*/
|
||||
private final Place place;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param start start date of visit
|
||||
* @param end end date of visit
|
||||
* @param person person who visits
|
||||
* @param place place where person is
|
||||
*/
|
||||
public Visit(LocalDateTime start, LocalDateTime end, Person person, Place place) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.person = person;
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #start}
|
||||
*/
|
||||
public LocalDateTime getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param start {@link #start}
|
||||
*/
|
||||
public void setStart(LocalDateTime start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #end}
|
||||
*/
|
||||
public LocalDateTime getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param end {@link #end}
|
||||
*/
|
||||
public void setEnd(LocalDateTime end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #person}
|
||||
*/
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param person {@link #person}
|
||||
*/
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {@link #place}
|
||||
*/
|
||||
public Place getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param start Start of timespan
|
||||
* @param end End of timespan
|
||||
*
|
||||
* @return boolean if timespan between start and end is overlapping timespan between this visits start and end
|
||||
*/
|
||||
public boolean isOverlapping(LocalDateTime start, LocalDateTime end) {
|
||||
return ((null == end) || this.start.isBefore(end)) && ((null == this.end) || start.isBefore(this.end));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param inputTime time
|
||||
*
|
||||
* @return boolean if time is between this visits start and end
|
||||
*/
|
||||
public boolean isInTimePeriod(LocalDateTime inputTime) {
|
||||
return this.start.isBefore(inputTime) && this.end.isAfter(inputTime) || this.end.equals(inputTime) || this.start.equals(inputTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Besuch{" +
|
||||
"start=" + start +
|
||||
", end=" + end +
|
||||
", person=" + person +
|
||||
", ort=" + place +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package de.dhbw.contactdb.utils;
|
||||
|
||||
import de.dhbw.contactdb.Besuch;
|
||||
import de.dhbw.contactdb.Place;
|
||||
import de.dhbw.contactdb.Visit;
|
||||
import de.dhbw.contactdb.Main;
|
||||
import de.dhbw.contactdb.Ort;
|
||||
import de.dhbw.contactdb.Person;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -11,41 +11,81 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
|
||||
/**
|
||||
* Parser for parsing contacts2021.db
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
*/
|
||||
public class Parser {
|
||||
/**
|
||||
* Saves type of current line in database
|
||||
*/
|
||||
private static db_new_entity new_entity = null;
|
||||
|
||||
|
||||
/**
|
||||
* Parses contacts.db, creates objects of content and saves these objects in HashMaps
|
||||
*
|
||||
* @param filename Filename and path of contacts.db
|
||||
*/
|
||||
public static void parse(String filename) {
|
||||
InputStream db = Main.class.getResourceAsStream(filename);
|
||||
|
||||
if(db == null) {
|
||||
System.err.println("Cannot find database!");
|
||||
System.exit(-1);
|
||||
System.exit(-3);
|
||||
}
|
||||
|
||||
try (BufferedReader bf = new BufferedReader(new InputStreamReader(db))) {
|
||||
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;
|
||||
if (line.toLowerCase().contains("start_date")) new_entity = db_new_entity.VISIT;
|
||||
else if (line.toLowerCase().contains("location_id")) new_entity = db_new_entity.PLACE;
|
||||
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) {
|
||||
if (new_entity == db_new_entity.VISIT) {
|
||||
LocalDateTime start = null;
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
start = LocalDateTime.parse(line.split(",")[0].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e1) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
|
||||
start = LocalDateTime.parse(line.split(",")[0].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e2) {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
LocalDateTime end = null;
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
end = LocalDateTime.parse(line.split(",")[1].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e1) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
|
||||
end = LocalDateTime.parse(line.split(",")[1].replaceAll("\"", ""), formatter);
|
||||
} catch (DateTimeParseException e2) {
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
Person person = Main.persons.get(Integer.parseInt(line.split(",")[2].replaceAll("\"", "")));
|
||||
Place place = Main.places.get(Integer.parseInt(line.split(",")[3].replaceAll("\"", "")));
|
||||
Main.visits.add(new Visit(start, end, person, place));
|
||||
} else if (new_entity == db_new_entity.PLACE) {
|
||||
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));
|
||||
Main.places.put(id, new Place(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("\"", "");
|
||||
|
@ -1,5 +1,29 @@
|
||||
package de.dhbw.contactdb.utils;
|
||||
|
||||
|
||||
/**
|
||||
* Used by Parser
|
||||
*
|
||||
* @author florian kaiser
|
||||
* @version 1.0
|
||||
* @since 21.06.2021
|
||||
* @see de.dhbw.contactdb.utils.Parser
|
||||
*/
|
||||
public enum db_new_entity {
|
||||
PERSON, ORT, BESUCH
|
||||
/**
|
||||
* Person
|
||||
*/
|
||||
PERSON,
|
||||
|
||||
|
||||
/**
|
||||
* Place
|
||||
*/
|
||||
PLACE,
|
||||
|
||||
|
||||
/**
|
||||
* Visit
|
||||
*/
|
||||
VISIT
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user