On this page

ComparableUtils

public class org.apache.commons.lang3.compare.ComparableUtils[source]

Helper translating Comparable.compareTo(T) results to booleans.

Example: boolean x = ComparableUtils.is(myComparable).lessThanOrEqualTo(otherComparable)

#ThreadSafe#

Since:

3.10

Methods

static <A extends Comparable<A>> Predicate<A>

between(A b, A c)

Creates a predicate to test if [b <= a <= c] or [b >= a >= c] where the a is the tested object.

static <A extends Comparable<A>> Predicate<A>

betweenExclusive(A b, A c)

Creates a predicate to test if (b < a < c) or (b > a > c) where the a is the tested object.

static <A extends Comparable<A>> Predicate<A>

ge(A b)

Creates a predicate to test if the tested object is greater than or equal to b

static <A extends Comparable<A>> Predicate<A>

gt(A b)

Creates a predicate to test if the tested object is greater than b

static <A extends Comparable<A>> ComparableUtils.ComparableCheckBuilder<A>

is(A a)

Creates a new ComparableUtils.ComparableCheckBuilder.

static <A extends Comparable<A>> Predicate<A>

le(A b)

Creates a predicate to test if the tested object is less than or equal to b

static <A extends Comparable<A>> Predicate<A>

lt(A b)

Creates a predicate to test if the tested object is less than b

static <A extends Comparable<A>> A

max(A comparable1, A comparable2)

Returns the greater of two Comparable values, ignoring null.

static <A extends Comparable<A>> A

min(A comparable1, A comparable2)

Returns the lesser of two Comparable values, ignoring null.

public static <A extends Comparable<A>> Predicate<A> between(A b, A c)[source]

Creates a predicate to test if [b <= a <= c] or [b >= a >= c] where the a is the tested object.

Type parameters:

<A> – type of the test object

Parameters:
  • b – The object to compare to the tested object

  • c – The object to compare to the tested object

Returns:

A predicate for true if the tested object is between b and c

public static <A extends Comparable<A>> Predicate<A> betweenExclusive(A b, A c)[source]

Creates a predicate to test if (b < a < c) or (b > a > c) where the a is the tested object.

Type parameters:

<A> – type of the test object

Parameters:
  • b – The object to compare to the tested object

  • c – The object to compare to the tested object

Returns:

A predicate for true if the tested object is between b and c and not equal to those

public static <A extends Comparable<A>> Predicate<A> ge(A b)[source]

Creates a predicate to test if the tested object is greater than or equal to b

Type parameters:

<A> – type of the test object

Parameters:

b – The object to compare to the tested object

Returns:

A predicate for true if the value returned by Comparable.compareTo(T) is greater than or equal to 0

public static <A extends Comparable<A>> Predicate<A> gt(A b)[source]

Creates a predicate to test if the tested object is greater than b

Type parameters:

<A> – type of the test object

Parameters:

b – The object to compare to the tested object

Returns:

A predicate for true if the value returned by Comparable.compareTo(T) is greater than 0

public static <A extends Comparable<A>> ComparableUtils.ComparableCheckBuilder<A> is(A a)[source]

Creates a new ComparableUtils.ComparableCheckBuilder.

Type parameters:

<A> – type of the base object

Parameters:

a – base object in the further comparison

Returns:

A builder object with further methods

public static <A extends Comparable<A>> Predicate<A> le(A b)[source]

Creates a predicate to test if the tested object is less than or equal to b

Type parameters:

<A> – type of the test object

Parameters:

b – The object to compare to the tested object

Returns:

A predicate for true if the value returned by Comparable.compareTo(T) is less than or equal to 0

public static <A extends Comparable<A>> Predicate<A> lt(A b)[source]

Creates a predicate to test if the tested object is less than b

Type parameters:

<A> – type of the test object

Parameters:

b – The object to compare to the tested object

Returns:

A predicate for true if the value returned by Comparable.compareTo(T) is less than 0

public static <A extends Comparable<A>> A max(A comparable1, A comparable2)[source]

Returns the greater of two Comparable values, ignoring null.

For three or more values, use ObjectUtils.max(Comparable...).

Type parameters:

<A> – Type of what we are comparing.

Parameters:
  • comparable1 – The first comparable, may be null.

  • comparable2 – The second comparable, may be null.

Returns:

The largest of comparable1 and comparable2.

Since:

3.13.0

See also:

ObjectUtils.max(Comparable...)

public static <A extends Comparable<A>> A min(A comparable1, A comparable2)[source]

Returns the lesser of two Comparable values, ignoring null.

For three or more values, use ObjectUtils.min(Comparable...).

Type parameters:

<A> – Type of what we are comparing.

Parameters:
  • comparable1 – The first comparable, may be null.

  • comparable2 – The second comparable, may be null.

Returns:

The smallest of comparable1 and comparable2.

Since:

3.13.0

See also:

ObjectUtils.min(Comparable...)