Pipe { public List<T> process(T elem) { Pipe<T> p = head; List<T> elems = new ArrayList<T>(); p.fun.eval(elem, p.collector); while (p.getNext() != null) { Iterator<T> iter = p.getOutput(); if (iter == null) { logger.warn("iter is null"); } elems.clear(); while (iter.hasNext()) { T obj = iter.next(); if (obj == null) { logger.warn("iter returned null object"); } if (obj != null) { elems.add(obj); } } p.clearOutput(); p = p.getNext(); for (T t : elems) { p.fun.eval(t, p.collector); } } return getResults(); } Pipe(Function<T> fun);  Pipe(Pipe<T> previous, Function<T> fun); List<T> process(T elem); public ArrayList<T> output; }
@Test public void pipe2() { Pipe<String> pipe = new Pipe<String>(new AppendOne()); pipe = new Pipe<String>(pipe, new AppendTwo()); List<String> result = pipe.process(""); assertEquals("12",result.get(0)); }