net.sf.jga.fn.property
Class CompareProperty<T,V>

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.property.CompareProperty<T,V>
All Implemented Interfaces:
java.io.Serializable, Visitable

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

Unary Predicate that compares the value of the named property to the given value. The type of comparison is a binary predicate: the two arguments passed to the predicate are the value of the argument's property in the first position and the constant value passed at construction in the second position.

The test returns bp(getProperty(name).fn(arg), value). This is also equivalent to the following:

 UnaryPredicate CompareProperty =
     new UnaryCompose(new Binder2nd(bp, value),
                      new GetProperty(propName))
 
with one less call to fn at evaluation and somewhat clearer construction syntax.

To Serialize a CompareProperty, the generic parameter V must be serializable.

Copyright © 2003-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface CompareProperty.Visitor
          Interface for classes that may interpret a CompareProperty predicate.
 
Constructor Summary
CompareProperty(java.lang.Class<T> argType, java.lang.String propName, BinaryFunctor<V,V,java.lang.Boolean> pred, V val)
          Builds the CompareProperty predicate that will compare the named property of an instance of type argType to the given value.
CompareProperty(java.lang.Class<T> argType, java.lang.String propName, V val)
          Builds the CompareProperty predicate that will compare the named property of an instance of type argType to the given value using an EqualTo predicate.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(CompareProperty) method, if it implements the nested Visitor interface.
 java.lang.Boolean fn(T arg)
          Tests the designated property of the argument against the value given at construction.
 BinaryFunctor<V,V,java.lang.Boolean> getPredicate()
          Returns the predicate used to compare property values
 java.lang.String getPropName()
          Returns the name of the property to be compared
 V getValue()
          Returns the constant value to which properties are compared
 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

CompareProperty

public CompareProperty(java.lang.Class<T> argType,
                       java.lang.String propName,
                       V val)
Builds the CompareProperty predicate that will compare the named property of an instance of type argType to the given value using an EqualTo predicate.


CompareProperty

public CompareProperty(java.lang.Class<T> argType,
                       java.lang.String propName,
                       BinaryFunctor<V,V,java.lang.Boolean> pred,
                       V val)
Builds the CompareProperty predicate that will compare the named property of an instance of type argType to the given value. The comparison can be any type of BinaryFunctor where both arguments are of the same type.

Method Detail

getPropName

public java.lang.String getPropName()
Returns the name of the property to be compared

Returns:
the name of the property to be compared

getValue

public V getValue()
Returns the constant value to which properties are compared

Returns:
the constant value to which properties are compared

getPredicate

public BinaryFunctor<V,V,java.lang.Boolean> getPredicate()
Returns the predicate used to compare property values

Returns:
the predicate used to compare property values.

fn

public java.lang.Boolean fn(T arg)
Tests the designated property of the argument against the value given at construction.

Specified by:
fn in class UnaryFunctor<T,java.lang.Boolean>
Returns:
the boolean value of the comparison

accept

public void accept(Visitor v)
Calls the Visitor's visit(CompareProperty) 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.