net.sf.jga.fn.property
Class SetProperty<T,R>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.BinaryFunctor<T,R,R>
          extended by net.sf.jga.fn.property.SetProperty<T,R>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class SetProperty<T,R>
extends BinaryFunctor<T,R,R>

Binary Functor that sets the named property of the first argument to the value. The property name and type are set at construction. The return value will be that which the argument's property setter method returns (generally either null or the old value).

Note that declaring the return type incorrectly can result in ClassCastExceptions being thrown when the functor is invoked: the compiler cannot check the return type of a reflectively loaded method.

Copyright © 2002-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface SetProperty.Visitor
          Interface for classes that may interpret a SetProperty function.
 
Constructor Summary
SetProperty(java.lang.Class<T> argType, java.lang.String propName, java.lang.Class<R> propType)
          Builds a SetProperty that will return the value of the named property of an instance of type argType.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(SetProperty) method, if it implements the nested Visitor interface.
 R fn(T arg, R val)
          Sets the designated property of the argument to the given value.
 java.lang.String getPropertyName()
          Returns the name of the property that this functor sets.
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.BinaryFunctor
bind, bind0th, bind1st, bind2nd, bindNth, compose, compose, composeNth, distribute, eval, generate, generate1st, generate2nd, generateNth
 
Methods inherited from class net.sf.jga.fn.Functor
composeNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SetProperty

public SetProperty(java.lang.Class<T> argType,
                   java.lang.String propName,
                   java.lang.Class<R> propType)
Builds a SetProperty that will return the value of the named property of an instance of type argType. The property will be of type propType.

Throws:
java.lang.IllegalArgumentException - if either argument is omitted, or if there is no such setter method in type argType.
Method Detail

getPropertyName

public java.lang.String getPropertyName()
Returns the name of the property that this functor sets.


fn

public R fn(T arg,
            R val)
Sets the designated property of the argument to the given value. When the property's setter method returns a value, then this functor will return it (otherwise it will return null).

Specified by:
fn in class BinaryFunctor<T,R,R>
Returns:
the value returned by the designated property's setter method: generally it is null, but in some cases it might be the old value
Throws:
EvaluationException - if the argument does not have the designated public property, or if it is accept the given value.

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<R>

toString

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


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