net.sf.jga.fn.property
Class InvokeNoArgMethod<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.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 unless we add more arguments to the constructor.

Copyright © 2003-2005 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 an InvokeNoArgMethod for the given method, which takes no arguments.
InvokeNoArgMethod(java.lang.Class<T> objclass, java.lang.String methName)
          Builds a InvokeNoArgMethod for the given method, which takes no arguments.
InvokeNoArgMethod(java.lang.reflect.Method method)
          Builds an InvokeNoArgMethod 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.reflect.Method getMethod()
          Lazy loads the method
 java.lang.String getMethodName()
          Returns the name of the property that this functor retrieves.
 java.lang.Class<T> getObjectType()
          Returns the class which supplied the method is invoked.
 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, 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

InvokeNoArgMethod

public InvokeNoArgMethod(java.lang.Class<T> objclass,
                         java.lang.String methName)
Builds a InvokeNoArgMethod 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.reflect.Method method)
Builds an InvokeNoArgMethod for the given method, which takes no arguments.

NOTE: this constructor has lower type-safety guarantee than the other constructors, in that the compiler cannot check that the method's declaring class is T. When a functor built by this constructor is evaluated, it will throw IllegalArgumentException if given an incompatible argument.

Throws:
java.lang.IllegalArgumentException - if the method is null or if it takes arguments

InvokeNoArgMethod

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

Throws:
java.lang.IllegalArgumentException - if the method or class is null; if the method is not supplied by the given class; or if the method takes one or more arguments
Method Detail

getObjectType

public java.lang.Class<T> getObjectType()
Returns the class which supplied the method is invoked.


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


getMethod

public java.lang.reflect.Method getMethod()
                                   throws java.lang.NoSuchMethodException
Lazy loads the method

Throws:
java.lang.NoSuchMethodException

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.
java.lang.IllegalArgumentException - if the argument 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 Functor<R>

toString

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


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