package com.github.ferstl.depgraph.graph.gml;

import java.util.Collection;
import com.github.ferstl.depgraph.graph.Edge;
import com.github.ferstl.depgraph.graph.GraphFormatter;
import com.github.ferstl.depgraph.graph.Node;

public class GmlGraphFormatter implements GraphFormatter {

  @Override
  public String format(String graphName, Collection<Node<?>> nodes, Collection<Edge> edges) {
    StringBuilder result = new StringBuilder();
    result.append("graph [\n");

    //output nodes
    for (Node<?> node : nodes) {
      result.append("node [\n");
      result.append("id \"").append(node.getNodeId()).append("\"\n");
      result.append("label \"").append(node.getNodeName()).append("\"\n");
      result.append("]\n\n");
    }

    //output edges
    for (Edge edge : edges) {
      result.append("edge [\n");
      result.append("source \"").append(edge.getFromNodeId()).append("\"\n");
      result.append("target \"").append(edge.getToNodeId()).append("\"\n");
      result.append("]\n\n");
    }

    result.append("]");
    return result.toString();
  }
}

@@ -44,37 +44,8 @@
 l;%0A%0A
-import java.util.Collection;%0A
 impo
@@ -86,16 +86,16 @@
 h.Edge;%0A
+
 import c
@@ -189,16 +189,110 @@
 .Node;%0A%0A
+import java.util.Collection;%0A%0Aimport static org.apache.commons.lang3.StringUtils.isNotBlank;%0A%0A
 public c
@@ -677,32 +677,78 @@
 append(%22%5C%22%5Cn%22);%0A
+      if (isNotBlank(node.getNodeName())) %7B%0A  
       result.app
@@ -798,32 +798,40 @@
 append(%22%5C%22%5Cn%22);%0A
+      %7D%0A
       result.app
@@ -1003,32 +1003,32 @@
 append(%22%5C%22%5Cn%22);%0A
-
       result.app
@@ -1079,32 +1079,153 @@
 append(%22%5C%22%5Cn%22);%0A
+      if (isNotBlank(edge.getName())) %7B%0A        result.append(%22label %5C%22%22).append(edge.getName()).append(%22%5C%22%5Cn%22);%0A      %7D%0A
       result.app

Add edge labels