jaggregate
Class Comparables

java.lang.Object
  extended by jaggregate.Comparables

public class Comparables
extends Object

Utility class that offers useful operations on Comparables.

Version:
$Id: Comparables.java,v 1.7 2008/08/09 04:35:29 pholser Exp $
Author:
Paul Holser

Method Summary
static
<E extends Comparable<? super E>>
UnaryPredicate<E>
between(E minimum, E maximum)
          Answers a predicate which will answer true if its argument compares "between" the given minimum and maximum, inclusive.
static
<E extends Comparable<? super E>>
UnaryPredicate<E>
greaterThan(E comparand)
          Answers a predicate which will answer true if its argument compares "greater than" the given comparand.
static
<E extends Comparable<? super E>>
UnaryPredicate<E>
greaterThanOrEqualTo(E comparand)
          Answers a predicate which will answer true if its argument compares "greater than" or "equal to" the given comparand.
static
<E extends Comparable<? super E>>
UnaryPredicate<E>
lessThan(E comparand)
          Answers a predicate which will answer true if its argument compares "less than" the given comparand.
static
<E extends Comparable<? super E>>
UnaryPredicate<E>
lessThanOrEqualTo(E comparand)
          Answers a predicate which will answer true if its argument compares "less than" or "equal to" the given comparand.
static
<E extends Comparable<? super E>>
BinaryFunction<E,E,E>
max()
          Answers a function which will give the greater of its two arguments.
static
<E extends Comparable<? super E>>
BinaryFunction<E,E,E>
min()
          Answers a function which will give the lesser of its two arguments.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

lessThan

public static <E extends Comparable<? super E>> UnaryPredicate<E> lessThan(E comparand)
Answers a predicate which will answer true if its argument compares "less than" the given comparand.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the type of the comparand
Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

lessThanOrEqualTo

public static <E extends Comparable<? super E>> UnaryPredicate<E> lessThanOrEqualTo(E comparand)
Answers a predicate which will answer true if its argument compares "less than" or "equal to" the given comparand.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the type of the comparand
Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

greaterThan

public static <E extends Comparable<? super E>> UnaryPredicate<E> greaterThan(E comparand)
Answers a predicate which will answer true if its argument compares "greater than" the given comparand.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the type of the comparand
Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

greaterThanOrEqualTo

public static <E extends Comparable<? super E>> UnaryPredicate<E> greaterThanOrEqualTo(E comparand)
Answers a predicate which will answer true if its argument compares "greater than" or "equal to" the given comparand.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the type of the comparand
Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

between

public static <E extends Comparable<? super E>> UnaryPredicate<E> between(E minimum,
                                                                          E maximum)
Answers a predicate which will answer true if its argument compares "between" the given minimum and maximum, inclusive.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the type of the bounds
Parameters:
minimum - the lower bound
maximum - the upper bound
Returns:
a predicate that can be used to compare arguments with minimum and maximum

max

public static <E extends Comparable<? super E>> BinaryFunction<E,E,E> max()
Answers a function which will give the greater of its two arguments.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the types of the function's arguments
Returns:
function which will give the greater of its two arguments

min

public static <E extends Comparable<? super E>> BinaryFunction<E,E,E> min()
Answers a function which will give the lesser of its two arguments.

For purposes of this comparison, null always compares "less than" non-null.

Type Parameters:
E - a constraint on the types of the function's arguments
Returns:
function which will give the lesser of its two arguments


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu