From 3d94eaeb32647c8360d4185809a15b6384220ed2 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 22 Aug 2016 09:01:34 +0100 Subject: [PATCH] AbstractNodeItem: refactor formatting name by depth Remove duplicate string literals. --- src/main/java/net/kemitix/node/AbstractNodeItem.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kemitix/node/AbstractNodeItem.java b/src/main/java/net/kemitix/node/AbstractNodeItem.java index 4815d93..f177c73 100644 --- a/src/main/java/net/kemitix/node/AbstractNodeItem.java +++ b/src/main/java/net/kemitix/node/AbstractNodeItem.java @@ -132,17 +132,18 @@ abstract class AbstractNodeItem implements Node { 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().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() { return name != null && name.length() > 0;