Skip to content

Commit 40e88b6

Browse files
author
Sascha Toennies
committed
last code embellishment
1 parent cd5195a commit 40e88b6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main/java/eu/toennies/javahttpobservatoryapi/HelpFormatter.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private Appendable renderWrappedTextBlock(StringBuffer sb, int width, int nextLi
306306
*
307307
* @return the StringBuffer with the rendered Options contents.
308308
*/
309-
protected StringBuffer renderWrappedText(StringBuffer sb, int width, final int nextLineTabStop, String text) {
309+
protected StringBuffer renderWrappedText(final StringBuffer sb, final int width, final int nextLineTabStop, final String text) {
310310
int pos = findWrapPos(text, width, 0);
311311

312312
if (pos == -1) {
@@ -328,21 +328,22 @@ protected StringBuffer renderWrappedText(StringBuffer sb, int width, final int n
328328
// characters
329329
final String padding = createPadding(currentNextLineTabStop);
330330

331+
String newText = text;
331332
while (true) {
332-
text = padding + text.substring(pos).trim();
333-
pos = findWrapPos(text, width, 0);
333+
newText = padding + newText.substring(pos).trim();
334+
pos = findWrapPos(newText, width, 0);
334335

335336
if (pos == -1) {
336-
sb.append(text);
337+
sb.append(newText);
337338

338339
return sb;
339340
}
340341

341-
if (text.length() > width && pos == currentNextLineTabStop - 1) {
342+
if (newText.length() > width && pos == currentNextLineTabStop - 1) {
342343
pos = width;
343344
}
344345

345-
sb.append(rtrim(text.substring(0, pos))).append(getNewLine());
346+
sb.append(rtrim(newText.substring(0, pos))).append(getNewLine());
346347
}
347348
}
348349

@@ -529,9 +530,10 @@ protected StringBuffer renderCommands(StringBuffer sb, int width, ApiCommands[]
529530
int max = 0;
530531

531532
List<StringBuffer> prefixList = new ArrayList<StringBuffer>();
533+
StringBuffer optBuf;
532534
for (ApiCommands cmds : commands) {
533535
ApiCommand command = cmds.getCommand();
534-
StringBuffer optBuf = new StringBuffer();
536+
optBuf = new StringBuffer();
535537

536538
optBuf.append(lpad).append(command.getConsoleShortCommand());
537539
optBuf.append(", ").append(command.getConsoleCommand());
@@ -546,9 +548,10 @@ protected StringBuffer renderCommands(StringBuffer sb, int width, ApiCommands[]
546548

547549
int x = 0;
548550

551+
StringBuilder opt2Buf;
549552
for (Iterator<ApiCommands> it = Arrays.asList(commands).iterator(); it.hasNext();) {
550553
ApiCommands option = it.next();
551-
StringBuilder opt2Buf = new StringBuilder(prefixList.get(x++).toString());
554+
opt2Buf = new StringBuilder(prefixList.get(x++).toString());
552555

553556
if (opt2Buf.length() < max) {
554557
opt2Buf.append(createPadding(max - opt2Buf.length()));

0 commit comments

Comments
 (0)