Added JavaDocs, changed some formatting

This commit is contained in:
Leonardo Brandenberger 2021-11-09 20:54:54 +01:00
parent e96f492386
commit e2261dc2f4
2 changed files with 24 additions and 18 deletions

View File

@ -1,12 +1,15 @@
import java.util.ArrayList;
/**
*
*/
public class TextOutput {
private boolean formatRaw;
private int columnWidth = 10;
/**
* 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 calls the corresponding
* method to output the text as desired.
*
* @param text the ArrayList which is then formatted into the desired output.
*/
@ -30,12 +33,6 @@ public class TextOutput {
}
/**
* Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next
* paragraph.
*
* @param text the ArrayList which is used for the output.
*/
private void toFormatold(ArrayList<String> text) {
for (String paragraph : text) {
String[] words = paragraph.split(" ");
@ -73,17 +70,23 @@ public class TextOutput {
System.out.println(); //added
}
}
/**
* Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next
* paragraph.
*
* @param text the ArrayList which is used for the output.
*/
private void toFormat(ArrayList<String> text) {
int currentLength = 0;
for (String paragraph : text) {
String[] words = paragraph.split(" ");
int lastwordNumber = words.length;
int lastWordNumber = words.length;
int currentWordNumber = 0;
for(String word : words) {
currentWordNumber++;
if (word.length()<= columnWidth - currentLength) {
System.out.print(word);
if (!(lastwordNumber == currentWordNumber)) {
if (!(lastWordNumber == currentWordNumber)) {
System.out.print(" ");
currentLength = currentLength + word.length() + 1;
}
@ -94,7 +97,7 @@ public class TextOutput {
else {
System.out.println();
System.out.print(word);
if(!(currentWordNumber == lastwordNumber)) {
if(!(currentWordNumber == lastWordNumber)) {
System.out.print(" ");
currentLength = word.length();
}

View File

@ -1,6 +1,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
class TextOutputTest {
@ -10,15 +11,17 @@ class TextOutputTest {
@BeforeEach
public void setup() {
textOutput = new TextOutput();
textOutput.formatFix(9);
textOutput.formatFix(20);
//textOutput.formatRaw();
text = new ArrayList<>();
text.add("123456789");
text.add("1234");
text.add("12 12 12 12 12 12");
text.add(" ");
text.add("1eeeeeee8597389751");
text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText");
text.add("Virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, septentr ionesimmensoslongusw ordos.");
text.add("Virtutedasjdhashdkjhakjdhakdshjkashd praecedunt, quod fere cotidianis proeliis cum");
//text.add("ordos.");
//text.add("1234");
text.add("12417575147517845 445264565");
text.add(" ");
//text.add("1eeeeeee8597389751");
//text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText");
}
@Test