From 2dd8cc4f39dc9c6a52cd9e3b95c93a06c9ff746d Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 31 May 2018 09:45:43 +0200 Subject: [PATCH] =?UTF-8?q?kleine=20=C3=84nderungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../praktikum/praktikum4/KlausurenServer.java | 38 +++++-------------- .../resources/praktikum3/vorlesungen-db.txt | 2 +- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java index 67cf11e..802872b 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum4/KlausurenServer.java @@ -48,35 +48,17 @@ public class KlausurenServer { ConcurrentMap> set = new ConcurrentHashMap<>(data); Set> result = new HashSet<>(); - set.forEach((key, value) -> { - set.forEach((s, integers) -> { - if(!value.equals(integers)) { - if (integers.containsAll(value)) { - set.remove(key); - } + set.forEach((key, value) -> set.forEach((s, integers) -> { + if(!value.equals(integers)) { + if (integers.containsAll(value)) { + set.remove(key); } - }); - }); - - set.forEach((key, value) -> { - result.add(value); - }); - - /* - data.forEach((key, value) -> { - result.forEach(integers -> { - if(!integers.containsAll(value)) { - result.add(integers); - } - }); - }); - */ - Iterator> iterator = result.iterator(); - while (iterator.hasNext()) { - if(iterator.next().isEmpty()) { - iterator.remove(); } - } + })); + + set.forEach((key, value) -> result.add(value)); + + result.removeIf(TreeSet::isEmpty); writer.write(result.toString().substring(1, result.toString().length()-1).replace(" ", "")); } else { @@ -138,7 +120,7 @@ public class KlausurenServer { } catch (FileNotFoundException e) { e.printStackTrace(); } - try (BufferedReader br = new BufferedReader(fileReader)) { + try (BufferedReader br = new BufferedReader(Objects.requireNonNull(fileReader))) { for (String line = br.readLine(); line != null; line = br.readLine()) { TreeSet set = new TreeSet<>(); String[] array = line.split(":"); diff --git a/src/main/resources/praktikum3/vorlesungen-db.txt b/src/main/resources/praktikum3/vorlesungen-db.txt index 5fbff2c..59b11ad 100644 --- a/src/main/resources/praktikum3/vorlesungen-db.txt +++ b/src/main/resources/praktikum3/vorlesungen-db.txt @@ -1,4 +1,4 @@ -A1:Relativitätstheorie:Einstein:15 +A1:Relativitätstheorie:Einstein:15 B2:Quantenmechanik:Heisenberg:17 C2:Quantenphysik:Planck:5 T4:Thermodynamik:Kelvin:78