public static String toGml(final IDirectedGraph<?,? extends IGraphEdge<?>> graph){
  Preconditions.checkNotNull(graph,"Graph argument can not be null");
  final StringBuilder sb=new StringBuilder();
  sb.append("graph\n" + "[\n");
  int currentId=0;
  final Map<Object,Integer> nodeMap=new HashMap<>();
  for (  final Object node : graph.getNodes()) {
    sb.append("\tnode\n" + "\t[\n" + "\tid "+ "\n");
    sb.append(currentId);
    sb.append("\tlabel \"");
    sb.append(node);
    sb.append("\"\n" + "\t]\n");
    nodeMap.put(node,currentId);
    ++currentId;
  }
  for (  final IGraphEdge<?> edge : graph.getEdges()) {
    sb.append("\tedge\n" + "\t[\n" + "\tsource ");
    sb.append(nodeMap.get(edge.getSource()));
    sb.append("\n" + "\ttarget ");
    sb.append(nodeMap.get(edge.getTarget()));
    sb.append("\n" + "\tgraphics\n" + "\t[\n"+ "\t\tfill \"#000000\"\n"+ "\t\ttargetArrow \"standard\"\n"+ "\t]\n"+ "\t]\n");
  }
  sb.append("]\n");
  return sb.toString();
}

public static String toGml ( final IDirectedGraph < ? , ? extends IGraphEdge < ? > > graph ) { Preconditions . checkNotNull ( graph , "Graph argument can not be null" ) ; final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "graph\n" + "[\n" ) ; int currentId = 0 ; final Map < Object , Integer > nodeMap = new HashMap < > ( ) ; for ( final Object node : graph . getNodes ( ) ) { sb . append ( "\tnode\n" + "\t[\n" + "\tid " + "\n" ) ; sb . append ( currentId ) ; sb . append ( "\tlabel \"" ) ; sb . append ( node ) ; sb . append ( "\"\n" + "\t]\n" ) ; nodeMap . put ( node , currentId ) ; ++ currentId ; } for ( final IGraphEdge < ? > edge : graph . getEdges ( ) ) { sb . append ( "\tedge\n" + "\t[\n" + "\tsource " ) ; sb . append ( nodeMap . get ( edge . getSource ( ) ) ) ; sb . append ( "\n" + "\ttarget " ) ; sb . append ( nodeMap . get ( edge . getTarget ( ) ) ) ; sb . append ( "\n" + "\tgraphics\n" + "\t[\n" + "\t\tfill \"#000000\"\n" + "\t\ttargetArrow \"standard\"\n" + "\t]\n" + "\t]\n" ) ; } sb . append ( "]\n" ) ; return sb . toString ( ) ; }
creates gml code that represents a given directed graph .
