Top Description Inners Constructors Methods
org.apache.commons.lang3.compare

public Class ComparableUtils

extends Object
Class Inheritance
Imports
java.util.function.Predicate, org.apache.commons.lang3.ObjectUtils

Helper translating Comparable#compareTo results to booleans.

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

#ThreadSafe#

Since
3.10

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ComparableUtils.ComparableCheckBuilder<
the type of objects that this object may be compared against.
A extends Comparable<A>
>

Compares objects of a given generic type A.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the tested object is between b and c
between
(final A
the object to compare to the tested object
b
,
final A
the object to compare to the tested object
c
)

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

public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the tested object is between b and c and not equal to those
betweenExclusive
(final A
the object to compare to the tested object
b
,
final A
the object to compare to the tested object
c
)

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

public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the value returned by Comparable#compareTo is greater than or equal to 0
ge
(final A
the object to compare to the tested object
b
)

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

public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the value returned by Comparable#compareTo is greater than 0
gt
(final A
the object to compare to the tested object
b
)

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

public static <
type of the base object
A extends Comparable<A>
>
ComparableUtils.ComparableCheckBuilder<A>

Returns:

a builder object with further methods
is
(final A
base object in the further comparison
a
)

Creates a new ComparableCheckBuilder.

public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the value returned by Comparable#compareTo is less than or equal to 0
le
(final A
the object to compare to the tested object
b
)

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

public static <
type of the test object
A extends Comparable<A>
>
Predicate<A>

Returns:

a predicate for true if the value returned by Comparable#compareTo is less than 0
lt
(final A
the object to compare to the tested object
b
)

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

public static <
Type of what we are comparing.
A extends Comparable<A>
>
A

Returns:

the largest of comparable1 and comparable2.
max
(final A
the first comparable, may be null.
comparable1
,
final A
the second comparable, may be null.
comparable2
)

Returns the greater of two Comparable values, ignoring null.

public static <
Type of what we are comparing.
A extends Comparable<A>
>
A

Returns:

the smallest of comparable1 and comparable2.
min
(final A
the first comparable, may be null.
comparable1
,
final A
the second comparable, may be null.
comparable2
)

Returns the lesser of two Comparable values, ignoring null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ComparableUtilsback to summary
private ComparableUtils()

Method Detail

betweenback to summary
public static <A extends Comparable<A>> Predicate<A> between(final A b, final A c)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

c:A

the object to compare to the tested object

Returns:Predicate<A>

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

betweenExclusiveback to summary
public static <A extends Comparable<A>> Predicate<A> betweenExclusive(final A b, final A c)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

c:A

the object to compare to the tested object

Returns:Predicate<A>

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

geback to summary
public static <A extends Comparable<A>> Predicate<A> ge(final A b)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

Returns:Predicate<A>

a predicate for true if the value returned by Comparable#compareTo is greater than or equal to 0

gtback to summary
public static <A extends Comparable<A>> Predicate<A> gt(final A b)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

Returns:Predicate<A>

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

isback to summary
public static <A extends Comparable<A>> ComparableUtils.ComparableCheckBuilder<A> is(final A a)

Creates a new ComparableCheckBuilder.

Parameters
<A>
type of the base object
a:A

base object in the further comparison

Returns:ComparableUtils.ComparableCheckBuilder<A>

a builder object with further methods

leback to summary
public static <A extends Comparable<A>> Predicate<A> le(final A b)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

Returns:Predicate<A>

a predicate for true if the value returned by Comparable#compareTo is less than or equal to 0

ltback to summary
public static <A extends Comparable<A>> Predicate<A> lt(final A b)

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

Parameters
<A>
type of the test object
b:A

the object to compare to the tested object

Returns:Predicate<A>

a predicate for true if the value returned by Comparable#compareTo is less than 0

maxback to summary
public static <A extends Comparable<A>> A max(final A comparable1, final A comparable2)

Returns the greater of two Comparable values, ignoring null.

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

Parameters
<A>
Type of what we are comparing.
comparable1:A

the first comparable, may be null.

comparable2:A

the second comparable, may be null.

Returns:A

the largest of comparable1 and comparable2.

Since
3.13.0
See Also
ObjectUtils#max(Comparable...)
minback to summary
public static <A extends Comparable<A>> A min(final A comparable1, final A comparable2)

Returns the lesser of two Comparable values, ignoring null.

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

Parameters
<A>
Type of what we are comparing.
comparable1:A

the first comparable, may be null.

comparable2:A

the second comparable, may be null.

Returns:A

the smallest of comparable1 and comparable2.

Since
3.13.0
See Also
ObjectUtils#min(Comparable...)
org.apache.commons.lang3.compare back to summary

public Class ComparableUtils.ComparableCheckBuilder<A extends Comparable<A>>

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.lang3.compare.ComparableUtils.ComparableCheckBuilder
Type Parameters
<A>
the type of objects that this object may be compared against.

Compares objects of a given generic type A.

Field Summary

Modifier and TypeField and Description
private final A
a

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the base object is between b and c
between
(final A
the object to compare to the base object
b
,
final A
the object to compare to the base object
c
)

Tests if [b <= a <= c] or [b >= a >= c] where the a is object passed to is.

public boolean

Returns:

true if the base object is between b and c and not equal to those
betweenExclusive
(final A
the object to compare to the base object
b
,
final A
the object to compare to the base object
c
)

Tests if (b < a < c) or (b > a > c) where the a is object passed to is.

private boolean
betweenOrdered(final A b, final A c)

private boolean
betweenOrderedExclusive(final A b, final A c)

public boolean

Returns:

true if the value returned by Comparable#compareTo is equal to 0
equalTo
(final A
the object to compare to the base object
b
)

Tests if the object passed to is is equal to b

public boolean

Returns:

true if the value returned by Comparable#compareTo is greater than 0
greaterThan
(final A
the object to compare to the base object
b
)

Tests if the object passed to is is greater than b

public boolean

Returns:

true if the value returned by Comparable#compareTo is greater than or equal to 0
greaterThanOrEqualTo
(final A
the object to compare to the base object
b
)

Tests if the object passed to is is greater than or equal to b

public boolean

Returns:

true if the value returned by Comparable#compareTo is less than 0
lessThan
(final A
the object to compare to the base object
b
)

Tests if the object passed to is is less than b

public boolean

Returns:

true if the value returned by Comparable#compareTo is less than or equal to 0
lessThanOrEqualTo
(final A
the object to compare to the base object
b
)

Tests if the object passed to is is less than or equal to b

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final A a

Constructor Detail

ComparableCheckBuilderback to summary
private ComparableCheckBuilder(final A a)

Method Detail

betweenback to summary
public boolean between(final A b, final A c)

Tests if [b <= a <= c] or [b >= a >= c] where the a is object passed to is.

Parameters
b:A

the object to compare to the base object

c:A

the object to compare to the base object

Returns:boolean

true if the base object is between b and c

betweenExclusiveback to summary
public boolean betweenExclusive(final A b, final A c)

Tests if (b < a < c) or (b > a > c) where the a is object passed to is.

Parameters
b:A

the object to compare to the base object

c:A

the object to compare to the base object

Returns:boolean

true if the base object is between b and c and not equal to those

betweenOrderedback to summary
private boolean betweenOrdered(final A b, final A c)
betweenOrderedExclusiveback to summary
private boolean betweenOrderedExclusive(final A b, final A c)
equalToback to summary
public boolean equalTo(final A b)

Tests if the object passed to is is equal to b

Parameters
b:A

the object to compare to the base object

Returns:boolean

true if the value returned by Comparable#compareTo is equal to 0

greaterThanback to summary
public boolean greaterThan(final A b)

Tests if the object passed to is is greater than b

Parameters
b:A

the object to compare to the base object

Returns:boolean

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

greaterThanOrEqualToback to summary
public boolean greaterThanOrEqualTo(final A b)

Tests if the object passed to is is greater than or equal to b

Parameters
b:A

the object to compare to the base object

Returns:boolean

true if the value returned by Comparable#compareTo is greater than or equal to 0

lessThanback to summary
public boolean lessThan(final A b)

Tests if the object passed to is is less than b

Parameters
b:A

the object to compare to the base object

Returns:boolean

true if the value returned by Comparable#compareTo is less than 0

lessThanOrEqualToback to summary
public boolean lessThanOrEqualTo(final A b)

Tests if the object passed to is is less than or equal to b

Parameters
b:A

the object to compare to the base object

Returns:boolean

true if the value returned by Comparable#compareTo is less than or equal to 0