net.sf.jga.fn.property

Class ConstructUnary<T,R>

public class ConstructUnary<T,R> extends AbstractUnaryFunctor<T,R> implements Serializable

Unary Predicate that constructs an object of the given class via a one-argument constructor.

Note that declaring the argument type or the return type incorrectly can result in an EvaluationException being thrown on construction or a ClassCastException being thrown when the functor is invoked: the compiler cannot check the argument type or return type of a reflectively loaded constructor.

Copyright © 2003 David A. Hall

Author: David A. Hall

Nested Class Summary
interfaceConstructUnary.Visitor
Interface for classes that may interpret a ConstructUnary predicate.
Constructor Summary
ConstructUnary(Class argclass, Class ctorclass)
Builds a predicate that will build an object of class ctorclass, given an argument of class argclass.
Method Summary
voidaccept(Visitor v)
Calls the Visitor's visit(ConstructUnary) method, if it implements the nested Visitor interface.
Rfn(T arg)
Builds an object via a one-arg constructor, passing the given value.
StringtoString()

Constructor Detail

ConstructUnary

public ConstructUnary(Class argclass, Class ctorclass)
Builds a predicate that will build an object of class ctorclass, given an argument of class argclass. The classes passed to the constructor must be assignable to the generic arguments (when generics are in use): ConstructUnary ctor = new ConstructUnary(String.class,Integer.class);

Throws: EvaluationException if the constructor cannot be found IllegalArgumentException if either argument is omitted

Method Detail

accept

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

fn

public R fn(T arg)
Builds an object via a one-arg constructor, passing the given value.

Returns: the object built by the constructor

UNKNOWN: arg the value to be passed to the constructor

toString

public String toString()