geo.google.mapping
Class FunctionChain<ReturnType>

java.lang.Object
  extended by geo.google.mapping.FunctionChain<ReturnType>

public class FunctionChain<ReturnType>
extends Object

A FunctionChain is simply a chain of functions. When the execute() is call, the argument of execute() will be passed to the first function in the chain, the returned value of the first function will be further passed along as the argument of the second function in the chain. The returned value of the second function will be passed to the third function and so on until the end of the chain.
For example:
if you have a function Add1 that adds 1 to an integer, then you can create a function chain for adding 2, adding 3 and so on by chaining the Add1 function.

 Function add1 = new Function(){
        public Integer execute(Integer arg) {
          return arg+1;
        }
      };
 FunctionChain add2 = new FunctionChain(new Function[]{add1, add1});
 FunctionChain add3 = new FunctionChain(add1, add2);
 

Author:
jliang

Constructor Summary
FunctionChain(Functor[] functions)
           
FunctionChain(Functor head, FunctionChain tail)
           
FunctionChain(List<Functor> functions)
           
 
Method Summary
 ReturnType execute(Object arg)
          Execute function chain with arg as an argument.
static FunctionChain getChain(Functor func)
           
 Functor getHead()
           
 FunctionChain getTail()
           
 void setHead(Functor head)
           
 void setTail(FunctionChain tail)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FunctionChain

public FunctionChain(List<Functor> functions)

FunctionChain

public FunctionChain(Functor[] functions)

FunctionChain

public FunctionChain(Functor head,
                     FunctionChain tail)
Method Detail

getHead

public Functor getHead()

setHead

public void setHead(Functor head)

getTail

public FunctionChain getTail()

setTail

public void setTail(FunctionChain tail)

execute

public ReturnType execute(Object arg)
                   throws Exception
Execute function chain with arg as an argument.

Throws:
Throwable
Exception

getChain

public static FunctionChain getChain(Functor func)


Copyright © 2008. All Rights Reserved.