All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.spals.appbuilder.graph.writer.AsciiServiceGraphWriterPlugin Maven / Gradle / Ivy

package net.spals.appbuilder.graph.writer;

import com.github.mdr.ascii.graph.Graph;
import com.github.mdr.ascii.java.GraphBuilder;
import com.github.mdr.ascii.java.GraphLayouter;
import net.spals.appbuilder.graph.model.IServiceDAGVertex;
import net.spals.appbuilder.graph.model.IServiceGraphVertex;
import net.spals.appbuilder.graph.model.PrintableVertex;
import net.spals.appbuilder.graph.model.ServiceDAG;

import static net.spals.appbuilder.graph.model.PrintableVertex.createPrintableVertex;

/**
 * @author tkral
 */
class AsciiServiceGraphWriterPlugin implements ServiceGraphWriterPlugin, ServiceDAG> {

    @Override
    public String writeServiceGraph(final ServiceDAG serviceDAG) {
        final GraphBuilder asciiGraphBuilder = new GraphBuilder<>();
        // Add all the edges to the graph builder
        serviceDAG.edgeSet().forEach(edge -> {
            // Use newlines as the separator to make the graph more vertical
            final PrintableVertex edgeSource = createPrintableVertex(
                serviceDAG.getEdgeSource(edge), String.format("%n")
            );
            final PrintableVertex edgeTarget = createPrintableVertex(
                serviceDAG.getEdgeTarget(edge), String.format("%n")
            );
            asciiGraphBuilder.addEdge(edgeSource, edgeTarget);
        });

        final Graph asciiGraph = asciiGraphBuilder.build();
        final GraphLayouter asciiGraphLayouter = new GraphLayouter<>();
        asciiGraphLayouter.setVertical(false);

        return String.format("%n%s", asciiGraphLayouter.layout(asciiGraph));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy