On this page

ComparableUtils

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

Helper translating Comparable#compareTo results to booleans.

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

#ThreadSafe#

Since:

3.10

Methods

between(Comparable, Comparable)

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

betweenExclusive(Comparable, Comparable)

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

ge(Comparable)

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

gt(Comparable)

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

is(Comparable)

Creates a new ComparableCheckBuilder.

le(Comparable)

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

lt(Comparable)

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

max(Comparable, Comparable)

Returns the greater of two Comparable values, ignoring null.

min(Comparable, Comparable)

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.

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

  • c – The object to compare to the tested object

Type parameters:

<A> – type of the test 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.

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

  • c – The object to compare to the tested object

Type parameters:

<A> – type of the test 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

Parameters:

b – The object to compare to the tested object

Type parameters:

<A> – type of the test object

Returns:

A predicate for true if the value returned by Comparable#compareTo 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

Parameters:

b – The object to compare to the tested object

Type parameters:

<A> – type of the test object

Returns:

A predicate for true if the value returned by Comparable#compareTo is greater than 0

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

Creates a new ComparableCheckBuilder.

Parameters:

a – base object in the further comparison

Type parameters:

<A> – type of the base object

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

Parameters:

b – The object to compare to the tested object

Type parameters:

<A> – type of the test object

Returns:

A predicate for true if the value returned by Comparable#compareTo 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

Parameters:

b – The object to compare to the tested object

Type parameters:

<A> – type of the test object

Returns:

A predicate for true if the value returned by Comparable#compareTo 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.

See also:

ObjectUtils#max(Comparable...)

Since:

3.13.0

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.

See also:

ObjectUtils#min(Comparable...)

Since:

3.13.0