Skip to content
Snippets Groups Projects
Commit 2ce8ca50 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

implemented the FileExtensionSwitch with HPPC

parent 59bd0445
No related branches found
No related tags found
No related merge requests found
...@@ -16,35 +16,23 @@ ...@@ -16,35 +16,23 @@
package teetime.stage; package teetime.stage;
import java.io.File; import java.io.File;
import java.util.Map;
import teetime.framework.AbstractConsumerStage; import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort; import teetime.framework.OutputPort;
import teetime.util.HashMapWithDefault;
import teetime.util.concurrent.hashmap.ValueFactory;
import com.carrotsearch.hppc.ObjectObjectOpenHashMap;
import com.google.common.io.Files; import com.google.common.io.Files;
public final class FileExtensionSwitch extends AbstractConsumerStage<File> { public final class FileExtensionSwitch extends AbstractConsumerStage<File> {
private final OutputPort<File> unknownFileExtensionOutputPort = createOutputPort(File.class); private final OutputPort<File> unknownFileExtensionOutputPort = createOutputPort(File.class);
// BETTER use the hppc ObjectObjectMap that provide getOrDefault() private final ObjectObjectOpenHashMap<String, OutputPort<File>> fileExtensions = new ObjectObjectOpenHashMap<String, OutputPort<File>>();
private final Map<String, OutputPort<File>> fileExtensions = new HashMapWithDefault<String, OutputPort<File>>(new ValueFactory<OutputPort<File>>() {
@Override
public OutputPort<File> create() {
return unknownFileExtensionOutputPort;
}
});
@Override @Override
protected void execute(final File file) { protected void execute(final File file) {
String fileExtension = Files.getFileExtension(file.getAbsolutePath()); String fileExtension = Files.getFileExtension(file.getAbsolutePath());
if (logger.isDebugEnabled()) { OutputPort<File> outputPort = this.fileExtensions.getOrDefault(fileExtension, unknownFileExtensionOutputPort);
this.logger.debug("fileExtension: " + fileExtension);
}
OutputPort<File> outputPort = this.fileExtensions.get(fileExtension);
outputPort.send(file); outputPort.send(file);
} }
...@@ -55,7 +43,6 @@ public final class FileExtensionSwitch extends AbstractConsumerStage<File> { ...@@ -55,7 +43,6 @@ public final class FileExtensionSwitch extends AbstractConsumerStage<File> {
} }
OutputPort<File> outputPort = this.createOutputPort(); OutputPort<File> outputPort = this.createOutputPort();
this.fileExtensions.put(fileExtension, outputPort); this.fileExtensions.put(fileExtension, outputPort);
this.logger.debug("SUCCESS: Registered output port for '" + fileExtension + "'");
return outputPort; return outputPort;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment