From e96f492386fb920f023902467fd9c0170508b1b9 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Tue, 9 Nov 2021 17:06:46 +0100 Subject: [PATCH] removed old toFormat Method --- src/TextOutput.java | 79 +++------------------------------------------ 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 9423199..91fde26 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -14,7 +14,7 @@ public class TextOutput { if (formatRaw) { printFormated(text); } else { - toFormat4(text); + toFormat(text); } } @@ -29,25 +29,6 @@ public class TextOutput { } } - private void toFormat2(ArrayList text) { - for (String para : text) { - String[] words = para.split(" "); - String output = ""; - for (String word : words) { - if ((output.length() + word.length()) < columnWidth) { - output += "word "; - } else { - if (word.length() <= columnWidth) { - System.out.println(output); - output = ""; - } else { - System.out.println(word.substring(0, columnWidth) );//+ "-"); - output = word.substring(columnWidth); - } - } - } - } - } /** * Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next @@ -55,7 +36,7 @@ public class TextOutput { * * @param text the ArrayList which is used for the output. */ - private void toFormat(ArrayList text) { + private void toFormatold(ArrayList text) { for (String paragraph : text) { String[] words = paragraph.split(" "); int currentLength = 0; @@ -92,7 +73,7 @@ public class TextOutput { System.out.println(); //added } } - private void toFormat4(ArrayList text) { + private void toFormat(ArrayList text) { int currentLength = 0; for (String paragraph : text) { String[] words = paragraph.split(" "); @@ -109,15 +90,11 @@ public class TextOutput { else { System.out.println(); } - } else { System.out.println(); System.out.print(word); - if(currentWordNumber == lastwordNumber) { - //System.out.println(); - } - else { + if(!(currentWordNumber == lastwordNumber)) { System.out.print(" "); currentLength = word.length(); } @@ -126,54 +103,6 @@ public class TextOutput { } } - private void toFormat3(ArrayList text) { - for(String paragraph : text) { - if (paragraph.length() <= columnWidth) { - System.out.println(paragraph); - } - else { - String[] word = paragraph.split(" "); - int currentLineLength = 0; - for(String eachword : word) { - if (eachword.length() > columnWidth) { - String remainingText = eachword; - do { - if (remainingText.length() < columnWidth) { - System.out.println(remainingText); - break; - } - System.out.println(remainingText.substring(0, columnWidth)); - remainingText = remainingText.substring((columnWidth)); - - } while (!(remainingText.length() == 0)); - } - else { - if (currentLineLength == 0) { - System.out.println(); - } - if (columnWidth > eachword.length()) { - System.out.print(eachword); - if (!(currentLineLength == columnWidth)) { - System.out.print(" "); - } - currentLineLength = currentLineLength + eachword.length(); - } - else { - System.out.println(eachword); - currentLineLength = eachword.length(); - if (!(currentLineLength == columnWidth)) { - System.out.print(" "); - } - } - - - } - - } - - } - } - } /** * Method which sets the Variable formatRaw to true. */