NodeItem: refactor formatting name by depth
Remove duplicate string literals.
This commit is contained in:
parent
b2130442e5
commit
2a435a849e
1 changed files with 6 additions and 5 deletions
|
@ -331,17 +331,18 @@ class NodeItem<T> implements Node<T> {
|
|||
final StringBuilder sb = new StringBuilder();
|
||||
final String unnamed = "(unnamed)";
|
||||
if (isNamed()) {
|
||||
sb.append(String.format("[%1$" + (depth + name.length()) + "s]\n",
|
||||
name));
|
||||
sb.append(formatByDepth(name, depth));
|
||||
} else if (!children.isEmpty()) {
|
||||
sb.append(
|
||||
String.format("[%1$" + (depth + unnamed.length()) + "s]\n",
|
||||
unnamed));
|
||||
sb.append(formatByDepth(unnamed, depth));
|
||||
}
|
||||
getChildren().stream().forEach(c -> sb.append(c.drawTree(depth + 1)));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String formatByDepth(final String value, final int depth) {
|
||||
return String.format("[%1$" + (depth + value.length()) + "s]\n", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNamed() {
|
||||
String currentName = getName();
|
||||
|
|
Loading…
Reference in a new issue