net.fortytwo.flow.Mapping Maven / Gradle / Ivy
package net.fortytwo.flow;
import net.fortytwo.ripple.RippleException;
/**
* A data transformer which takes individual data items of one type (the "arguments"),
* maps them to zero or more items of a second type (the "solutions") and
* pushes the solutions into a downstream Sink
*
* @param the argument data type
* @param the solution data type
* @param a helper type which provides "context" to the mapping
*
* @author Joshua Shinavier (http://fortytwo.net)
*/
public interface Mapping
{
/**
* @return whether this function is referentially transparent w.r.t. all of its
* parameters.
*/
boolean isTransparent();
// Open-world, push-based
/**
* Applies the mapping to a single argument,
* producing zero or more solutions and passing them into a downstream Sink
* @param arg the argument data item
* @param solutions the solutions the argument is mapped to
* @param context a helper object providing context (may be null)
* @throws RippleException if a data handling error occurs
*/
void apply( D arg, Sink solutions, C context ) throws RippleException;
/*
// Open-world, pull-based
Iterator apply( D arg ) throws E;
// Closed-world, push-based
void apply( Iterator source, Sink sink ) throws E;
// Closed-world, pull-based
Iterator apply( Iterator source ) throws E;
public class Count implements Mapping
{
public void apply( Collection source, Sink sink ) throws RippleException
{
sink.put( new Integer( source.size() ) );
}
}*/
}