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

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

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

Functor that invokes a no-arg method named at construction and returns the result or null if the result is void.

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

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface InvokeNoArgMethod.Visitor
          Interface for classes that may interpret a InvokeMethod function.
 
Constructor Summary
InvokeNoArgMethod(java.lang.Class<T> objClass, java.lang.reflect.Method method)
          Builds a InvokeMethod for the given method, which takes no arguments.
InvokeNoArgMethod(java.lang.Class<T> objclass, java.lang.String methName)
          Builds a InvokeMethod for the given method, which takes no arguments.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(InvokeMethod) method, if it implements the nested Visitor interface.
 R fn(T obj)
          Invokes the method on the given object, and returns the result.
 java.lang.String getMethodName()
          Returns the name of the property that this functor retrieves.
 java.lang.Class<R> getReturnType()
          Returns the type of the method
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.UnaryFunctor
bind, compose, compose, generate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InvokeNoArgMethod

public InvokeNoArgMethod(java.lang.Class<T> objclass,
                         java.lang.String methName)
Builds a InvokeMethod for the given method, which takes no arguments.

Throws:
java.lang.IllegalArgumentException - if the method name is null or empty

InvokeNoArgMethod

public InvokeNoArgMethod(java.lang.Class<T> objClass,
                         java.lang.reflect.Method method)
Builds a InvokeMethod for the given method, which takes no arguments.

Throws:
java.lang.IllegalArgumentException - if the method name is null or empty, or if it is not defined for the given class, or if it takes arguments
Method Detail

getMethodName

public java.lang.String getMethodName()
Returns the name of the property that this functor retrieves.


getReturnType

public java.lang.Class<R> getReturnType()
Returns the type of the method


fn

public R fn(T obj)
Invokes the method on the given object, and returns the result.

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

accept

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

Specified by:
accept in interface Visitable
Overrides:
accept in class UnaryFunctor<T,R>

toString

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


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