uk.co.jezuk.mango
Class Adapt

java.lang.Object
  extended by uk.co.jezuk.mango.Adapt

public class Adapt
extends java.lang.Object

The Mango Library Object Adaptors

Provides methods to adapt instance and static methods into Functions.

Author:
Jez Higgins, jez@jezuk.co.uk
See Also:
Bind

Method Summary
static Function ArgumentMethod(java.lang.String methodName)
          Creates a Function which will call a method on the object passed as the argument to Function.fn method.
static
<T,Void> Function<T,Void>
ArgumentMethod(java.lang.String methodName, java.lang.Class<T> argType)
           
static
<T,R> Function<T,R>
ArgumentMethod(java.lang.String methodName, java.lang.Class<T> argType, java.lang.Class<R> returnType)
           
static Function Method(java.lang.Class klass, java.lang.String methodName)
          Adapts static member functions as Function objects, allowing them to be passed to algorithms.
static
<T,Void> Function<T,Void>
Method(java.lang.Class klass, java.lang.String methodName, java.lang.Class<T> argType)
           
static
<T,R> Function<T,R>
Method(java.lang.Class klass, java.lang.String methodName, java.lang.Class<T> argType, java.lang.Class<R> returnType)
           
static Function Method(java.lang.Object obj, java.lang.String methodName)
          Adapts member functions as Function objects, allowing them to be passed to algorithms.
static
<T,Void> Function<T,Void>
Method(java.lang.Object obj, java.lang.String methodName, java.lang.Class<T> argType)
           
static
<T,R> Function<T,R>
Method(java.lang.Object obj, java.lang.String methodName, java.lang.Class<T> argType, java.lang.Class<R> returnType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

Method

public static Function Method(java.lang.Object obj,
                              java.lang.String methodName)
Adapts member functions as Function objects, allowing them to be passed to algorithms.
e.g. to print all the elements in a list
Mango.forEach(list, Adapt.Method(System.out, "println"));
is equivalent to
for(int i = 0; i < list.size(); ++i)
System.out.println(list.get(i));

If the named method is not found, or its signature is incorrect throws a RuntimeException. If multiple methods have the correct name, and take a single parameter one of them will be called, but you can't determine which.


Method

public static <T,Void> Function<T,Void> Method(java.lang.Object obj,
                                               java.lang.String methodName,
                                               java.lang.Class<T> argType)

Method

public static <T,R> Function<T,R> Method(java.lang.Object obj,
                                         java.lang.String methodName,
                                         java.lang.Class<T> argType,
                                         java.lang.Class<R> returnType)

Method

public static Function Method(java.lang.Class klass,
                              java.lang.String methodName)
Adapts static member functions as Function objects, allowing them to be passed to algorithms.

If the named method is not found, or its signature is incorrect throws a RuntimeException. If multiple methods have the correct name, and take a single parameter one of them will be called, but you can't determine which.


Method

public static <T,Void> Function<T,Void> Method(java.lang.Class klass,
                                               java.lang.String methodName,
                                               java.lang.Class<T> argType)

Method

public static <T,R> Function<T,R> Method(java.lang.Class klass,
                                         java.lang.String methodName,
                                         java.lang.Class<T> argType,
                                         java.lang.Class<R> returnType)

ArgumentMethod

public static Function ArgumentMethod(java.lang.String methodName)
Creates a Function which will call a method on the object passed as the argument to Function.fn method.
e.g. to print all the elements in a list
interface Something { void persist(); }
// fill list with Somethings Mango.forEach(list, Bind.ArgumentMethod("persist"));

is equivalent to
for(int i = 0; i < list.size(); ++i)
{
  Something s = (Something)list.get(i);
  s.persist();
}

If the named method is not found, or its signature is incorrect throws a RuntimeException.

See Also:
Function

ArgumentMethod

public static <T,Void> Function<T,Void> ArgumentMethod(java.lang.String methodName,
                                                       java.lang.Class<T> argType)

ArgumentMethod

public static <T,R> Function<T,R> ArgumentMethod(java.lang.String methodName,
                                                 java.lang.Class<T> argType,
                                                 java.lang.Class<R> returnType)


Copyright © 2002-2010 JezUK Ltd.