net.sf.jga.fn.property

Class SetProperty<T,R>

public class SetProperty<T,R> extends AbstractBinaryFunctor<T,R,R> implements Serializable

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 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceSetProperty.Visitor
Interface for classes that may interpret a SetProperty function.
Constructor Summary
SetProperty(String propName, Class propType)
Builds a SetProperty for the given property, which must be of the given class.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(SetProperty) method, if it implements the nested Visitor interface.
Rfn(T arg, R val)
Sets the designated property of the argument to the given value.
StringtoString()

Constructor Detail

SetProperty

public SetProperty(String propName, Class propType)
Builds a SetProperty for the given property, which must be of the given class. The class argument must be the same as the generic class argument (when generics are in use) or else a ClassCastException will be thrown when the functor is used.

Throws: IllegalArgumentException if either argument is omitted.

Method Detail

accept

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

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).

Returns: the value returned by the designated property's setter method

Throws: EvaluationException if the argument does not have the designated public property, or if it is accept the given value.

UNKNOWN: arg the object whose property will be set val the value to which the property will be set

toString

public String toString()