I found the following code that adds an item under certain circumstances (if it's not OLD) to the list. After that, the list will be packed into a general management list.
List<ListDataContent> list = new ArrayList<>(); for (KonditionValue kondition : konditions) { if (kondition.getStatusKz().equals(StatusKz.OLD)) continue; for (TermKondValue tilg : kondition.getTermimKonditions()) { if (tilg.getStatusKz().equals(StatusKz.OLD)) continue; TerminKondListContent listContent = new TerminKondListContent(tilg, kondition.getChangeDatum(), funds); list.add(listContent); } } SimpleListControl listCtrl = new SimpleListControl(); listCtrl.setDataModel(new ListDataModel(list));
I tried the following refactoring using java8 threads:
List<ListDataContent> list = konditionen.stream().map(kondition -> map(tilg, kondition.getChangeDate(), funds)).sorted().collect(Collectors.toList()); SimpleListControl listCtrl = new SimpleListControl(); listCtrl.setDataModel(new ListDataModel(list));
The problem is the map method ...
private TerminKondListContent map(TermKondValue tilg, Date changeDate, BigDecimal funds) { if (kondition.getStatusKz().equals(StatusKz.OLD)) return null; for (TermKondValue zins : kondition.getTerminkonditions()) { if (zins.getStatusKz().equals(StatusKz.OLD)) return null; return new TerminKondListContent(tilg, changeDate, funds); } return null; }
What can I do if I continue? return null? Then I could filter the null values ββfrom the stream through
list.stream().filter( Objects::nonNull )
Is Optionals used here?
source share