I want to use the filter in a stream only if a checkbox is selected or on an selected index > 1
In the example below there is only 1 filter but I want to use more than one. Is it possible to implement an if condition ?
List<SoeEntry> sortedList = soeArraylist.stream()
.filter(p -> p.getEntryDoy().equals(comboBoxDoys.getSelectedItem()))
.sorted(
Comparator
.comparing(SoeEntry::getEntryGSAT)
.thenComparing(SoeEntry::getEntryNumber)
)
.collect(Collectors.toList());
sortedList.forEach(System.out::println);
Something like
if(comboBox1.getSelectedIndex() > 1) {.filter(p -> p.getEntryDoy().equals(comboBox1.getSelectedItem()))}
if(comboBox2.getSelectedIndex() > 1) {.filter(p -> p.getEntryGSAT().equals(comboBox2.getSelectedItem()))}
if(comboBox3.getSelectedIndex() > 1) {.filter(p -> p.getEntryDuration().equals(comboBox3.getSelectedItem()))}
EDIT: I will try to explain it again.
Lets say I have 3 ComboBoxes with items.
One ComboBox for DOY, one for GSAT and one for DURATION.
I want wo filter with 0 up to 3 filter.
If I select the DOY 025 I want to see only the entries from DOY 025, if I select additionally the GSAT XYZ I want to see the entries from DOY 025 with GSAT XYZ only. If I select additionally a DURATION of 30 I want to see the entries from DOY 025 with GSAT XYZ and a DURATION of 30 only.
question from:
https://stackoverflow.com/questions/65885617/if-condition-for-filter-in-java-8-stream 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…