How can you check a collection to see if any of a particular field are set to a value.
- I have a composite entity with a boolean field.
- I need to check if any value has been set to true
- If so, there is another boolean field on the owning entity that also must be set to true.
I have a collection datasource listener set up to trigger a function:
employersDs.addCollectionChangeListener(event -> statusSetter());`
...
private void statusSetter() {
//check if any employer hired referral
Boolean wasHired = employersDs.getItems().stream().anyMatch(employersDs.getItem().getHired() == true);
//if yes, set jobSeekerHired to Yes
if (wasHired) {
getItem().setJobSeekerHired(YesNoOTher.Yes);
}
}
I just can’t get my hands around the syntax to achieve this. Any help would be appreciated.