public static <T> boolean areEqual(T value1, T value2, Comparator<T> comparator) {
        return ((value1 == null) && (value2 == null)) || //
                ((value1 != null) && (value2 != null) && (comparator.compare(value1, value2) == 0));
    }
public static < T > boolean areEqual ( T value1 , T value2 , Comparator < T > comparator ) { return ( ( value1 == null ) && ( value2 == null ) ) || ( ( value1 != null ) && ( value2 != null ) && ( comparator . compare ( value1 , value2 ) == 0 ) ) ; }
Compares the two given values by taking null values into account and the specified comparator.

@param value1     First value.
@param value2     Second value.
@param comparator Comparator to be used to compare the two values in case they are both non null.
@param <T>        Type of values to be compared.

@return True if both values are null, or equal according to the comparator.