I have a bunch of entries like these two:
if (update) {
if (activity.getName() == null) {
logger.debug(" Setting name on " + id);
} else
if (!activity.getName().equals(name)) {
logger.debug(" Updating name on " + id);
}
}
// if (!update) not logged on purpose
activity.setName(name);
if (update) {
if (activity.getPlannedDuration() == null) {
logger.debug(" Setting plannedDuration on " + id);
} else
if (!activity.getPlannedDuration().equals(duration)) {
logger.debug(" Updating plannedDuration on " + id);
}
}
// if (!update) not logged on purpose
activity.setPlannedDuration(duration);
and for code readability purposes I'd like to replace them with something like this:
updateField(update, name, "name", activity.getName, activity.setName);
updateField(update, duration, "plannedDuration", activity.getPlannedDuration, activity.setPlannedDuration);
I'm aware this is a common question, I did my homework, and wraping methods to Callable interface seems to be the simplest solution. But, that solution would be even more of a mess than my current code (remember, I'm doing this for the readability).
So, is there an elegant solution for my problem in Java?