public class CU extends Object
Comparable.
The name of this class is an abbreviation of Comparable Utilities. We have intentionally used a short name for readability because this class is intended to be used in comparison statements so that you can write something like
if( CU.lt(a,b) ) // Do something...instead of
if( a.compareTo(b) < 0 ) // Do something...If you are dealing with existing
comparable
classes like String or Integer
this class will facilitate the writing of comparison statements.
If you are writing a new comparable class we
suggest to implement Comparative instead.
This will allow you to implement Comparable
and to have the convenience methods provided by this
class directly on your comparable object.
Comparative| Modifier and Type | Method and Description |
|---|---|
static <C extends Comparable<C>> |
eq(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if a == b. |
static <C extends Comparable<C>> |
eq(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if a == b. |
static <C extends Comparable<C>> |
ge(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if a >= b. |
static <C extends Comparable<C>> |
ge(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if a >= b. |
static <C extends Comparable<C>> |
gt(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if a > b. |
static <C extends Comparable<C>> |
gt(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if a > b. |
static <C extends Comparable<C>> |
le(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if a <= b. |
static <C extends Comparable<C>> |
le(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if a <= b. |
static <C extends Comparable<C>> |
lt(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if a < b. |
static <C extends Comparable<C>> |
lt(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if a < b. |
static <C extends Comparable<C>> |
max(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, returns the maximum value between them. |
static <C extends Comparable<C>> |
max(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, returns the maximum value between them. |
static <C extends Comparable<C>> |
min(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, returns the minimum value between them. |
static <C extends Comparable<C>> |
min(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, returns the minimum value between them. |
static <C extends Comparable<C>> |
ne(C a,
C b)
This is a
null-safe method that, given two comparable
values a and b, tells if {@code a ! |
static <C extends Comparable<C>> |
ne(C a,
C b,
boolean nullLast)
This is a
null-safe method that, given two comparable
values a and b, tells if {@code a ! |
static <T> Comparator<T> |
nullFirstNaturalOrderComparator()
Returns a
null-safe natural ordered comparator
considering null to be less than non-null. |
static <T> Comparator<T> |
nullLastNaturalOrderComparator()
Returns a
null-safe natural ordered comparator
considering null to be greater than non-null. |
static <T> Comparator<T> |
nullSafeNaturalOrderComparator(boolean nullLast)
Returns a
null-safe natural ordered comparator
considering null to be less than or greater than
non-null based on the value of the parameter. |
public static <T> Comparator<T> nullFirstNaturalOrderComparator()
null-safe natural ordered comparator
considering null to be less than non-null.T - type of object to compare.null-safe natural ordered comparator.public static <T> Comparator<T> nullLastNaturalOrderComparator()
null-safe natural ordered comparator
considering null to be greater than non-null.T - type of object to compare.null-safe natural ordered comparator.public static <T> Comparator<T> nullSafeNaturalOrderComparator(boolean nullLast)
null-safe natural ordered comparator
considering null to be less than or greater than
non-null based on the value of the parameter.T - type of object to compare.nullLast - tells to consider null to be greater than non-null.null-safe natural ordered comparator.public static <C extends Comparable<C>> boolean lt(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a < b.
This method considers null to be less than non-null.
This method is the same as CU.lt(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a < b.public static <C extends Comparable<C>> boolean lt(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a < b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a < b.public static <C extends Comparable<C>> boolean le(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a <= b.
This method considers null to be less than non-null.
This method is the same as CU.le(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a <= b.public static <C extends Comparable<C>> boolean le(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a <= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a <= b.public static <C extends Comparable<C>> boolean eq(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a == b.
This method considers null to be less than non-null.
This method is the same as CU.eq(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a == b.public static <C extends Comparable<C>> boolean eq(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a == b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a == b.public static <C extends Comparable<C>> boolean ne(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a != b.
This method considers null to be less than non-null.
This method is the same as CU.ne(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a != b.public static <C extends Comparable<C>> boolean ne(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a != b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a != b.public static <C extends Comparable<C>> boolean ge(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a >= b.
This method considers null to be less than non-null.
This method is the same as CU.ge(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a >= b.public static <C extends Comparable<C>> boolean ge(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a >= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a >= b.public static <C extends Comparable<C>> boolean gt(C a, C b)
null-safe method that, given two comparable
values a and b, tells if a > b.
This method considers null to be less than non-null.
This method is the same as CU.gt(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.true if a > b.public static <C extends Comparable<C>> boolean gt(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, tells if a > b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.true if a > b.public static <C extends Comparable<C>> C min(C a, C b)
null-safe method that, given two comparable
values a and b, returns the minimum value between them.
If the values are equal returns a.
This method considers null to be less than non-null.
This method is the same as CU.min(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.a and b.public static <C extends Comparable<C>> C min(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, returns the minimum value between them.
If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.public static <C extends Comparable<C>> C max(C a, C b)
null-safe method that, given two comparable
values a and b, returns the maximum value between them.
If the values are equal returns a.
This method considers null to be less than non-null.
This method is the same as CU.max(a,b,false).
C - type of the comparable values.a - value to compare.b - value to compare.a and b.public static <C extends Comparable<C>> C max(C a, C b, boolean nullLast)
null-safe method that, given two comparable
values a and b, returns the maximum value between them.
If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
C - type of the comparable values.a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.Copyright © 2011–2020 Nerd4j. All rights reserved.