I have an object with a List of other objects, each other object has a List etc. I need to find in the hierarchy the first (and unique) last element in the hierarchy that has a property matching some value. Seeing my present code will be clearer :
@Override
public Poste findByNumeroAndMillesime(String numero, Millesime millesime) {
return millesime
.getDivisions()
.stream()
.filter(
division -> division
.getGroupes()
.stream()
.filter(
groupe -> groupe
.getClasses()
.stream()
.filter(
classe -> classe
.getSousClasses()
.stream()
.filter(
sousClasse -> sousClasse
.getPostes()
.stream()
.filter(poste -> numero.equals(poste.getNumero()))
.findFirst()
.get()
))));
}
I need to return the Poste having the same numero as that passed as a parameter.
Thanks in advance.