jfun.yan
Class Functions

java.lang.Object
  extended by jfun.yan.Functions

public final class Functions
extends java.lang.Object

This is the facade class to create different Function objects.

throughout this class, when searching reflection objects, public members are defined as members defined with "public" keyword and declared in a public type. public members declared by a non-public class is considered non-public because access to it from outside is prohibited by the java access control anyway.

public members defined in public classes are always prefered even when we allow private/protected members and types to be visible. So if a non-public subtype and a public super type both have a field with the same name, the field in the public super type is always used.

Codehaus.org.

Author:
Ben Yu

Constructor Summary
Functions()
           
 
Method Summary
static
<T> Function<T>
ctor(java.lang.Class<T> c)
          Create a Function object that uses the public constructor of a class.
static
<T> Function<T>
ctor(java.lang.Class<T> c, boolean suppress_security)
          Create a Function object that uses the constructor of a class.
static
<T> Function<T>
ctor(java.lang.Class<T> c, java.lang.Class[] param_types)
          Create a Function object that uses one public constructor of a class.
static
<T> Function<T>
ctor(java.lang.Class<T> c, java.lang.Class[] param_types, boolean suppress_security)
          Create a Function object that uses one constructor of a class.
static
<T> Function<T>
ctor(java.lang.reflect.Constructor<T> ctor)
          Adapts a Constructor object to a Function object.
static Function field(java.lang.Class type, java.lang.Object obj, java.lang.String name)
          Create a Function object that reads a public field from a given object.
static Function field(java.lang.Class type, java.lang.Object obj, java.lang.String name, boolean suppress_security)
          Create a Function object that reads a field from a given object.
static Function field(java.lang.Object obj, java.lang.reflect.Field fld)
          Adapts a Field object and the receiver object to a Function object.
static Function field(java.lang.Object obj, java.lang.String name)
          Create a Function object that reads a public field from a given object.
static Function field(java.lang.Object obj, java.lang.String name, boolean suppress_security)
          Create a Function object that reads a field from a given object.
static Function getter(Bean bean, java.lang.String name)
          Creates a Function object that invokes a property getter.
static Function indexed_getter(Bean bean, java.lang.String name, int ind)
          Creates a Function object that invokes an indexed property getter.
static Function indexed_setter(Bean bean, java.lang.String name, int ind)
          Creates a Function object that invokes an indexed property setter.
static Function instance_field(java.lang.Class c, java.lang.reflect.Field fld)
          Create a Function object that reads an instance field.
static Function instance_field(java.lang.Class c, java.lang.String name)
          Create a Function object that reads a public instance field.
static Function instance_field(java.lang.Class c, java.lang.String name, boolean suppress_security)
          Create a Function object that reads an instance field.
static Function instance_method(java.lang.Class c, java.lang.reflect.Method mtd)
          Create a Function object that invokes an instance method.
static Function instance_method(java.lang.Class c, java.lang.String name)
          Create a Function object that invokes a public instance method.
static Function instance_method(java.lang.Class c, java.lang.String name, boolean suppress_security)
          Create a Function object that invokes an instance method.
static Function instance_method(java.lang.Class c, java.lang.String name, java.lang.Class[] param_types)
          Create a Function object that invokes a public instance method.
static Function instance_method(java.lang.Class c, java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Create a Function object that invokes an instance method.
static Function method(java.lang.Class type, java.lang.Object obj, java.lang.String name)
          Create a Function object that invokes a public method against a given object.
static Function method(java.lang.Class type, java.lang.Object obj, java.lang.String name, boolean suppress_security)
          Create a Function object that invokes a method against a given object.
static Function method(java.lang.Class type, java.lang.Object obj, java.lang.String name, java.lang.Class[] param_types)
          Create a Function object that invokes a public method against a given object.
static Function method(java.lang.Class type, java.lang.Object obj, java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Create a Function object that invokes a method against a given object.
static Function method(java.lang.Object obj, java.lang.reflect.Method mtd)
          Adapts a Method object and the receiver object to a Function object.
static Function method(java.lang.Object obj, java.lang.String name)
          Create a Function object that invokes a public method against a given object.
static Function method(java.lang.Object obj, java.lang.String name, boolean suppress_security)
          Create a Function object that invokes a method against a given object.
static Function method(java.lang.Object obj, java.lang.String name, java.lang.Class[] param_types)
          Create a Function object that invokes a public method against a given object.
static Function method(java.lang.Object obj, java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Create a Function object that invokes a method against a given object.
static Function setter(Bean bean, java.lang.String name)
          Creates a Function object that invokes a property setter.
static Function static_field(java.lang.Class c, java.lang.String name)
          Create a Function object that reads a public static field.
static Function static_field(java.lang.Class c, java.lang.String name, boolean suppress_security)
          Create a Function object that reads a static field.
static Function static_field(java.lang.reflect.Field fld)
          Create a Function object that reads a static field.
static Function static_method(java.lang.Class c, java.lang.String name)
          Create a Function object that invokes a public static method.
static Function static_method(java.lang.Class c, java.lang.String name, boolean suppress_security)
          Create a Function object that invokes a static method.
static Function static_method(java.lang.Class c, java.lang.String name, java.lang.Class[] param_types)
          Create a Function object that invokes a public static method.
static Function static_method(java.lang.Class c, java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Create a Function object that invokes a static method.
static Function static_method(java.lang.reflect.Method mtd)
          Create a Function object that invokes a static method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functions

public Functions()
Method Detail

ctor

public static <T> Function<T> ctor(java.lang.reflect.Constructor<T> ctor)
Adapts a Constructor object to a Function object.

Parameters:
ctor - the constructor object.
Returns:
the Function object.

method

public static Function method(java.lang.Object obj,
                              java.lang.reflect.Method mtd)
Adapts a Method object and the receiver object to a Function object.

Parameters:
obj - the receiver object to call the method against. If the method is static, the object can be null.
mtd - the method object.
Returns:
the Function object.

ctor

public static <T> Function<T> ctor(java.lang.Class<T> c)
                        throws java.lang.IllegalArgumentException
Create a Function object that uses the public constructor of a class. This class should have one and only one public constructor.
Array type is given a special constructor so that the constructor of array type T has one parameter of type int and calls new T[size] when invoked.

Parameters:
c - the class.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - if the class has no public constructor or has more than one public constructor.

ctor

public static <T> Function<T> ctor(java.lang.Class<T> c,
                                   boolean suppress_security)
                        throws java.lang.IllegalArgumentException
Create a Function object that uses the constructor of a class. This class should have one and only one visible constructor.
Array type is given a special constructor so that the constructor of array type T has one parameter of type int and calls new T[size] when invoked.

Parameters:
c - the class.
suppress_security - whether access to non-public members is allowed.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - if the class has no public constructor or has more than one public constructor.

ctor

public static <T> Function<T> ctor(java.lang.Class<T> c,
                                   java.lang.Class[] param_types)
Create a Function object that uses one public constructor of a class. The constructor to invoke is determined by the parameter types specified.
Array type is given a special constructor so that the constructor of array type T has one parameter of type int and calls new T[size] when invoked.

Parameters:
c - the class.
param_types - the parameter types of the constructor to use. null indicates the default constructor.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - if the public constructor cannot be found.

ctor

public static <T> Function<T> ctor(java.lang.Class<T> c,
                                   java.lang.Class[] param_types,
                                   boolean suppress_security)
                        throws java.lang.IllegalArgumentException
Create a Function object that uses one constructor of a class. The constructor to invoke is determined by the parameter types specified.
Array type is given a special constructor so that the constructor of array type T has one parameter of type int and calls new T[size] when invoked.

Parameters:
c - the class.
param_types - the parameter types of the constructor to use.
suppress_security - whether access to non-public member is allowed. null indicates the default constructor.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - if the public constructor cannot be found.

static_method

public static Function static_method(java.lang.Class c,
                                     java.lang.String name)
Create a Function object that invokes a public static method. This class should have one and only one public static method of this name.

Parameters:
c - the class where the static method belongs.
name - the static method name.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. this method is not static.
3. more than one public static method with the specified name.
4. no public static method with the specified name.
5. the class is not public.

static_method

public static Function static_method(java.lang.Class c,
                                     java.lang.String name,
                                     boolean suppress_security)
Create a Function object that invokes a static method. This class should have one and only one visible static method of this name.

Parameters:
c - the class where the static method belongs.
name - the static method name.
suppress_security - whether to look at non-public methods.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. this method is not static.
3. more than one visible static method with the specified name.
4. no visible static method with the specified name.
5. the class is not visible.

static_method

public static Function static_method(java.lang.Class c,
                                     java.lang.String name,
                                     java.lang.Class[] param_types)
Create a Function object that invokes a public static method. The static method to invoke is determined by the method name and the parameter types.

Parameters:
c - the class where the static method belongs.
name - the static method name.
param_types - the parameter types. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. this method is not static.
3. no public static method with the specified name and the parameter types.
4. the class is not public.

static_method

public static Function static_method(java.lang.Class c,
                                     java.lang.String name,
                                     java.lang.Class[] param_types,
                                     boolean suppress_security)
                              throws java.lang.IllegalArgumentException
Create a Function object that invokes a static method. The static method to invoke is determined by the method name and the parameter types.

Parameters:
c - the class where the static method belongs.
name - the static method name.
param_types - the parameter types. null indicates a parameter-less method.
suppress_security - whether to look at non-public methods.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. this method is not static.
3. no visible static method with the specified name and the parameter types.
4. the class is not visible.

static_method

public static Function static_method(java.lang.reflect.Method mtd)
Create a Function object that invokes a static method. The static method to invoke is determined by the method name and the parameter types.

Parameters:
mtd - the method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if this method is not static.

instance_method

public static Function instance_method(java.lang.Class c,
                                       java.lang.String name)
Create a Function object that invokes a public instance method. This class should have one and only one public instance method of this name.
The first parameter of this Function will be the object to invoke the method against.

Parameters:
c - the class where the instance method belongs.
name - the instance method name.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. this method is static.
3. more than one public instance method with the specified name.
4. no public instance method with the specified name.
5. the class is not public.

instance_method

public static Function instance_method(java.lang.Class c,
                                       java.lang.String name,
                                       boolean suppress_security)
                                throws java.lang.IllegalArgumentException
Create a Function object that invokes an instance method. This class should have one and only one visible instance method of this name.
The first parameter of this Function will be the object to invoke the method against.

Parameters:
c - the class where the instance method belongs.
name - the instance method name.
suppress_security - whether to look at non-public methods.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. this method is static.
3. more than one visible instance method with the specified name.
4. no visible instance method with the specified name.
5. the class is not visible.

instance_method

public static Function instance_method(java.lang.Class c,
                                       java.lang.String name,
                                       java.lang.Class[] param_types)
Create a Function object that invokes a public instance method. The instance method to invoke is determined by the method name and the parameter types.
The first parameter of this Function will be the object to invoke the method against.

Parameters:
c - the class where the instance method belongs.
name - the method name.
param_types - the parameter types. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. this method is static.
3. no public instance method with the specified name and the parameter types.

instance_method

public static Function instance_method(java.lang.Class c,
                                       java.lang.String name,
                                       java.lang.Class[] param_types,
                                       boolean suppress_security)
                                throws java.lang.IllegalArgumentException
Create a Function object that invokes an instance method. The instance method to invoke is determined by the method name and the parameter types.
The first parameter of this Function will be the object to invoke the method against.

Parameters:
c - the class where the instance method belongs.
name - the method name.
param_types - the parameter types.
suppress_security - whether to look at non-public ones. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. this method is static.
3. no visible instance method with the specified name and the parameter types.
4. the class is not visible.

instance_method

public static Function instance_method(java.lang.Class c,
                                       java.lang.reflect.Method mtd)
Create a Function object that invokes an instance method.
The first parameter of this Function will be the object to invoke the method against.

Parameters:
c - the class where the instance method belongs.
mtd - the method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if this method is static.

method

public static Function method(java.lang.Object obj,
                              java.lang.String name)
Create a Function object that invokes a public method against a given object. The class of the object should be public and have one and only one public method of this name.

Parameters:
obj - the object to run the method against. It cannot be null.
name - the method name.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. more than one public method with the specified name.
3. no public method with the specified name.

method

public static Function method(java.lang.Object obj,
                              java.lang.String name,
                              boolean suppress_security)
Create a Function object that invokes a method against a given object. The class of the object should have one and only one visible method of this name.

Parameters:
obj - the object to run the method against. It cannot be null.
name - the method name.
suppress_security - whether to look at non-public ones.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. more than one public method with the specified name.
3. no visible method with the specified name.

method

public static Function method(java.lang.Class type,
                              java.lang.Object obj,
                              java.lang.String name)
Create a Function object that invokes a public method against a given object. The class of the object should have one and only one public method of this name.

Parameters:
type - the Class object to look up method. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to run the method against.
name - the method name.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. more than one public method with the specified name.
3. no public method with the specified name.

method

public static Function method(java.lang.Class type,
                              java.lang.Object obj,
                              java.lang.String name,
                              boolean suppress_security)
Create a Function object that invokes a method against a given object. The class of the object should have one and only one visible method of this name.

Parameters:
type - the Class object to look up method. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to run the method against.
name - the method name.
suppress_security - whether to look at non-public ones.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. more than one public method with the specified name.
3. no public method with the specified name.

method

public static Function method(java.lang.Object obj,
                              java.lang.String name,
                              java.lang.Class[] param_types)
Create a Function object that invokes a public method against a given object. The method to invoke is determined by the method name and the parameter types.

Parameters:
obj - the object to run the method against. It cannot be null.
name - the method name.
param_types - the parameter types. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. no public method with the specified name and the parameter types.

method

public static Function method(java.lang.Object obj,
                              java.lang.String name,
                              java.lang.Class[] param_types,
                              boolean suppress_security)
Create a Function object that invokes a method against a given object. The method to invoke is determined by the method name and the parameter types.

Parameters:
obj - the object to run the method against. It cannot be null.
name - the method name.
param_types - the parameter types.
suppress_security - whether to look at non-public ones. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. no visible method with the specified name and the parameter types.

method

public static Function method(java.lang.Class type,
                              java.lang.Object obj,
                              java.lang.String name,
                              java.lang.Class[] param_types)
Create a Function object that invokes a public method against a given object. The method to invoke is determined by the method name and the parameter types.

Parameters:
type - the Class object to look up method. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to run the method against. It cannot be null.
name - the method name.
param_types - the parameter types. null indicates a parameter-less method.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not public.
2. no public method with the specified name and the parameter types.

method

public static Function method(java.lang.Class type,
                              java.lang.Object obj,
                              java.lang.String name,
                              java.lang.Class[] param_types,
                              boolean suppress_security)
Create a Function object that invokes a method against a given object. The method to invoke is determined by the method name and the parameter types.

Parameters:
type - the Class object to look up method. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to run the method against. It cannot be null.
name - the method name.
param_types - the parameter types. null indicates a parameter-less method.
suppress_security - whether to look at non-public ones.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. this method is not visible.
2. no visible method with the specified name and the parameter types.

getter

public static Function getter(Bean bean,
                              java.lang.String name)
Creates a Function object that invokes a property getter.

Parameters:
bean - the bean object.
name - the property name.
Returns:
the Function object.

indexed_getter

public static Function indexed_getter(Bean bean,
                                      java.lang.String name,
                                      int ind)
Creates a Function object that invokes an indexed property getter.

Parameters:
bean - the bean object.
name - the property name.
ind - the index.
Returns:
the Function object.

setter

public static Function setter(Bean bean,
                              java.lang.String name)
Creates a Function object that invokes a property setter.

Parameters:
bean - the bean object.
name - the property name.
Returns:
the Function object.

indexed_setter

public static Function indexed_setter(Bean bean,
                                      java.lang.String name,
                                      int ind)
Creates a Function object that invokes an indexed property setter.

Parameters:
bean - the bean object.
name - the property name.
ind - the index.
Returns:
the Function object.

static_field

public static Function static_field(java.lang.Class c,
                                    java.lang.String name)
Create a Function object that reads a public static field.

Parameters:
c - the class where the static field belongs.
name - the static field name.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. field is not static.
3. field is not public.

static_field

public static Function static_field(java.lang.Class c,
                                    java.lang.String name,
                                    boolean suppress_security)
Create a Function object that reads a static field.

Parameters:
c - the class where the static field belongs.
name - the static field name.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. field is not static.

static_field

public static Function static_field(java.lang.reflect.Field fld)
Create a Function object that reads a static field. The static field to read is determined by the field name and the parameter types.

Parameters:
fld - the field.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if this field is not static.

instance_field

public static Function instance_field(java.lang.Class c,
                                      java.lang.String name)
Create a Function object that reads a public instance field.
The first parameter of this Function will be the object to read the field from.

Parameters:
c - the class where the instance field belongs.
name - the instance field name.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. this field is static.
3. the field is not public.

instance_field

public static Function instance_field(java.lang.Class c,
                                      java.lang.String name,
                                      boolean suppress_security)
                               throws java.lang.IllegalArgumentException
Create a Function object that reads an instance field.
The first parameter of this Function will be the object to read the field from.

Parameters:
c - the class where the instance field belongs.
name - the instance field name.
suppress_security - whether to look at non-public ones.
Returns:
the Component object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. this field is static.

instance_field

public static Function instance_field(java.lang.Class c,
                                      java.lang.reflect.Field fld)
Create a Function object that reads an instance field.
The first parameter of this Function will be the object to read the field from.

Parameters:
c - the class where the instance field belongs.
fld - the field.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if this field is static.

field

public static Function field(java.lang.Object obj,
                             java.lang.String name)
Create a Function object that reads a public field from a given object.

Parameters:
obj - the object to read the field from. It cannot be null.
name - the field name.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. field is not public.

field

public static Function field(java.lang.Object obj,
                             java.lang.String name,
                             boolean suppress_security)
Create a Function object that reads a field from a given object.

Parameters:
obj - the object to read the field from. It cannot be null.
name - the field name.
suppress_security - whether to look at non-public ones.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.

field

public static Function field(java.lang.Class type,
                             java.lang.Object obj,
                             java.lang.String name)
Create a Function object that reads a public field from a given object.

Parameters:
type - the Class object to look up field. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to read field from.
name - the field name.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.
2. field is not public.

field

public static Function field(java.lang.Class type,
                             java.lang.Object obj,
                             java.lang.String name,
                             boolean suppress_security)
Create a Function object that reads a field from a given object.

Parameters:
type - the Class object to look up field. This parameter can be used when we only want to look up in a super type rather than obj.getClass().
obj - the object to read field from.
name - the field name.
suppress_security - whether to look at non-public ones.
Returns:
the Function object.
Throws:
java.lang.IllegalArgumentException - thrown if any of the following conditions is true:
1. field is not found.

field

public static Function field(java.lang.Object obj,
                             java.lang.reflect.Field fld)
Adapts a Field object and the receiver object to a Function object.

Parameters:
obj - the receiver object to read the field from. If the field is static, the object can be null.
fld - the field object.
Returns:
the Function object.