Class AbstractProcessor.FlatMapper<T,​R>

Type Parameters:
T - type of the input item
R - type of the emitted item
Enclosing class:

protected final class AbstractProcessor.FlatMapper<T,​R>
extends Object
A helper that simplifies the implementation of tryProcess(ordinal, item) for emitting collections. User supplies a mapper which takes an item and returns a traverser over all output items that should be emitted. The tryProcess(Object) method obtains and passes the traverser to AbstractProcessor.emitFromTraverser(int, Traverser). Example:
 public static class SplitWordsP extends AbstractProcessor {

    private FlatMapper<String, String> flatMapper =
             flatMapper(item -> Traverser.over(item.split("\\W")));

     protected boolean tryProcess(int ordinal, Object item) throws Exception {
         return flatMapper.tryProcess((String) item);
  • Method Details

    • tryProcess

      public boolean tryProcess​(@Nonnull T item)
      Method designed to be called from one of AbstractProcessor#tryProcessX() methods. The calling method must return this method's return value.
      item - the item to process
      what the calling tryProcessX() method should return