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

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

public class GetField<T,R>
extends UnaryFunctor<T,R>

Unary Functor that returns the value of the named field for the argument. The field name and type are set at construction.

Copyright © 2002-2005 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface GetField.Visitor
          Interface for classes that may interpret a GetField function.
 
Constructor Summary
GetField(java.lang.Class<T> argclass, java.lang.reflect.Field field)
          Builds a GetField for the given field
GetField(java.lang.Class<T> argclass, java.lang.String fieldName)
          Builds a GetField for the given field, using the given class to find the desired field.
GetField(java.lang.reflect.Field field)
          Builds a GetField for the given field
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(GetField) field, if it implements the nested Visitor interface.
 R fn(T arg)
          Returns the value of the designated field of the argument
 java.lang.reflect.Field getField()
          Lazily loads the Field object.
 java.lang.String getFieldName()
          Returns the name of the field that this functor retrieves.
 java.lang.Class<R> getFieldType()
          Returns the type of field that this functor retrieves.
 java.lang.Class<T> getObjectType()
          Returns the class on which the field is retrieved.
 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

GetField

public GetField(java.lang.reflect.Field field)
Builds a GetField for the given field

Throws:
java.lang.IllegalArgumentException - if the field is null, or is not a field of the given class

GetField

public GetField(java.lang.Class<T> argclass,
                java.lang.reflect.Field field)
Builds a GetField for the given field

Throws:
java.lang.IllegalArgumentException - if the field is null, or is not a field of the given class

GetField

public GetField(java.lang.Class<T> argclass,
                java.lang.String fieldName)
Builds a GetField for the given field, using the given class to find the desired field.

Throws:
java.lang.IllegalArgumentException - if the field name is null or empty,
Method Detail

getObjectType

public java.lang.Class<T> getObjectType()
Returns the class on which the field is retrieved.


getFieldName

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


getFieldType

public java.lang.Class<R> getFieldType()
Returns the type of field that this functor retrieves.


getField

public java.lang.reflect.Field getField()
                                 throws java.lang.NoSuchFieldException
Lazily loads the Field object.

Throws:
java.lang.NoSuchFieldException

fn

public R fn(T arg)
Returns the value of the designated field of the argument

Specified by:
fn in class UnaryFunctor<T,R>
Returns:
the value of the designated field of the argument
Throws:
EvaluationException - if the argument does not have the designated public field, or if it is not of the correct type.

accept

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