public static <DATATYPE> int compare (@Nullable final DATATYPE aObj1,
                                        @Nullable final DATATYPE aObj2,
                                        @Nonnull final Comparator <? super DATATYPE> aComp,
                                        final boolean bNullValuesComeFirst)
  {
    if (EqualsHelper.identityEqual (aObj1, aObj2))
      return 0;
    if (aObj1 == null)
      return bNullValuesComeFirst ? -1 : +1;
    if (aObj2 == null)
      return bNullValuesComeFirst ? +1 : -1;
    return aComp.compare (aObj1, aObj2);
  }
public static < DATATYPE > int compare ( @ Nullable final DATATYPE aObj1 , @ Nullable final DATATYPE aObj2 , @ Nonnull final Comparator < ? super DATATYPE > aComp , final boolean bNullValuesComeFirst ) { if ( EqualsHelper . identityEqual ( aObj1 , aObj2 ) ) return 0 ; if ( aObj1 == null ) return bNullValuesComeFirst ? - 1 : + 1 ; if ( aObj2 == null ) return bNullValuesComeFirst ? + 1 : - 1 ; return aComp . compare ( aObj1 , aObj2 ) ; }
Compare the passed items and handle <code>null</code> values correctly. A
<code>null</code> value is always smaller than a non-<code>null</code>
value.

@param <DATATYPE>
Any object to be used. Both need to be of the same type.
@param aObj1
First object to compare. May be <code>null</code>.
@param aObj2
Second object to compare. May be <code>null</code>.
@param aComp
The comparator to be used if both parameters are not
<code>null</code>. The comparator itself may not be
<code>null</code>.
@param bNullValuesComeFirst
if <code>true</code> <code>null</code> values are ordered before
non-<code>null</code> values
@return 0 if they are equal (or both <code>null</code>), -1 or +1.