Initial commit of programmieren-2-projekt
This commit is contained in:
commit
d85a49407b
63
Besuch.java
Normal file
63
Besuch.java
Normal file
@ -0,0 +1,63 @@
|
||||
package project;
|
||||
|
||||
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 +
|
||||
'}';
|
||||
}
|
||||
}
|
105
Main.java
Normal file
105
Main.java
Normal file
@ -0,0 +1,105 @@
|
||||
package project;
|
||||
|
||||
import project.utils.Parser;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
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<>();
|
||||
|
||||
public static void main(String[] args) {
|
||||
Parser.parse("/project/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);
|
||||
}
|
||||
});
|
||||
} 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);
|
||||
}
|
||||
});
|
||||
} else if (args[0].contains("--kontaktpersonen")) {
|
||||
int id = Integer.parseInt(args[0].split("=")[1].replaceAll("\"", ""));
|
||||
|
||||
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)
|
||||
.sorted()
|
||||
.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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println(kontaktpersonen.stream()
|
||||
.map(Person::getName)
|
||||
.sorted()
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
||||
} else {
|
||||
System.out.println("Invalid paramater! \nUsage [Option]=\"[Value]\"\n--personensuche\n--ortsuche\n--kontaktpersonen\n--besucher");
|
||||
}
|
||||
} else {
|
||||
System.out.println("Invalid paramater! \nUsage [Option]=\"[Value]\"\n--personensuche\n--ortsuche\n--kontaktpersonen\n--besucher");
|
||||
}
|
||||
// persons.forEach((key, value) -> System.out.println(key + " " + value));
|
||||
// besuche.forEach(System.out::println);
|
||||
// orte.forEach((key, value) -> System.out.println(key + " " + value));
|
||||
}
|
||||
}
|
50
Ort.java
Normal file
50
Ort.java
Normal file
@ -0,0 +1,50 @@
|
||||
package project;
|
||||
|
||||
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 +
|
||||
'}';
|
||||
}
|
||||
}
|
39
Person.java
Normal file
39
Person.java
Normal file
@ -0,0 +1,39 @@
|
||||
package project;
|
||||
|
||||
public class Person {
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Person(String s) {
|
||||
|
||||
}
|
||||
|
||||
public Person(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
206
db/contacts2021.db
Normal file
206
db/contacts2021.db
Normal file
@ -0,0 +1,206 @@
|
||||
New_Entity: "person_id","person_name"
|
||||
"1","Mia"
|
||||
"2","Emilia"
|
||||
"3","Hannah"
|
||||
"4","Emma"
|
||||
"5","Sophia"
|
||||
"6","Lina"
|
||||
"7","Ella"
|
||||
"8","Mila"
|
||||
"9","Clara"
|
||||
"10","Lea"
|
||||
"11","Marie"
|
||||
"12","Anna"
|
||||
"13","Luisa"
|
||||
"14","Ida"
|
||||
"15","Leni"
|
||||
"16","Frieda"
|
||||
"17","Emily"
|
||||
"18","Lia"
|
||||
"19","Lena"
|
||||
"20","Mathilda"
|
||||
"21","Charlotte"
|
||||
"22","Leonie"
|
||||
"23","Amelie"
|
||||
"24","Johanna"
|
||||
"25","Sophie"
|
||||
"26","Maja"
|
||||
"27","Lilly"
|
||||
"28","Lara"
|
||||
"29","Nele"
|
||||
"30","Lotta"
|
||||
"31","Laura"
|
||||
"32","Sarah"
|
||||
"33","Nora"
|
||||
"34","Paula"
|
||||
"35","Juna"
|
||||
"36","Mira"
|
||||
"37","Elisa"
|
||||
"38","Helena"
|
||||
"39","Mara"
|
||||
"40","Melina"
|
||||
"41","Victoria"
|
||||
"42","Elena"
|
||||
"43","Alina"
|
||||
"44","Maria"
|
||||
"45","Thea"
|
||||
"46","Tilda"
|
||||
"47","Luna"
|
||||
"48","Marlene"
|
||||
"49","Carla"
|
||||
"50","Eva"
|
||||
"51","Romy"
|
||||
"52","Pia"
|
||||
"53","Paulina"
|
||||
"54","Elina"
|
||||
"55","Hailey"
|
||||
"56","Malia"
|
||||
"57","Merle"
|
||||
"58","Isabella"
|
||||
"59","Luise"
|
||||
"60","Anni"
|
||||
"61","Antonia"
|
||||
"62","Josephine"
|
||||
"63","Zoe"
|
||||
"64","Fiona"
|
||||
"65","Pauline"
|
||||
"66","Julia"
|
||||
"67","Olivia"
|
||||
"68","Finja"
|
||||
"69","Elli"
|
||||
"70","Lisa"
|
||||
"71","Martha"
|
||||
"72","Amalia"
|
||||
"73","Mina"
|
||||
"74","Amira"
|
||||
"75","Carlotta"
|
||||
"76","Isabell"
|
||||
"77","Jana"
|
||||
"78","Rosalie"
|
||||
"79","Lotte"
|
||||
"80","Alma"
|
||||
"81","Noah"
|
||||
"82","Ben"
|
||||
"83","Matteo"
|
||||
"84","Finn"
|
||||
"85","Leon"
|
||||
"86","Elias"
|
||||
"87","Paul"
|
||||
"88","Henry"
|
||||
"89","Louis"
|
||||
"90","Felix"
|
||||
"91","Luca"
|
||||
"92","Emil"
|
||||
"93","Jonas"
|
||||
"94","Theo"
|
||||
"95","Lukas"
|
||||
"96","Anton"
|
||||
"97","Liam"
|
||||
"98","Maximilian"
|
||||
"99","Jakob"
|
||||
"100","Leo"
|
||||
"101","Oskar"
|
||||
"102","Max"
|
||||
"103","Milan"
|
||||
"104","Karl"
|
||||
"105","David"
|
||||
"106","Moritz"
|
||||
"107","Julian"
|
||||
"108","Alexander"
|
||||
"109","Jonah"
|
||||
"110","Niklas"
|
||||
"111","Samuel"
|
||||
"112","Jonathan"
|
||||
"113","Lio"
|
||||
"114","Levi"
|
||||
"115","Mohammed"
|
||||
"116","Mats"
|
||||
"117","Raphael"
|
||||
"118","Aaron"
|
||||
"119","Philipp"
|
||||
"120","Tim"
|
||||
"121","Tom"
|
||||
"122","Linus"
|
||||
"123","Erik"
|
||||
"124","Mika"
|
||||
"125","Hannes"
|
||||
"126","Leonard"
|
||||
"127","Valentin"
|
||||
"128","Benjamin"
|
||||
"129","Johann"
|
||||
"130","Jannis"
|
||||
"131","Till"
|
||||
"132","Adrian"
|
||||
"133","Adam"
|
||||
"134","Simon"
|
||||
"135","Milo"
|
||||
"136","Theodor"
|
||||
"137","Joshua"
|
||||
"138","Jan"
|
||||
"139","Konstantin"
|
||||
"140","Arthur"
|
||||
"141","Lian"
|
||||
"142","Maxim"
|
||||
"143","Julius"
|
||||
"144","Vincent"
|
||||
"145","Fabian"
|
||||
"146","Marlon"
|
||||
"147","Nico"
|
||||
"148","Fiete"
|
||||
"149","Toni"
|
||||
"150","Daniel"
|
||||
"151","Lennard"
|
||||
"152","Mattis"
|
||||
"153","Carlo"
|
||||
"154","Johannes"
|
||||
"155","Fritz"
|
||||
"156","Kilian"
|
||||
"157","Jannik"
|
||||
"158","Ole"
|
||||
"159","Malik"
|
||||
"160","Emilio"
|
||||
New_Entity: "location_id","location_name","in_door"
|
||||
"1","Bäckerei","in_door"
|
||||
"2","Supermarkt","in_door"
|
||||
"3","Zoo","out_door"
|
||||
"4","Büro abc","in_door"
|
||||
"4","Büro xyz","in_door"
|
||||
"5","Spielplatz","out_door"
|
||||
"6","Großmarkt","in_door"
|
||||
New_Entity: "start_date", "end_date", "person_id", "location_id"
|
||||
"2021-05-15T15:00:00","2021-05-15T16:00:00","1","1"
|
||||
"2021-05-15T14:00:00","2021-05-15T15:00:01","2","1"
|
||||
"2021-05-15T14:16:00","2021-05-15T15:15:00","3","1"
|
||||
"2021-05-15T13:14:00","2021-05-15T14:14:00","4","1"
|
||||
"2021-05-15T14:14:00","2021-05-15T15:14:00","5","1"
|
||||
"2021-05-15T13:20:00","2021-05-15T13:59:59","6","1"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","1","3"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","2","3"
|
||||
"2021-05-15T11:16:00","2021-05-15T15:00:00","3","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","4","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","5","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","6","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","7","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","8","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","9","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","10","3"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","11","3"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","12","3"
|
||||
"2021-05-15T11:16:00","2021-05-15T15:00:00","13","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","14","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","15","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","16","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","17","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","18","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","19","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","20","3"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","21","3"
|
||||
"2021-05-15T11:00:00","2021-05-15T15:00:00","22","3"
|
||||
"2021-05-15T11:16:00","2021-05-15T15:00:00","23","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","24","3"
|
||||
"2021-05-15T11:14:00","2021-05-15T15:00:00","25","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","26","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","27","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","28","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","29","3"
|
||||
"2021-05-15T11:20:00","2021-05-15T15:00:00","30","3"
|
52
utils/Parser.java
Normal file
52
utils/Parser.java
Normal file
@ -0,0 +1,52 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
5
utils/db_new_entity.java
Normal file
5
utils/db_new_entity.java
Normal file
@ -0,0 +1,5 @@
|
||||
package project.utils;
|
||||
|
||||
public enum db_new_entity {
|
||||
PERSON, ORT, BESUCH
|
||||
}
|
Loading…
Reference in New Issue
Block a user