I have these classes
class LivingOrganism
{
List<Domain> listOfDomain;
}
class Domain
{
List<Species> listOfSpecies;
}
class Species
{
List<Color> listOfColor;
}
class Color
{
String color;
}
From the top to bottom, it won't have any duplicated entries until I reach to color. So some species even if they are in another domain can have the same color. And one single species can have different color.
Given a parent LivingOrganism, I want to filter a listOfDomain with a certain color.
I did it in a classic nested for loop, but with 4 nest for, the code doesn't look pretty. I was trying to use java 8 flatmap and filter to get some more elegant code, but I spent hours without success.
I even made a badly drawn graph in MSPaint
Let's say I want to get List<Species>
that can be blue or List<Domain>
with all the Species
that can be blue. How do I proceed?
Any help would be appreciated