This might look like a primitive question or a this could be done by a simple utility library method that I don't know about.
The goal is to check the value of a boolean field that is nested under two objects.
private boolean sourceWebsite(Registration registration) {
Application application = registration.getApplication();
if (application == null) {
return true;
}
Metadata metadata = application.getMetadata();
if (metadata == null) {
return true;
}
Boolean source = metadata.getSource();
if (source == null) {
return true;
}
return !source;
}
I know this could be done in a single if()
. I have added multiple if
s here for the sake of readability.
Is there a way that we could simplify the above if
statements and have a simple utility class that returns the value of Boolean source
if the parent objects or not null?