@Immutable public final class CompareHelper extends Object
null safe. Also provides secure ways to compare double and float
values.| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_NULL_VALUES_COME_FIRST
By default
null values come first |
| Modifier and Type | Method and Description |
|---|---|
static int |
compare(byte n1,
byte n2)
Special version for byte
|
static int |
compare(char n1,
char n2)
Special version for byte
|
static <DATATYPE extends Comparable<? super DATATYPE>> |
compare(DATATYPE aObj1,
DATATYPE aObj2)
Compare the passed items and handle
null values correctly. |
static <DATATYPE extends Comparable<? super DATATYPE>> |
compare(DATATYPE aObj1,
DATATYPE aObj2,
boolean bNullValuesComeFirst)
Compare the passed items and handle
null values correctly. |
static <DATATYPE> int |
compare(DATATYPE aObj1,
DATATYPE aObj2,
Comparator<? super DATATYPE> aComp)
Compare the passed items and handle
null values correctly. |
static <DATATYPE> int |
compare(DATATYPE aObj1,
DATATYPE aObj2,
Comparator<? super DATATYPE> aComp,
boolean bNullValuesComeFirst)
Compare the passed items and handle
null values correctly. |
static int |
compare(double d1,
double d2)
Special version for doubles
|
static int |
compare(float f1,
float f2)
Special version for floats
|
static int |
compare(int n1,
int n2)
Special version for int
|
static int |
compare(long n1,
long n2)
Special version for long
|
static int |
compare(short n1,
short n2)
Special version for short
|
static int |
compare(String sStr1,
String sStr2,
Collator aCollator) |
static int |
compare(String sStr1,
String sStr2,
Collator aCollator,
boolean bNullValuesComeFirst) |
static int |
compare(String sStr1,
String sStr2,
Locale aSortLocale) |
static int |
compare(String sStr1,
String sStr2,
Locale aSortLocale,
boolean bNullValuesComeFirst) |
static int |
compareFalseBeforeTrue(boolean b1,
boolean b2)
Special version for boolean,
true before false |
static int |
compareIgnoreCase(String sStr1,
String sStr2) |
static int |
compareIgnoreCase(String sStr1,
String sStr2,
boolean bNullValuesComeFirst) |
static int |
compareTrueBeforeFalse(boolean b1,
boolean b2)
Special version for boolean,
true before false |
public static final boolean DEFAULT_NULL_VALUES_COME_FIRST
null values come firstpublic static int compareTrueBeforeFalse(boolean b1,
boolean b2)
true before falseb1 - First valueb2 - Second valuepublic static int compareFalseBeforeTrue(boolean b1,
boolean b2)
true before falseb1 - First valueb2 - Second valuepublic static int compare(byte n1,
byte n2)
n1 - First valuen2 - Second valuepublic static int compare(char n1,
char n2)
n1 - First valuen2 - Second valuepublic static int compare(double d1,
double d2)
d1 - First valued2 - Second valuepublic static int compare(float f1,
float f2)
f1 - First valuef2 - Second valuepublic static int compare(int n1,
int n2)
n1 - First valuen2 - Second valuepublic static int compare(long n1,
long n2)
n1 - First valuen2 - Second valuepublic static int compare(short n1,
short n2)
n1 - First valuen2 - Second valuepublic static <DATATYPE extends Comparable<? super DATATYPE>> int compare(@Nullable DATATYPE aObj1, @Nullable DATATYPE aObj2)
null values correctly. A
null value is always smaller than a non-null
value.DATATYPE - Any comparable object to be used. Both need to be of the same type.aObj1 - First object to compare. May be null.aObj2 - Second object to compare. May be null.null), -1 or +1.public static <DATATYPE extends Comparable<? super DATATYPE>> int compare(@Nullable DATATYPE aObj1, @Nullable DATATYPE aObj2, boolean bNullValuesComeFirst)
null values correctly. A
null value is always smaller than a non-null
value.DATATYPE - Any comparable object to be used. Both need to be of the same type.aObj1 - First object to compare. May be null.aObj2 - Second object to compare. May be null.bNullValuesComeFirst - if true null values are ordered before
non-null valuesnull), -1 or +1.public static <DATATYPE> int compare(@Nullable DATATYPE aObj1, @Nullable DATATYPE aObj2, @Nonnull Comparator<? super DATATYPE> aComp)
null values correctly. A
null value is always smaller than a non-null
value.DATATYPE - Any object to be used. Both need to be of the same type.aObj1 - First object to compare. May be null.aObj2 - Second object to compare. May be null.aComp - The comparator to be used if both parameters are not
null. The comparator itself may not be
null.null), -1 or +1.public static <DATATYPE> int compare(@Nullable DATATYPE aObj1, @Nullable DATATYPE aObj2, @Nonnull Comparator<? super DATATYPE> aComp, boolean bNullValuesComeFirst)
null values correctly. A
null value is always smaller than a non-null
value.DATATYPE - Any object to be used. Both need to be of the same type.aObj1 - First object to compare. May be null.aObj2 - Second object to compare. May be null.aComp - The comparator to be used if both parameters are not
null. The comparator itself may not be
null.bNullValuesComeFirst - if true null values are ordered before
non-null valuesnull), -1 or +1.public static int compare(@Nullable String sStr1, @Nullable String sStr2, @Nonnull Locale aSortLocale)
public static int compare(@Nullable String sStr1, @Nullable String sStr2, @Nonnull Locale aSortLocale, boolean bNullValuesComeFirst)
public static int compare(@Nullable String sStr1, @Nullable String sStr2, @Nonnull Collator aCollator)
public static int compare(@Nullable String sStr1, @Nullable String sStr2, @Nonnull Collator aCollator, boolean bNullValuesComeFirst)
public static int compareIgnoreCase(@Nullable String sStr1, @Nullable String sStr2)
Copyright © 2014–2015 Philip Helger. All rights reserved.