Java 8 corriente - cómo encontrar entidad matriz del niño?

gtludwig:

Tengo un escenario similar a:

public class A {
    private String id;
    @ManyToMany
    private Set<B> bSet;
    // getters and setters
}

y

public class B {
    private String id;
    // other attributes
    // getters and setters
}

¿Cómo puedo encontrar un ejemplo de Acuando tengo un caso de Buso de la stream()API? Estaba tratando algo como:

public A findAFromB(B b) {
    List<A> aList = aService.findAll();
    Optional<A> matchingObject = aList.stream().filter({find a where a.getBSet().contains(b)}).getA();
return (A) matchingObject.get();
}

Cómo escribir correctamente este filtro?

también:

Soemthing como usar una findFirsto findAnycomo una operación de terminal:

Optional<A> matchingObject = aList.stream()
        .filter(a -> a.getbSet().contains(b))
        .findFirst();

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=225629&siteId=1
Recomendado
Clasificación