From d51da117519154c709c8540626c6dd35dd0e1caf Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 11 Nov 2021 15:28:41 +0100 Subject: [PATCH 01/12] TextLogik sync and Text updated --- src/Text.java | 4 ++-- src/TextLogik.java | 18 +++++++++++------- src/TextOutput.java | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Text.java b/src/Text.java index 108d703..902a39a 100644 --- a/src/Text.java +++ b/src/Text.java @@ -39,7 +39,7 @@ public class Text { * @return returns true if the paragraph is added successfully */ public boolean add(String text) { - this.text.add(text); + this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]","")); return true; } @@ -168,7 +168,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/TextLogik.java b/src/TextLogik.java index 38a6aea..8fd9f79 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,11 +68,10 @@ public class TextLogik { textOutput.IndexOutput(text.index()); break; case "PRINT": - textOutput.print(text.getText()); - break; case "REPLACE": + textOutput.UserInfoOutput("Please enter your text to replace: "); if (command.length == 1){ checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput())); }else if(isNumeric(command[1])) { @@ -98,7 +102,7 @@ public class TextLogik { private void checkIfSuccess(boolean method) { if(method) { - textOutput.UserInfoOutput("Command was successfully"); + textOutput.UserInfoOutput("Command was successfull"); }else { textOutput.errorInvalidParagraph(); } diff --git a/src/TextOutput.java b/src/TextOutput.java index c60cbbc..fe4dc90 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -103,6 +103,7 @@ public class TextOutput { } } } + System.out.println(); } } From 04647a5934a424b68267529b1d131a79e94b6f73 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 11 Nov 2021 15:33:58 +0100 Subject: [PATCH 02/12] TextLogik sync --- src/TextLogik.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TextLogik.java b/src/TextLogik.java index 8fd9f79..a1f84fa 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -12,16 +12,16 @@ public class TextLogik { textOutput = new TextOutput(); String[] command; - textOutput.UserInfoOutput("######################"); - textOutput.UserInfoOutput("#WELCOME TO THE EDITOR#"); - textOutput.UserInfoOutput("######################"); + textOutput.userInfoOutput("######################"); + textOutput.userInfoOutput("#WELCOME TO THE EDITOR#"); + textOutput.userInfoOutput("######################"); do { - textOutput.UserInfoOutput("Please enter a Command: "); + textOutput.userInfoOutput("Please enter a Command: "); command = TextInput.checkForInput(); switch (command[0]) { case "ADD": - textOutput.UserInfoOutput("Please enter your text: "); + textOutput.userInfoOutput("Please enter your text: "); if (command.length == 1) { checkIfSuccess(text.add(TextInput.getTextInput())); } else if (isNumeric(command[1])) { @@ -65,13 +65,13 @@ public class TextLogik { break; case "INDEX": - textOutput.IndexOutput(text.index()); + textOutput.indexOutput(text.index()); break; case "PRINT": textOutput.print(text.getText()); break; case "REPLACE": - textOutput.UserInfoOutput("Please enter your text to replace: "); + textOutput.userInfoOutput("Please enter your text to replace: "); if (command.length == 1){ checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput())); }else if(isNumeric(command[1])) { @@ -102,7 +102,7 @@ public class TextLogik { private void checkIfSuccess(boolean method) { if(method) { - textOutput.UserInfoOutput("Command was successfull"); + textOutput.userInfoOutput("Command was successfull"); }else { textOutput.errorInvalidParagraph(); } From ac8aa5d193df2ae3217d2bf71e307421498a6377 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 15:47:21 +0100 Subject: [PATCH 03/12] deleted unused method --- src/TextOutput.java | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 6a94a63..21c868d 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. From fd3c7a60a806a901a51261665be924e538c2c974 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 15:53:51 +0100 Subject: [PATCH 04/12] fixed bug in TextOutput.java --- src/TextOutput.java | 2 +- test/TextOutputTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 6a94a63..30f9337 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -99,7 +99,7 @@ public class TextOutput { System.out.print(word); if(!(currentWordNumber == lastWordNumber)) { System.out.print(" "); - currentLength = word.length(); + currentLength = word.length() + 1; } } } 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 From 7f524459fa19e43a58943c9ca63899fd0dbc8796 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 11 Nov 2021 16:15:05 +0100 Subject: [PATCH 05/12] =?UTF-8?q?ClassDiagram=20updated=20Rename=20=C3=84q?= =?UTF-8?q?uivalent=20to=20Equivalent.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/{Äquivalenzklassen.md => Equivalent.md} | 0 docs/PM2_ClassDiagram.drawio | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/{Äquivalenzklassen.md => Equivalent.md} (100%) 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..f8994f4 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 From 65af721a7a53fa6d39d23b94f26cb6dbde69ef8d Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 16:19:30 +0100 Subject: [PATCH 06/12] change in Method add in Text.java --- src/Text.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Text.java b/src/Text.java index 902a39a..a4e5f59 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,6 +42,9 @@ public class Text { * @return returns true if the paragraph is added successfully */ public boolean add(String text) { + if(text.length() < 1) { + return false; + } this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]","")); return true; } From e7ab7dad676e6ccc3f0e654d46bfb42872d70c5d Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 16:45:00 +0100 Subject: [PATCH 07/12] update in Classdiagramm --- docs/PM2_ClassDiagram.drawio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/PM2_ClassDiagram.drawio b/docs/PM2_ClassDiagram.drawio index f8994f4..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 From bc4dd38db4d0a2a79968befc43f79770db261225 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 11 Nov 2021 17:18:50 +0100 Subject: [PATCH 08/12] TextLogik remove duplicated code --- src/Text.java | 14 ++++++++++---- src/TextLogik.java | 22 ++++++++++++++-------- test/TextTest.java | 6 ++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Text.java b/src/Text.java index a4e5f59..60c830c 100644 --- a/src/Text.java +++ b/src/Text.java @@ -102,8 +102,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; } /** @@ -127,8 +130,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; } /** diff --git a/src/TextLogik.java b/src/TextLogik.java index a1f84fa..a8682c8 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -71,13 +71,19 @@ public class TextLogik { textOutput.print(text.getText()); break; case "REPLACE": - textOutput.userInfoOutput("Please enter your text to 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(); } @@ -101,9 +107,9 @@ public class TextLogik { } private void checkIfSuccess(boolean method) { - if(method) { + if (method) { textOutput.userInfoOutput("Command was successfull"); - }else { + } else { textOutput.errorInvalidParagraph(); } } 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(); + } } From 6a60150a19c4967afaee344d3e9ce1a123d3f09d Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 17:48:26 +0100 Subject: [PATCH 09/12] change in TextInput convert commands toUpperCase --- src/TextInput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() { From 94fa99d5b22ec150ba154f895486565c5f62a4d5 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 20:20:35 +0100 Subject: [PATCH 10/12] fix in TextOutput --- src/TextOutput.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 468bc31..06f863b 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -64,9 +64,11 @@ public class TextOutput { System.out.print(" "); currentLength = word.length() + 1; } + else { + System.out.println(); + } } } - System.out.println(); } } From 70920b794a6d02406406fdeb17cc24979b3f785b Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 20:35:41 +0100 Subject: [PATCH 11/12] fixed bugs in TextOutput.java --- src/TextOutput.java | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 06f863b..765ba5e 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -40,33 +40,25 @@ 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; - for(String word : words) { + for (String word : words) { currentWordNumber++; - if (word.length()<= columnWidth - currentLength) { + if (word.length() <= columnWidth - currentLength) { System.out.print(word); - if (!(lastWordNumber == currentWordNumber)) { - System.out.print(" "); - currentLength = currentLength + word.length() + 1; - } - else { - System.out.println(); - } - } - else { + } else { System.out.println(); + currentLength = 0; System.out.print(word); - if(!(currentWordNumber == lastWordNumber)) { - System.out.print(" "); - currentLength = word.length() + 1; - } - else { - System.out.println(); - } + } + if (!(currentWordNumber == lastWordNumber)) { + System.out.print(" "); + currentLength = currentLength + word.length() + 1; + } else { + System.out.println(); } } } @@ -90,12 +82,11 @@ public class TextOutput { * @return returns true if successful and false if and invalid length has been submitted. */ public boolean formatFix(int length) { - if(length > 0) { + if (length > 0) { formatRaw = false; columnWidth = length; return true; - } - else { + } else { return false; } } From bbc5a07f5385aa127fd6298c297e1772b30d0f95 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 20:58:45 +0100 Subject: [PATCH 12/12] fixed bugs in TextOutput.java --- src/TextOutput.java | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 06f863b..4b5c46e 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -40,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; @@ -49,24 +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() + 1; - } - else { - System.out.println(); - } } } }