... | ... | @@ -23,8 +23,41 @@ The last stage will save or print the resulting number. |
|
|
Our mission is to implement those four stages as seperate filter and connect them.
|
|
|
In the following we will learn how to implement a stage.
|
|
|
|
|
|
### Implementing a stage
|
|
|
### Implementing them stages
|
|
|
|
|
|
This section will explain the implementation of those exact stages.
|
|
|
If you want to dig deeper into the implementation mechanisms of the TeeTime framework, we recommend to take a look at [INSERT LINK](#).
|
|
|
|
|
|
Our first stage will be the ```DirReader```. It visits all directories and sends all containing files to the next stage.
|
|
|
A suitable implementation may look like this:
|
|
|
```Java
|
|
|
class DirReader extends AbstractProducerStage<File> {
|
|
|
|
|
|
private final File element;
|
|
|
|
|
|
public DirReader(final File directory) {
|
|
|
if (directory.isDirectory()) { // Check if it is a directory
|
|
|
element = directory;
|
|
|
} else {
|
|
|
throw new IllegalArgumentException("Given file is not a directory.");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void execute() {
|
|
|
visit(element);
|
|
|
this.terminate(); // If everything is done, terminate
|
|
|
}
|
|
|
|
|
|
private void visit(final File element) {
|
|
|
for (File file : element.listFiles()) {
|
|
|
if (file.isDirectory()) {
|
|
|
this.visit(file); // Visit recursively all dirs
|
|
|
} else {
|
|
|
outputPort.send(file); // Send file to next stage
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |