uk.co.jezuk.mango
Class Adapt

java.lang.Object
  extended byuk.co.jezuk.mango.Adapt

public class Adapt
extends java.lang.Object

Object method adaptors.

Version:
$Id: Adapt.java 79 2003-04-03 11:34:24Z jez $
Author:
Jez Higgins, jez@jezuk.co.uk
See Also:
Bind

Method Summary
static UnaryFunction ArgumentMethod(java.lang.String methodName)
          Creates a UnaryFunction which will call a method on the object passed as the argument to UnaryFunction.fn method.
static BinaryFunction Compose(BinaryFunction f, UnaryFunction g1, UnaryFunction g2)
          Compose is a function adaptor.
static UnaryFunction Compose(UnaryFunction f, UnaryFunction g)
          Compose is a unary function adaptor.
static UnaryFunction Method(java.lang.Class klass, java.lang.String methodName)
          Adapts static member functions as UnaryFunction objects, allowing them to be passed to algorithms.
static UnaryFunction Method(java.lang.Object obj, java.lang.String methodName)
          Adapts member functions as UnaryFunction objects, allowing them to be passed to algorithms.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

Compose

public static UnaryFunction Compose(UnaryFunction f,
                                    UnaryFunction g)
Compose is a unary function adaptor. If f and g are UnaryFunctions, then Compose creates a new function h, where h(x) is equal to f(g(x)).


Compose

public static BinaryFunction Compose(BinaryFunction f,
                                     UnaryFunction g1,
                                     UnaryFunction g2)
Compose is a function adaptor. If f is a BinaryFunction and g1 and g2 are UnaryFunctions, then Compose returns a new BinaryFunction h such that h(x, y) is f(g1(x), g2(y))


Method

public static UnaryFunction Method(java.lang.Object obj,
                                   java.lang.String methodName)
Adapts member functions as UnaryFunction 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 UnaryFunction Method(java.lang.Class klass,
                                   java.lang.String methodName)
Adapts static member functions as UnaryFunction 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.


ArgumentMethod

public static UnaryFunction ArgumentMethod(java.lang.String methodName)
Creates a UnaryFunction which will call a method on the object passed as the argument to UnaryFunction.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:
UnaryFunction


Copyright © 2002-2006 JezUK Ltd.