Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
b190a8d161
|
@ -1,5 +1,4 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
|
|
||||||
public class TextOutput {
|
public class TextOutput {
|
||||||
|
@ -9,13 +8,13 @@ public class TextOutput {
|
||||||
/**
|
/**
|
||||||
* Method which checks in which way the paragraphs should be displayed. And then
|
* Method which checks in which way the paragraphs should be displayed. And then
|
||||||
*
|
*
|
||||||
* @param text the ArrayList which is then formated into the desired output.
|
* @param text the ArrayList which is then formatted into the desired output.
|
||||||
*/
|
*/
|
||||||
public void print(ArrayList<String> text) {
|
public void print(ArrayList<String> text) {
|
||||||
if (formatRaw) {
|
if (formatRaw) {
|
||||||
printFormated(text);
|
printFormated(text);
|
||||||
} else {
|
} else {
|
||||||
printUnformatedV2(text);
|
toFormat(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ public class TextOutput {
|
||||||
*
|
*
|
||||||
* @param text the ArrayList which is used for the output.
|
* @param text the ArrayList which is used for the output.
|
||||||
*/
|
*/
|
||||||
private void printUnformated(ArrayList<String> text) {
|
private void toFormatold(ArrayList<String> text) {
|
||||||
for (String paragraph : text) {
|
for (String paragraph : text) {
|
||||||
String[] words = paragraph.split(" ");
|
String[] words = paragraph.split(" ");
|
||||||
int currentLength = 0;
|
int currentLength = 0;
|
||||||
|
@ -74,54 +73,36 @@ public class TextOutput {
|
||||||
System.out.println(); //added
|
System.out.println(); //added
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void printUnformatedV2(ArrayList<String> text) {
|
private void toFormat(ArrayList<String> text) {
|
||||||
|
int currentLength = 0;
|
||||||
for (String paragraph : text) {
|
for (String paragraph : text) {
|
||||||
if (paragraph.length() <= columnWidth) {
|
String[] words = paragraph.split(" ");
|
||||||
System.out.println(paragraph);
|
int lastwordNumber = words.length;
|
||||||
|
int currentWordNumber = 0;
|
||||||
|
for(String word : words) {
|
||||||
|
currentWordNumber++;
|
||||||
|
if (word.length()<= columnWidth - currentLength) {
|
||||||
|
System.out.print(word);
|
||||||
|
if (!(lastwordNumber == currentWordNumber)) {
|
||||||
|
System.out.print(" ");
|
||||||
|
currentLength = currentLength + word.length() + 1;
|
||||||
}
|
}
|
||||||
else {
|
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();
|
System.out.println();
|
||||||
}
|
}
|
||||||
if (columnWidth > eachword.length()) {
|
|
||||||
System.out.print(eachword);
|
|
||||||
if (!(currentLineLength == columnWidth)) {
|
|
||||||
System.out.print(" ");
|
|
||||||
}
|
|
||||||
currentLineLength = currentLineLength + eachword.length();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
System.out.println(eachword);
|
System.out.println();
|
||||||
currentLineLength = eachword.length();
|
System.out.print(word);
|
||||||
if (!(currentLineLength == columnWidth)) {
|
if(!(currentWordNumber == lastwordNumber)) {
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
|
currentLength = word.length();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Method which sets the Variable formatRaw to true.
|
* Method which sets the Variable formatRaw to true.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue