net.sf.jga.fn.property
Class SetField<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.SetField<T,R>
All Implemented Interfaces:
java.io.Serializable, Visitable
Direct Known Subclasses:
SetAndReturnField

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

Binary Functor that sets the named field of the first argument to the value. The field name and type are set at construction. The return value will be null.

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

Copyright © 2002-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface SetField.Visitor
          Interface for classes that may interpret a SetField function.
 
Constructor Summary
SetField(java.lang.Class<T> argType, java.lang.reflect.Field field)
          Builds a SetField that will update the value of the given field
SetField(java.lang.Class<T> argType, java.lang.reflect.Field field, java.lang.Class<R> fieldType)
          Builds a SetField that will update the value of the given field
SetField(java.lang.Class<T> argType, java.lang.String fieldName, java.lang.Class<R> fieldType)
          Builds a SetField that will update the value of the named field of an instance of type argType.
SetField(java.lang.reflect.Field field)
          Builds a SetField that will update the value of the given field
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(etField) field, if it implements the nested Visitor interface.
 R fn(T arg, R val)
          Sets the designated field of the argument to the given value and returns null.
 java.lang.String getFieldName()
          Returns the name of the field 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

SetField

public SetField(java.lang.reflect.Field field)
Builds a SetField that will update the value of the given field

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

SetField

public SetField(java.lang.Class<T> argType,
                java.lang.reflect.Field field)
Builds a SetField that will update the value of the given field

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

SetField

public SetField(java.lang.Class<T> argType,
                java.lang.reflect.Field field,
                java.lang.Class<R> fieldType)
Builds a SetField that will update the value of the given field

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

SetField

public SetField(java.lang.Class<T> argType,
                java.lang.String fieldName,
                java.lang.Class<R> fieldType)
Builds a SetField that will update the value of the named field of an instance of type argType. The field will be of type propType.

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

getFieldName

public java.lang.String getFieldName()
Returns the name of the field that this functor sets.


fn

public R fn(T arg,
            R val)
Sets the designated field of the argument to the given value and returns null.

Specified by:
fn in class BinaryFunctor<T,R,R>
Returns:
null
Throws:
EvaluationException - if the argument does not have the designated public field, or if it is accept the given value.

accept

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