I'm having an issue where my code just feels messy and I need some help on how I could structure it better.
example:
if (object.getDescription() == Status.Expected && !logEvent.equals("Expected")) {
System.out.println("Do nothing"); // ???
} else {
status.setChangedBy(logEvent);
}
How can i format this if in a cleaner way? I want the changedBy
method to be called in every case except when getDescription == Status.Expected
and logEvent
is not "Expected"
. But I don't want an empty if statement either.
An alternative is:
if (object.getDescription() == Status.Expected) {
if (logEvent.equals("Expected")) {
status.setChangedBy(logEvent);
}
} else {
status.setChangedBy(logEvent);
}
Both examples work. But neither examples "feels right". Is there any other solution I'm not seeing?