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