Search code examples
javajava-8spring-webfluxjava-9

Cannot convert from Stream<T> to boolean


I'm trying to filter a list of objects say BOLReference based on a key which is present in the inner object of one of the List of Objects of this BOLReference.

List<BOLReference> bolRef = complianceMongoTemplate.find(findQuery, BOLReference.class);

Optional<BOLReference> bref = bolRef.stream().filter(br -> br.getWorkflowExceptions().stream()
                        .filter(bk -> bk.getBusinessKeyValues().get(businessKey)
                        .equalsIgnoreCase("ABCD1234"))).findFirst();

While doing so I'm getting error as :

Cannot convert from Stream<WorkFlowExceptions> to boolean

My BOLReference looks like below:

private String ediTransmissionId;
private List<WorkflowExceptions> workflowExceptions;

And my WorkflowExceptions looks like:

private String category;
private Map<String,String> businessKeyValues;

Solution

  • Optional<BOLReference> bref = bolRef.stream()
        .filter(br -> 
            br.getWorkflowExceptions().stream()
                .anyMatch(bk ->
                    bk.getBusinessKeyValues().get(businessKey)
                        .equalsIgnoreCase("ABCD1234")))
        .findFirst();
    

    Failing anyMatch I think.