com.hammurapi.flow.runtime.impl
Class Joiner<T,C,R>

java.lang.Object
  extended by com.hammurapi.flow.runtime.impl.Joiner<T,C,R>
Type Parameters:
T - Join element type.
C - Context type passed from addInput to join.
R - Return type passed from join to to addInput.

public abstract class Joiner<T,C,R>
extends Object

Helper class to join data from several inputs.

Author:
Pavel Vlasov

Nested Class Summary
static class Joiner.InputConsumer
          Interface to consume inputs in join() method.
 
Constructor Summary
protected Joiner(Collection<T>[] inputCollectors, Class<T> inputType, boolean outerJoin)
          Creates joiner.
 
Method Summary
 R addInput(int index, T input, C context)
          Adds input.
protected abstract  boolean isValidInput(int index, T input)
          This method is invoked for all inputs before joining.
protected abstract  R join(T[] inputs, C context, Joiner.InputConsumer consumer, int activator)
          This method is invoked for every combination of valid inputs.
protected abstract  boolean partialJoin(T[] inputs, int index)
          This method is invoked to validate already joined inputs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Joiner

protected Joiner(Collection<T>[] inputCollectors,
                 Class<T> inputType,
                 boolean outerJoin)
Creates joiner.

Parameters:
inputCollectors - Input collectors.
inputType - Input type is required because of erasure of generics and T is needed at runtime.
outerJoin - If true, each input addition triggers invocation of join, even if other input collectors don't have any data.
Method Detail

addInput

public R addInput(int index,
                  T input,
                  C context)
           throws Exception
Adds input. Input is joined with other accumulated inputs (including

Parameters:
index - Input index.
input - Input.
Throws:
Exception

join

protected abstract R join(T[] inputs,
                          C context,
                          Joiner.InputConsumer consumer,
                          int activator)
                   throws Exception
This method is invoked for every combination of valid inputs.

Parameters:
inputs - Inputs
Returns:
Array of consumed flags. The array shall be the same size as inputs or null. If it is not null, each input for which the array contains true is considered to be "consumed", i.e. it gets removed from internal collections and doesn't participate in further joins.
Throws:
Exception

isValidInput

protected abstract boolean isValidInput(int index,
                                        T input)
This method is invoked for all inputs before joining. It is useful for situation when inputs in internal collections may become invalid over the course of life of joiner.

Parameters:
index -
input -
Returns:

partialJoin

protected abstract boolean partialJoin(T[] inputs,
                                       int index)
                                throws Exception
This method is invoked to validate already joined inputs. If this method returns false, further joining is abandoned.

Parameters:
inputs - Inputs array.
index - Index of last already joined input.
Returns:
Throws:
Exception