diff --git a/docs/Ă„quivalenzklassen.md b/docs/Equivalent.md
similarity index 100%
rename from docs/Ă„quivalenzklassen.md
rename to docs/Equivalent.md
diff --git a/docs/PM2_ClassDiagram.drawio b/docs/PM2_ClassDiagram.drawio
index f552812..3c57fb8 100644
--- a/docs/PM2_ClassDiagram.drawio
+++ b/docs/PM2_ClassDiagram.drawio
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/Text.java b/src/Text.java
index 752b9f3..f0dd6b5 100644
--- a/src/Text.java
+++ b/src/Text.java
@@ -25,6 +25,9 @@ public class Text {
* @return returns true if the given paragraph exists and is added successfully
*/
public boolean add(int paragraphNumber, String text) {
+ if(text.length() < 1) {
+ return false;
+ }
if (paragraphExists(paragraphNumber)) {
this.text.add((paragraphNumber - 1), text);
return true;
@@ -39,7 +42,10 @@ public class Text {
* @return returns true if the paragraph is added successfully
*/
public boolean add(String text) {
- this.text.add(text);
+ if(text.length() < 1) {
+ return false;
+ }
+ this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
return true;
}
@@ -95,8 +101,11 @@ public class Text {
* @return returns true if the paragraph is changed successfully
*/
public boolean replace(String oldChar, String newChar) {
- text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
- return true;
+ if(paragraphExists((text.size()))) {
+ text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
+ return true;
+ }
+ return false;
}
/**
@@ -120,8 +129,11 @@ public class Text {
* @return True: if paragraph has been deleted.
*/
public boolean del() {
- text.remove(text.size() - 1);
- return true;
+ if(paragraphExists(text.size())){
+ text.remove(text.size() - 1);
+ return true;
+ }
+ return false;
}
/**
@@ -167,7 +179,7 @@ public class Text {
String firstLetter;
String restLetters;
for (int i = 0; i < text.size(); i++) {
- String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/\n]+");
+ String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><+*}{)('/\n]+");
for (String word : words) {
//Words get formatted consistently
counter = 1;
diff --git a/src/TextInput.java b/src/TextInput.java
index d4abab5..f7f68d9 100644
--- a/src/TextInput.java
+++ b/src/TextInput.java
@@ -5,7 +5,7 @@ public class TextInput {
private static final Scanner sc = new Scanner(System.in);
public static String[] checkForInput() {
- return sc.nextLine().split(" ");
+ return sc.nextLine().toUpperCase().split(" ");
}
public static String getTextInput() {
diff --git a/src/TextLogik.java b/src/TextLogik.java
index a6123d8..a8682c8 100644
--- a/src/TextLogik.java
+++ b/src/TextLogik.java
@@ -12,11 +12,16 @@ public class TextLogik {
textOutput = new TextOutput();
String[] command;
+ textOutput.userInfoOutput("######################");
+ textOutput.userInfoOutput("#WELCOME TO THE EDITOR#");
+ textOutput.userInfoOutput("######################");
do {
+ textOutput.userInfoOutput("Please enter a Command: ");
command = TextInput.checkForInput();
switch (command[0]) {
case "ADD":
+ textOutput.userInfoOutput("Please enter your text: ");
if (command.length == 1) {
checkIfSuccess(text.add(TextInput.getTextInput()));
} else if (isNumeric(command[1])) {
@@ -29,10 +34,10 @@ public class TextLogik {
break;
case "DEL":
if (command.length == 1) {
- text.del();
+ checkIfSuccess(text.del());
} else if (isNumeric(command[1])) {
int line = Integer.parseInt(command[1]);
- text.del(line);
+ checkIfSuccess(text.del(line));
} else {
textOutput.errorInvalidCommand();
}
@@ -51,9 +56,9 @@ public class TextLogik {
break;
case "FORMAT":
if (command.length > 1 && "RAW".equals(command[1])) {
- textOutput.formatRaw();
+ checkIfSuccess(textOutput.formatRaw());
} else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) {
- textOutput.formatFix(Integer.parseInt(command[2]));
+ checkIfSuccess(textOutput.formatFix(Integer.parseInt(command[2])));
} else {
textOutput.errorInvalidCommand();
}
@@ -63,17 +68,22 @@ public class TextLogik {
textOutput.indexOutput(text.index());
break;
case "PRINT":
-
textOutput.print(text.getText());
-
break;
case "REPLACE":
- if (command.length == 1){
- checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput()));
- }else if(isNumeric(command[1])) {
+ String oldChar = "";
+ while (oldChar.length() == 0) {
+ textOutput.userInfoOutput("Please enter your text to replace: ");
+ oldChar = TextInput.getTextInput();
+ }
+ textOutput.userInfoOutput("Please enter the new text: ");
+ String newChar = TextInput.getTextInput();
+ if (command.length == 1) {
+ checkIfSuccess(text.replace(oldChar, newChar));
+ } else if (isNumeric(command[1])) {
int line = Integer.parseInt(command[1]);
- checkIfSuccess(text.replace(line, TextInput.getTextInput(), TextInput.getTextInput()));
- }else {
+ checkIfSuccess(text.replace(line, oldChar, newChar));
+ } else {
textOutput.errorInvalidCommand();
}
@@ -97,9 +107,9 @@ public class TextLogik {
}
private void checkIfSuccess(boolean method) {
- if(method) {
- textOutput.userInfoOutput("Command was successfully");
- }else {
+ if (method) {
+ textOutput.userInfoOutput("Command was successfull");
+ } else {
textOutput.errorInvalidParagraph();
}
}
diff --git a/src/TextOutput.java b/src/TextOutput.java
index 890794d..4b5c46e 100644
--- a/src/TextOutput.java
+++ b/src/TextOutput.java
@@ -33,43 +33,6 @@ public class TextOutput {
}
- private void toFormatold(ArrayList text) {
- for (String paragraph : text) {
- String[] words = paragraph.split(" ");
- int currentLength = 0;
- for (String word : words) {
- if (word.length() > columnWidth) {
- String[] letters = word.split("");
- int letterLenght = letters.length;
- int lettersPrinted = 0;
- do {
- currentLength = 0;
- for (int i = 0; i < columnWidth; i++) {
- if (letterLenght > 0) {
- System.out.print(letters[lettersPrinted]);
- letterLenght--;
- lettersPrinted++;
- currentLength++;
- }
- }
- if (!(letterLenght == 0)) {
- System.out.println();
- }
- }
- while (letterLenght >= columnWidth);
-
- } else {
- if (word.length() >= columnWidth - currentLength) {
- currentLength = 0;
- System.out.println();
- }
- System.out.print(word + " ");
- currentLength += word.length() + 1;
- }
- }
- System.out.println(); //added
- }
- }
/**
* Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next
* paragraph.
@@ -77,8 +40,8 @@ public class TextOutput {
* @param text the ArrayList which is used for the output.
*/
private void toFormat(ArrayList text) {
- int currentLength = 0;
for (String paragraph : text) {
+ int currentLength = 0;
String[] words = paragraph.split(" ");
int lastWordNumber = words.length;
int currentWordNumber = 0;
@@ -86,21 +49,21 @@ public class TextOutput {
currentWordNumber++;
if (word.length()<= columnWidth - currentLength) {
System.out.print(word);
- if (!(lastWordNumber == currentWordNumber)) {
- System.out.print(" ");
- currentLength = currentLength + word.length() + 1;
- }
- else {
+ }
+ else {
+ if(currentWordNumber != 1) {
System.out.println();
- }
+ currentLength = 0;
+ }
+ System.out.print(word);
+
+ }
+ if(!(currentWordNumber == lastWordNumber)) {
+ System.out.print(" ");
+ currentLength = currentLength + word.length() + 1;
}
else {
System.out.println();
- System.out.print(word);
- if(!(currentWordNumber == lastWordNumber)) {
- System.out.print(" ");
- currentLength = word.length();
- }
}
}
}
diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java
index 7aa6658..57bb624 100644
--- a/test/TextOutputTest.java
+++ b/test/TextOutputTest.java
@@ -27,5 +27,9 @@ class TextOutputTest {
@Test
public void print() {
textOutput.print(text);
+ System.out.println("fertig");
+ textOutput.formatRaw();
+ textOutput.print(text);
+ System.out.println("fertig");
}
}
\ No newline at end of file
diff --git a/test/TextTest.java b/test/TextTest.java
index 9818d55..8091360 100644
--- a/test/TextTest.java
+++ b/test/TextTest.java
@@ -92,4 +92,10 @@ public class TextTest {
stringListe = txt.index();
Assertions.assertEquals(0,stringListe.size());
}
+
+ @Test
+ void testing() {
+ txt.add("");
+ txt.index();
+ }
}