To update or to delete? That is the Query I'm currently developing a method which performs an update of some data; much like the following simplified logic:

boolean updateRequired = (currentValue == null &amp;&amp; newValue != null);
boolean deleteRequired = (currentValue != null &amp;&amp; newValue == null);

if(updateRequired || deleteRequired) {

    // ...

}


Which probably is fine enough by itself. However, I can't loose the feeling that I'm somehow re-inventing the wheel. The above is just simplified, current/new-Value are strings if that matters.

Is there any way to make this more neat?
Depending on your use case, I recommend two options. Both of them are based on a separate function for checking things....

At its simplest, have a function:

private static final boolean needToDoSomething(String currentValue, String newValue) {
    return currentValue == null &amp;&amp; newValue != null || currentValue != null &amp;&amp; newValue == null;
}


Then you can just have:

if (needToDoSomething(currentValue, newValue)) {
    ....
}


If you need to do something more special than just the 'needs modification' test, for example, you need to distinguish inside the if block between these conditions, then I would recommend an Enum with a static method, for example:

public enum EditState {
    ADDED, DELETED, MODIFIED, UNCHANGED;

    public static getState(String currentValue, String newValue) {
        if (currentValue == newValue) {
            // this covers null == null too
            return UNCHANGED;
        }
        if (currentValue != null &amp;&amp; newValue == null) {
            return DELETED;
        }
        if (newValue != null &amp;&amp; currentValue == null) {
            return ADDED;
        }
        return currentValue.equals(newValue) ? UNCHANGED : MODIFIED;
    }


    public boolean isStateChanging() {
        return this != UNCHANGED;
    }
}


Then, with this Enum class, you can be more specific:

EditState state = EditState.getState(currentValue, newValue);

switch (state) {
    case UNCHANGED :
        .....
    case DELETED :
        .....
    ....
}