From b236f20fc6996d51cb56599da4a19757602ac9b8 Mon Sep 17 00:00:00 2001 From: "piotr.suwala" Date: Wed, 17 Apr 2024 21:07:36 +0200 Subject: [PATCH] dependency less works with links --- .../kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt b/src/main/kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt index 8e5d4dd..d9bda93 100644 --- a/src/main/kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt +++ b/src/main/kotlin/sh/hsp/techtree/graphviz/DSLConverter.kt @@ -6,7 +6,7 @@ import java.util.stream.Collectors class DSLConverter { fun convert(model: TreeModel): String { - val nodesAsDSL = model.nodes.stream() + val nodesAsDSL = model.nodes.stream() .map { registerNode(it) } .collect(Collectors.joining(" ")) @@ -14,14 +14,12 @@ class DSLConverter { } private fun registerNode(node: TreeNode): String { - if (node.requires != null) { - val pathsToChildren = node.requires.stream() + val pathsToChildren = node.requires?.apply { + stream() .map { "${node.title.escaped()} -> ${it.escaped()}" } .collect(Collectors.joining(" ")) - return "${node.title.escaped()} ${node.link?.let { "[ href=\"$it\" fontcolor=blue]" } ?: ""} $pathsToChildren" - } - - return node.title.escaped() + } ?: listOf() + return "${node.title.escaped()} ${node.link?.let { "[ href=${it.escaped()} fontcolor=blue]" } ?: ""} $pathsToChildren" } private fun String.escaped(): String = "\"$this\""