net.sf.jga.fn.property

Class CompareProperty<T,V>

public class CompareProperty<T,V> extends AbstractUnaryPredicate<T> implements Serializable

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 simpleCompare =
     new UnaryCompose(new Binder2nd(bp, value),
                      new GetProperty(propName))
 
with one less call to fn at evaluation and somewhat clearer construction syntax.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceCompareProperty.Visitor
Interface for classes that may interpret a CompareProperty predicate.
Constructor Summary
CompareProperty(String propName, V val)
Builds the CompareProperty predicate that will compare the named property to the given value using an EqualTo predicate.
CompareProperty(String propName, BinaryFunctor<V,V,Boolean> pred, V val)
Builds the CompareProperty predicate that will compare the named property to the given value.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(CompareProperty) method, if it implements the nested Visitor interface.
BinaryFunctor<V,V,Boolean>getPredicate()
Returns the predicate used to compare property values
StringgetPropName()
Returns the name of the property to be compared
VgetValue()
Returns the constant value to which properties are compared
booleanp(T arg)
Tests the designated property of the argument against the value given at construction.
StringtoString()

Constructor Detail

CompareProperty

public CompareProperty(String propName, V val)
Builds the CompareProperty predicate that will compare the named property to the given value using an EqualTo predicate.

CompareProperty

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

Method Detail

accept

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

getPredicate

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

Returns: the predicate used to compare property values.

getPropName

public 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

p

public boolean p(T arg)
Tests the designated property of the argument against the value given at construction.

Returns: the boolean value of the comparison

UNKNOWN: arg the object whose property will be tested

toString

public String toString()