Implemented functional ADD, FORMAT and PRINT feature. Reformat code in several files
This commit is contained in:
		
							parent
							
								
									5369a16497
								
							
						
					
					
						commit
						5d4b9114a0
					
				| 
						 | 
					@ -2,9 +2,13 @@ import java.util.Scanner;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class TextInput {
 | 
					public class TextInput {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final Scanner sc = new Scanner("");
 | 
					    private static final Scanner sc = new Scanner(System.in);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static String[] checkForInput() {
 | 
					    public static String[] checkForInput() {
 | 
				
			||||||
        return sc.nextLine().split("");
 | 
					        return sc.nextLine().split(" ");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static String getTextInput() {
 | 
				
			||||||
 | 
					        return sc.nextLine();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,9 +2,11 @@ import java.util.ArrayList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class TextLogik {
 | 
					public class TextLogik {
 | 
				
			||||||
    private final Text text;
 | 
					    private final Text text;
 | 
				
			||||||
 | 
					    private final TextOutput textOutput;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public TextLogik() {
 | 
					    public TextLogik() {
 | 
				
			||||||
        text = new Text();
 | 
					        text = new Text();
 | 
				
			||||||
 | 
					        textOutput = new TextOutput();
 | 
				
			||||||
        String[] command;
 | 
					        String[] command;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        do {
 | 
					        do {
 | 
				
			||||||
| 
						 | 
					@ -12,22 +14,43 @@ public class TextLogik {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            switch (command[0]) {
 | 
					            switch (command[0]) {
 | 
				
			||||||
                case "ADD":
 | 
					                case "ADD":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (command.length == 1) {
 | 
				
			||||||
 | 
					                        text.add(TextInput.getTextInput());
 | 
				
			||||||
 | 
					                    } else if (isNumeric(command[1])) {
 | 
				
			||||||
 | 
					                        int line = Integer.parseInt(command[1]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        text.add(line, TextInput.getTextInput());
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        textOutput.errorInvalidCommand();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "DEL":
 | 
					                case "DEL":
 | 
				
			||||||
 | 
					                    // TODO Hier Delete Funktion hinzufügen.
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "Dummy":
 | 
					                case "Dummy":
 | 
				
			||||||
                    text.dummy();
 | 
					                    text.dummy();
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "EXIT":
 | 
					                case "EXIT":
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "FORMAT RAW":
 | 
					                case "FORMAT":
 | 
				
			||||||
                    break;
 | 
					                    if (command.length > 1 && "RAW".equals(command[1])) {
 | 
				
			||||||
                case "FORMAT FIX":
 | 
					                        textOutput.formatRaw();
 | 
				
			||||||
 | 
					                    } else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) {
 | 
				
			||||||
 | 
					                        textOutput.formatFix(Integer.parseInt(command[2]));
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        textOutput.errorInvalidCommand();
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "INDEX":
 | 
					                case "INDEX":
 | 
				
			||||||
                    ArrayList<String> Index = text.index();
 | 
					                    ArrayList<String> Index = text.index();
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "PRINT":
 | 
					                case "PRINT":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    textOutput.print(text.getText());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "REPLACE":
 | 
					                case "REPLACE":
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
| 
						 | 
					@ -36,7 +59,11 @@ public class TextLogik {
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } while ("EXIT".equals(command[0]));
 | 
					        } while (!"EXIT".equals(command[0]));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean isNumeric(String str) {
 | 
				
			||||||
 | 
					        return str.matches("\\d+");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,8 +7,7 @@ public class TextOutput {
 | 
				
			||||||
    public void print(ArrayList<String> text) {
 | 
					    public void print(ArrayList<String> text) {
 | 
				
			||||||
        if (formatRaw) {
 | 
					        if (formatRaw) {
 | 
				
			||||||
            printFormated(text);
 | 
					            printFormated(text);
 | 
				
			||||||
        }
 | 
					        } else {
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            printUnformated(text);
 | 
					            printUnformated(text);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -19,6 +18,7 @@ public class TextOutput {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void printUnformated(ArrayList<String> text) {
 | 
					    private void printUnformated(ArrayList<String> text) {
 | 
				
			||||||
        for (String paragraph : text) {
 | 
					        for (String paragraph : text) {
 | 
				
			||||||
            String[] words = paragraph.split(" ");
 | 
					            String[] words = paragraph.split(" ");
 | 
				
			||||||
| 
						 | 
					@ -39,14 +39,13 @@ public class TextOutput {
 | 
				
			||||||
                                currentLength++;
 | 
					                                currentLength++;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                        if(!(letterLenght == 0)){
 | 
					                        if (!(letterLenght == 0)) {
 | 
				
			||||||
                            System.out.println();
 | 
					                            System.out.println();
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    while (letterLenght >= columnWidth);
 | 
					                    while (letterLenght >= columnWidth);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                }
 | 
					                } else {
 | 
				
			||||||
                else {
 | 
					 | 
				
			||||||
                    if (word.length() >= columnWidth - currentLength) {
 | 
					                    if (word.length() >= columnWidth - currentLength) {
 | 
				
			||||||
                        currentLength = 0;
 | 
					                        currentLength = 0;
 | 
				
			||||||
                        System.out.println();
 | 
					                        System.out.println();
 | 
				
			||||||
| 
						 | 
					@ -64,9 +63,10 @@ public class TextOutput {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void formatFix(int length) {
 | 
					    public void formatFix(int length) {
 | 
				
			||||||
    formatRaw = false;
 | 
					        formatRaw = false;
 | 
				
			||||||
    columnWidth = length;
 | 
					        columnWidth = length;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void errorInvalidString() {
 | 
					    public void errorInvalidString() {
 | 
				
			||||||
        System.err.println("Invalid String");
 | 
					        System.err.println("Invalid String");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,2 +0,0 @@
 | 
				
			||||||
public class SystemInputTest {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,2 +0,0 @@
 | 
				
			||||||
public class TextEditorTest {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TextInputTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void inputTest() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,18 +1,14 @@
 | 
				
			||||||
import org.junit.jupiter.api.BeforeEach;
 | 
					import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.junit.jupiter.api.Assertions.*;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class TextOutputTest {
 | 
					class TextOutputTest {
 | 
				
			||||||
    TextOutput textOutput;
 | 
					    TextOutput textOutput;
 | 
				
			||||||
    ArrayList<String> text;
 | 
					    ArrayList<String> text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @BeforeEach
 | 
					    @BeforeEach
 | 
				
			||||||
    public void setup(){
 | 
					    public void setup() {
 | 
				
			||||||
        textOutput = new TextOutput();
 | 
					        textOutput = new TextOutput();
 | 
				
			||||||
        textOutput.formatFix(9);
 | 
					        textOutput.formatFix(9);
 | 
				
			||||||
        textOutput.formatRaw();
 | 
					        textOutput.formatRaw();
 | 
				
			||||||
| 
						 | 
					@ -25,10 +21,7 @@ class TextOutputTest {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void print(){
 | 
					    public void print() {
 | 
				
			||||||
    textOutput.print(text);
 | 
					        textOutput.print(text);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue