I have the following Java class:
public class MyClass{
private List<Settings> settings;
public static class Settings {
private String name;
private List<Features> features;
}
public static class Features {
private String name;
private Boolean isActive;
}
}
What I want to do is first check that settings
is not null or empty. If not, then I want to find the Settings
object that has the name "reliability", and then find its Features
objects that have the names "logs" and "score" and get the isActive
from these two objects.
This is what I've tried:
MyClass myClass = new MyClass ();
Boolean logs = false;
Boolean score = false;
if (myClass.getSettings != null) {
for (Settings setting: myClass.getSettings) {
if (setting.getName().equals("reliability")) {
for (Features features : setting.getFeatures) {
if (features.getName().equals("logs")) {
logs = features.getIsActive;
} else if (features.getName().equals("score")) {
score = features.getIsActive;
}
}
}
}
}
How do I do this in a clean way? I can only do it with countless nested if and for loops, and it is not pretty.