fun toGml(graph: IDirectedGraph<*, out IGraphEdge<*>?>): String? { Preconditions.checkNotNull(graph, "Graph argument can not be null") val sb = StringBuilder() sb.append( """ graph [ """.trimIndent() ) var currentId = 0 val nodeMap: MutableMap<Any, Int> = HashMap() for (node in graph.getNodes()) {sb.append( """ node [ id """ ) sb.append(currentId) sb.append("\tlabel \"") sb.append(node) sb.append( """" ] """ ) nodeMap[node] = currentId ++currentId} for (edge in graph.getEdges()) {sb.append(""" edge[ source """) sb.append(nodeMap[edge.getSource()])sb.append("""target """ ) sb.append(nodeMap[edge.getTarget()]) sb.append( """ graphics [ fill "#000000" targetArrow "standard" ] ] """ ) } sb.append("]\n") return sb.toString() }
Creates GML code that represents a given directed graph .