Clean up Nodes.drawTree
This commit is contained in:
parent
bca3ace552
commit
ad81c90a47
1 changed files with 3 additions and 3 deletions
|
@ -127,20 +127,20 @@ public final class Nodes {
|
||||||
/**
|
/**
|
||||||
* Draw a representation of the tree.
|
* Draw a representation of the tree.
|
||||||
*
|
*
|
||||||
|
* @param node the root node to draw
|
||||||
* @param depth current depth for recursion
|
* @param depth current depth for recursion
|
||||||
|
* @param <T> the type of the node's content
|
||||||
* @return a representation of the tree
|
* @return a representation of the tree
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("movevariableinsideif")
|
|
||||||
public static <T> String drawTree(
|
public static <T> String drawTree(
|
||||||
final Node<T> node,
|
final Node<T> node,
|
||||||
final int depth
|
final int depth
|
||||||
) {
|
) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
final String unnamed = "(unnamed)";
|
|
||||||
if (node.isNamed()) {
|
if (node.isNamed()) {
|
||||||
sb.append(formatByDepth(node.getName(), depth));
|
sb.append(formatByDepth(node.getName(), depth));
|
||||||
} else if (!node.getChildren().isEmpty()) {
|
} else if (!node.getChildren().isEmpty()) {
|
||||||
sb.append(formatByDepth(unnamed, depth));
|
sb.append(formatByDepth("(unnamed)", depth));
|
||||||
}
|
}
|
||||||
node.getChildren().forEach(c -> sb.append(drawTree(c, depth + 1)));
|
node.getChildren().forEach(c -> sb.append(drawTree(c, depth + 1)));
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
Loading…
Reference in a new issue