Skip to content
Snippets Groups Projects
Commit da616025 authored by Sören Henning's avatar Sören Henning
Browse files

use java util Function instead of own Interface

fix #30
parent f3996ba0
No related branches found
No related tags found
1 merge request!17Get impletemented stages and Java 8
Pipeline #
......@@ -3,19 +3,19 @@ package kieker.analysis.graph.export.dot;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.function.Function;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.mapping.GraphMapper;
import kieker.analysis.graph.mapping.SimpleFileNameMapper;
public class DotFileWriterStage extends DotWriterStage {
public DotFileWriterStage(final GraphMapper<String> fileNameMapper) {
super(new GraphMapper<Writer>() {
public DotFileWriterStage(final Function<Graph, String> fileNameMapper) {
super(new Function<Graph, Writer>() {
@Override
public Writer map(final Graph graph) {
public Writer apply(final Graph graph) {
try {
return new FileWriter(fileNameMapper.map(graph));
return new FileWriter(fileNameMapper.apply(graph));
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
......
package kieker.analysis.graph.export.dot;
import java.io.Writer;
import java.util.function.Function;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.mapping.GraphMapper;
import teetime.framework.AbstractConsumerStage;
public class DotWriterStage extends AbstractConsumerStage<Graph> {
private final GraphMapper<Writer> writerMapper;
private final Function<Graph, Writer> writerMapper;
public DotWriterStage(final GraphMapper<Writer> writerMapper) {
public DotWriterStage(final Function<Graph, Writer> writerMapper) {
super();
this.writerMapper = writerMapper;
}
@Override
protected final void execute(final Graph graph) {
DotExporter dotExporter = new DotExporter(graph, writerMapper.map(graph));
DotExporter dotExporter = new DotExporter(graph, writerMapper.apply(graph));
dotExporter.transform();
}
......
......@@ -3,19 +3,19 @@ package kieker.analysis.graph.export.graphml;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.function.Function;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.mapping.GraphMapper;
import kieker.analysis.graph.mapping.SimpleFileNameMapper;
public class GraphMLFileWriterComposite extends GraphMLWriterComposite {
public GraphMLFileWriterComposite(final GraphMapper<String> fileNameMapper) {
super(new GraphMapper<OutputStream>() {
public GraphMLFileWriterComposite(final Function<Graph, String> fileNameMapper) {
super(new Function<Graph, OutputStream>() {
@Override
public OutputStream map(final Graph graph) {
public OutputStream apply(final Graph graph) {
try {
return new FileOutputStream(fileNameMapper.map(graph));
return new FileOutputStream(fileNameMapper.apply(graph));
} catch (FileNotFoundException e) {
throw new IllegalArgumentException(e);
}
......
package kieker.analysis.graph.export.graphml;
import java.io.OutputStream;
import java.util.function.Function;
import javax.xml.bind.JAXBElement;
......@@ -8,7 +9,6 @@ import org.graphdrawing.graphml.GraphmlType;
import org.graphdrawing.graphml.ObjectFactory;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.mapping.GraphMapper;
import kieker.analysis.util.JAXBMarshalElement;
import teetime.stage.basic.AbstractTransformation;
......@@ -16,9 +16,9 @@ import teetime.stage.basic.AbstractTransformation;
public class GraphMLTransformationStage extends AbstractTransformation<Graph, JAXBMarshalElement<GraphmlType>> {
private final ObjectFactory objectFactory = new ObjectFactory();
private final GraphMapper<OutputStream> outputStreamMapper;
private final Function<Graph, OutputStream> outputStreamMapper;
public GraphMLTransformationStage(final GraphMapper<OutputStream> outputStreamMapper) {
public GraphMLTransformationStage(final Function<Graph, OutputStream> outputStreamMapper) {
this.outputStreamMapper = outputStreamMapper;
}
......@@ -30,7 +30,7 @@ public class GraphMLTransformationStage extends AbstractTransformation<Graph, JA
graphmlType.getGraphOrData().add(graphTypeTransformer.transform());
final JAXBElement<GraphmlType> jaxbElement = objectFactory.createGraphml(graphmlType);
final OutputStream outputStream = outputStreamMapper.map(graph);
final OutputStream outputStream = outputStreamMapper.apply(graph);
final JAXBMarshalElement<GraphmlType> marshalElement = new JAXBMarshalElement<>(jaxbElement, outputStream);
this.getOutputPort().send(marshalElement);
......
package kieker.analysis.graph.export.graphml;
import java.io.OutputStream;
import java.util.function.Function;
import org.graphdrawing.graphml.GraphmlType;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.mapping.GraphMapper;
import kieker.analysis.util.JAXBMarshalStage;
import teetime.framework.CompositeStage;
......@@ -15,7 +15,7 @@ public class GraphMLWriterComposite extends CompositeStage {
private final InputPort<Graph> inputPort;
public GraphMLWriterComposite(final GraphMapper<OutputStream> outputStreamMapper) {
public GraphMLWriterComposite(final Function<Graph, OutputStream> outputStreamMapper) {
final GraphMLTransformationStage graphTypeTransformer;
final JAXBMarshalStage<GraphmlType> jaxbMarshaller;
......
package kieker.analysis.graph.mapping;
import kieker.analysis.graph.Graph;
import kieker.analysis.graph.util.IMapper;
public interface GraphMapper<O> extends IMapper<Graph, O> {
}
package kieker.analysis.graph.mapping;
import java.util.function.Function;
import kieker.analysis.graph.Graph;
/**
......@@ -9,7 +11,7 @@ import kieker.analysis.graph.Graph;
* @author Sören Henning
*
*/
public class SimpleFileNameMapper implements GraphMapper<String> {
public class SimpleFileNameMapper implements Function<Graph, String> {
private final String outputDirectory;
private final String fileExtension;
......@@ -20,7 +22,7 @@ public class SimpleFileNameMapper implements GraphMapper<String> {
}
@Override
public String map(final Graph graph) {
public String apply(final Graph graph) {
return outputDirectory + '/' + graph.getName() + '.' + fileExtension;
}
......
package kieker.analysis.graph.util;
public interface IMapper<I, O> {
public O map(I object);
}
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