From 16df5c0fdf14276575396813dae493e4c3442133 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Mon, 23 Apr 2018 10:15:14 +0200 Subject: [PATCH] Praktikum 3: multiple titles jetzt richtig --- .../praktikum3/Vorlesungsverzeichnis.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java index f530ab0..9ee5f75 100644 --- a/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java +++ b/src/main/java/de/joethei/hs/java2/praktikum/praktikum3/Vorlesungsverzeichnis.java @@ -7,17 +7,16 @@ import java.util.*; import java.util.stream.Collectors; public class Vorlesungsverzeichnis implements Comparator{ + private Set vorlesungen = new HashSet<>(); public Vorlesungsverzeichnis(String filename) throws IOException { + List> datenbasis = load(filename); + for (List entry : datenbasis) { + if (entry.size() != 4) throw new TextFileFormatException("unexpected number of Strings in line"); + for (String s : entry) if (s.isEmpty()) throw new TextFileFormatException("empty attribute"); - List> datenbasis; - datenbasis = load(filename); - for (List a : datenbasis) { - if (a.size() != 4) throw new TextFileFormatException("unexpected number of Strings in line"); - for (String s : a) if (s.isEmpty()) throw new TextFileFormatException("empty attribute"); - - vorlesungen.add(new Vorlesung(a)); + vorlesungen.add(new Vorlesung(entry)); } } @@ -120,8 +119,13 @@ public class Vorlesungsverzeichnis implements Comparator{ return map; */ Map> map = vorlesungen.stream().collect(Collectors.groupingBy(Vorlesung::getTitle, Collectors.mapping(Vorlesung::getDozent, Collectors.toList()))); - map.forEach((s, strings) -> Collections.sort(strings)); + Iterator>> iterator = map.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry> entry = iterator.next(); + if(entry.getValue().size() < 2) iterator.remove(); + Collections.sort(entry.getValue()); + } return map;