net.sf.jga.fn.comparison
Class Between<T>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.UnaryFunctor<T,java.lang.Boolean>
          extended by net.sf.jga.fn.comparison.Between<T>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
Between.Comparable

public class Between<T>
extends UnaryFunctor<T,java.lang.Boolean>

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. The comparison is performed using a comparator or a pair of functors supplied at construction time: a default comparator will be used if the nested Comparable class' default constructor is used. The behaviour of this class in the presence of null arguments is left to the implementation of the specific Comparator, however it is generally safe to assume that using null arguments will cause a NullPointerException to be thrown.

Copyright © 2003-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static class Between.Comparable<T extends java.lang.Comparable<? super T>>
          Between functor for use with Comparable arguments.
static interface Between.Visitor
          Interface for classes that may interpret an Between predicate.
 
Constructor Summary
Between(T lo, T hi, java.util.Comparator<? super T> comp)
          Builds a Between predicate that returns TRUE when its argument is between its two arguments (inclusive).
Between(UnaryFunctor<T,java.lang.Boolean> lo, UnaryFunctor<T,java.lang.Boolean> hi)
          Builds a Between predicate that returns TRUE when both of the given predicates return TRUE for the same argument.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(Between) method, if it implements the nested Visitor interface.
 java.lang.Boolean fn(T x)
          Given argument x, returns TRUE if x is between lo and hi.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, bind0th, bindNth, compose, compose, compose, composeNth, composeNth, eval, generate, generateNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Between

public Between(T lo,
               T hi,
               java.util.Comparator<? super T> comp)
Builds a Between predicate that returns TRUE when its argument is between its two arguments (inclusive). The given comparator will be used to compare values.

Throws:
java.lang.IllegalArgumentException - when either argument is null or when lo > hi

Between

public Between(UnaryFunctor<T,java.lang.Boolean> lo,
               UnaryFunctor<T,java.lang.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

fn

public java.lang.Boolean fn(T x)
Given argument x, returns TRUE if x is between lo and hi.

Specified by:
fn in class UnaryFunctor<T,java.lang.Boolean>
Returns:
lo < x < hi

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<java.lang.Boolean>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2006 David A. Hall. All Rights Reserved.