Praktikum 3: multiple titles jetzt richtig

This commit is contained in:
Johannes Theiner 2018-04-23 10:15:14 +02:00
parent 5b5325fc29
commit 16df5c0fdf
1 changed files with 12 additions and 8 deletions

View File

@ -7,17 +7,16 @@ import java.util.*;
import java.util.stream.Collectors;
public class Vorlesungsverzeichnis implements Comparator<Vorlesung>{
private Set<Vorlesung> vorlesungen = new HashSet<>();
public Vorlesungsverzeichnis(String filename) throws IOException {
List<List<String>> datenbasis = load(filename);
for (List<String> 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<List<String>> datenbasis;
datenbasis = load(filename);
for (List<String> 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<Vorlesung>{
return map;
*/
Map<String, List<String>> map = vorlesungen.stream().collect(Collectors.groupingBy(Vorlesung::getTitle, Collectors.mapping(Vorlesung::getDozent, Collectors.toList())));
map.forEach((s, strings) -> Collections.sort(strings));
Iterator<Map.Entry<String, List<String>>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, List<String>> entry = iterator.next();
if(entry.getValue().size() < 2) iterator.remove();
Collections.sort(entry.getValue());
}
return map;