net.sf.jga.fn.comparison

Class Between<T>

public class Between<T extends Comparable> 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.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceBetween.Visitor
Interface for classes that may interpret an Between predicate.
Constructor Summary
Between(T lo, T hi)
Builds a Between predicate that returns TRUE when its argument is between its two arguments (inclusive).
Between(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(Between) 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

Between

public Between(T lo, T hi)
Builds a Between predicate that returns TRUE when its argument is between its two arguments (inclusive).

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

Between

public Between(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(Between) 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()