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) {
 | 
				
			||||||
        for(String paragraph : text) {
 | 
					        int currentLength = 0;
 | 
				
			||||||
            if (paragraph.length() <= columnWidth) {
 | 
					        for (String paragraph : text) {
 | 
				
			||||||
                System.out.println(paragraph);
 | 
					            String[] words = paragraph.split(" ");
 | 
				
			||||||
            }
 | 
					            int lastwordNumber = words.length;
 | 
				
			||||||
            else {
 | 
					            int currentWordNumber = 0;
 | 
				
			||||||
                String[] word = paragraph.split(" ");
 | 
					            for(String word : words) {
 | 
				
			||||||
                int currentLineLength = 0;
 | 
					                currentWordNumber++;
 | 
				
			||||||
                for(String eachword : word) {
 | 
					                if (word.length()<= columnWidth - currentLength) {
 | 
				
			||||||
                    if (eachword.length() > columnWidth) {
 | 
					                    System.out.print(word);
 | 
				
			||||||
                        String remainingText = eachword;
 | 
					                    if (!(lastwordNumber == currentWordNumber)) {
 | 
				
			||||||
                        do {
 | 
					                        System.out.print(" ");
 | 
				
			||||||
                            if (remainingText.length() < columnWidth) {
 | 
					                        currentLength = currentLength + word.length() + 1;
 | 
				
			||||||
                                System.out.println(remainingText);
 | 
					 | 
				
			||||||
                                break;
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                            System.out.println(remainingText.substring(0, columnWidth));
 | 
					 | 
				
			||||||
                            remainingText = remainingText.substring((columnWidth));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        } while (!(remainingText.length() == 0));
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else {
 | 
					                    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 {
 | 
					 | 
				
			||||||
                            System.out.println(eachword);
 | 
					 | 
				
			||||||
                            currentLineLength = eachword.length();
 | 
					 | 
				
			||||||
                            if (!(currentLineLength == columnWidth)) {
 | 
					 | 
				
			||||||
                                System.out.print(" ");
 | 
					 | 
				
			||||||
                            }
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    System.out.println();
 | 
				
			||||||
 | 
					                    System.out.print(word);
 | 
				
			||||||
 | 
					                    if(!(currentWordNumber == lastwordNumber)) {
 | 
				
			||||||
 | 
					                        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