-
Notifications
You must be signed in to change notification settings - Fork 58
MetaPipes
A metapipe is a pipe “wraps” another pipe. MetaPipes are useful in that they can make decisions based upon the behavior of the pipe(s) they wrap. There are numerous metapipes and this section will discuss a few of the more interesting cases. Moreover, by understanding the cases in which these pipes are used, its possible to create metapipes when such situations make themselves apparent.
A Pipeline
is a commonly used pipe. A Pipeline<S,E>
implements Pipe<S,E>
and as such, a Pipeline
is simply a Pipe
. A Pipeline
takes an ordered list of pipes in its constructor. It connects these pipes, whereby the input of pipe n
is connected to the output of pipe n-1
. Note that the output of pipe n-1
must be the same type as the input to pipe n
. The benefit of using a Pipeline
is that is greatly reduces the mental complexity of a process. It is analogous, in many ways, to creating a function to wrap a complex body of code. As such, the function serves as a blackbox with input and output.
There are two logical @FilterPipe@s called AndFilterPipe<S>
and OrFilterPipe<S>
. These pipes take an object of type S
and emit an object of type S
. However, they only emit the S
object if the collection of Pipe<S,Boolean>
that they wrap return true
. For AndFilterPipe
, all of its wrapped pipes must return true
for each object S
that it consumes. For the OrFilterPipe
, only one of its wrapped pipes must return true
.
Pipe<Integer,Integer> pipeA = new ObjectFilterPipe<Integer>(1, ComparisonFilterPipe.EQUALS);
Pipe<Integer,Integer> pipeB = new ObjectFilterPipe<Integer>(10, ComparisonFilterPipe.EQUALS);
Pipe<Integer,Integer> pipeC = new ObjectFilterPipe<Integer>(20, ComparisonFilterPipe.EQUALS);
Pipe<Integer,Integer> pipe1 = new OrFilterPipe<Integer>(new HasNextPipe<Integer>(pipeA), new HasNextPipe<Integer>(pipeB), new HasNextPipe<Integer>(pipeC));
pipe1.setStarts(Arrays.asList(1,22,10,136,7,2));
while(pipe1.hasNext()) {
System.out.print(pipe1.next() + "...");
}
The System.out
of the previous code is as follows.
1...10...
The FutureFilterPipe
is a metapipe that will determine what to do with its current S
object based upon some internal pipe that it wraps. That is, the FutureFilterPipe
will evaluate the object within its wrapped pipe and then allow the object to be emitted if it passes the test of its internal pipe. … TODO.