net.sf.jga.fn.comparison

Class BetweenComp<T>

public class BetweenComp<T> extends AbstractUnaryPredicate<T> implements Serializable

Unary Predicate that returns TRUE when its argument is between two given values. By default, the range is inclusive: a constructor is provided that allows client code to supply two predicates that can create exclusive ranges. All comparisons will be performed using a Comparator given at construction.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceBetweenComp.Visitor
Interface for classes that may interpret an BetweenComp predicate.
Constructor Summary
BetweenComp(T lo, T hi, Comparator<T> comp)
Builds a BetweenComp predicate that returns TRUE when its argument is between its two arguments (inclusive).
BetweenComp(UnaryFunctor<T,Boolean> lo, UnaryFunctor<T,Boolean> hi)
Builds a Between predicate that returns TRUE when both of the given predicates return TRUE for the same argument.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(BetweenComp) method, if it implements the nested Visitor interface.
booleanp(T x)
Given argument x, returns TRUE if x is between lo and hi.
StringtoString()

Constructor Detail

BetweenComp

public BetweenComp(T lo, T hi, Comparator<T> comp)
Builds a BetweenComp predicate that returns TRUE when its argument is between its two arguments (inclusive).

Throws: IllegalArgumentException when either argument is null or when lo > hi

BetweenComp

public BetweenComp(UnaryFunctor<T,Boolean> lo, UnaryFunctor<T,Boolean> hi)
Builds a Between predicate that returns TRUE when both of the given predicates return TRUE for the same argument. This version of the constructor is provided to allow finer control over the comparisons performed.

Method Detail

accept

public void accept(Visitor v)
Calls the Visitor's visit(BetweenComp) method, if it implements the nested Visitor interface.

p

public boolean p(T x)
Given argument x, returns TRUE if x is between lo and hi.

Returns: lo < x < hi

toString

public String toString()