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 persons = new HashMap<>(); public static HashSet besuche = new HashSet<>(); public static HashMap 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 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 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)); } }