From e7ab7dad676e6ccc3f0e654d46bfb42872d70c5d Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 16:45:00 +0100 Subject: [PATCH 01/13] 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 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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(); - } } } } From 5040958240f5deb1330ef7b9ec7dfcf6be8b60f1 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 21:49:39 +0100 Subject: [PATCH 07/13] added method invalidInput --- src/TextOutput.java | 7 +++++++ test/TextOutputTest.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 4b5c46e..c52739a 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -130,4 +130,11 @@ public class TextOutput { public void errorInvalidCommand() { System.err.println("Invalid Command"); } + + /** + * Method to give out the Error "Invalid Input". + */ + public void invalidInput() { + System.err.println("Invalid Input"); + } } diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java index 57bb624..17d72b9 100644 --- a/test/TextOutputTest.java +++ b/test/TextOutputTest.java @@ -17,7 +17,7 @@ class TextOutputTest { 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("1234"); text.add("12417575147517845 445264565"); text.add(" "); //text.add("1eeeeeee8597389751"); From 3e2bfbaf420247667927c0f9a1a8deb7783a3af0 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 21:55:45 +0100 Subject: [PATCH 08/13] removed method invalidInput --- src/TextOutput.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index c52739a..4b5c46e 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -130,11 +130,4 @@ public class TextOutput { public void errorInvalidCommand() { System.err.println("Invalid Command"); } - - /** - * Method to give out the Error "Invalid Input". - */ - public void invalidInput() { - System.err.println("Invalid Input"); - } } From 9874bf41297507c34137a2cb2910b55143291104 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 21:59:47 +0100 Subject: [PATCH 09/13] changed TextLogik.java error handling --- src/Text.java | 6 ------ src/TextLogik.java | 14 +++++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Text.java b/src/Text.java index 60c830c..0f9c165 100644 --- a/src/Text.java +++ b/src/Text.java @@ -25,9 +25,6 @@ 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; @@ -42,9 +39,6 @@ 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; } diff --git a/src/TextLogik.java b/src/TextLogik.java index a8682c8..9bd8f88 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -12,21 +12,25 @@ public class TextLogik { textOutput = new TextOutput(); String[] command; - textOutput.userInfoOutput("######################"); + textOutput.userInfoOutput("#######################"); textOutput.userInfoOutput("#WELCOME TO THE EDITOR#"); - textOutput.userInfoOutput("######################"); + textOutput.userInfoOutput("#######################"); do { textOutput.userInfoOutput("Please enter a Command: "); command = TextInput.checkForInput(); switch (command[0]) { case "ADD": - textOutput.userInfoOutput("Please enter your text: "); + String inputText = ""; + while(inputText.length() == 0) { + textOutput.userInfoOutput("Please enter your text: "); + inputText = TextInput.getTextInput(); + } if (command.length == 1) { - checkIfSuccess(text.add(TextInput.getTextInput())); + checkIfSuccess(text.add(inputText)); } else if (isNumeric(command[1])) { int line = Integer.parseInt(command[1]); - checkIfSuccess(text.add(line, TextInput.getTextInput())); + checkIfSuccess(text.add(line, inputText)); } else { textOutput.errorInvalidCommand(); } From fc2df137900297cfd49a96845ef80135e5321153 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 22:10:33 +0100 Subject: [PATCH 10/13] added error method missing text and implemented indexOutput and print to throw it when empty --- src/TextOutput.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 4b5c46e..2d32977 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -14,7 +14,10 @@ public class TextOutput { * @param text the ArrayList which is then formatted into the desired output. */ public void print(ArrayList text) { - if (formatRaw) { + if(text.size() == 0) { + errorMissingText(); + } + else if (formatRaw) { printFormated(text); } else { toFormat(text); @@ -112,8 +115,13 @@ public class TextOutput { * @param index ArrayList with words and in which part they have */ public void indexOutput(ArrayList index) { - for (String word : index) { - System.out.println(word); + if(index.size() == 0) { + errorMissingText(); + } + else { + for (String word : index) { + System.out.println(word); + } } } @@ -130,4 +138,11 @@ public class TextOutput { public void errorInvalidCommand() { System.err.println("Invalid Command"); } + + /** + * Method to give out the Error "Missing Text". + */ + public void errorMissingText() { + System.err.println("Missing Text"); + } } From d4b66010334f8d3d8d89d3ddaa237f9d1afe4d8e Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 22:19:52 +0100 Subject: [PATCH 11/13] implemented index is empty to index --- src/TextOutput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 2d32977..47c37bf 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -116,7 +116,7 @@ public class TextOutput { */ public void indexOutput(ArrayList index) { if(index.size() == 0) { - errorMissingText(); + System.out.println("index empty"); } else { for (String word : index) { From afd78900646b870c7e749ed717e01e7612a0a5d7 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Thu, 11 Nov 2021 22:20:44 +0100 Subject: [PATCH 12/13] implemented index is empty to index --- src/TextOutput.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 47c37bf..653e050 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -116,7 +116,7 @@ public class TextOutput { */ public void indexOutput(ArrayList index) { if(index.size() == 0) { - System.out.println("index empty"); + userInfoOutput("index empty"); } else { for (String word : index) { From dc798600e7c06f9fdbc30de6dd57c6ee3ca14d05 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 22:42:10 +0100 Subject: [PATCH 13/13] change in TextTest.java --- test/TextTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/TextTest.java b/test/TextTest.java index 8091360..376dc42 100644 --- a/test/TextTest.java +++ b/test/TextTest.java @@ -58,8 +58,11 @@ public class TextTest { Assertions.assertFalse(txt.replace(3, "alt", "neu")); Assertions.assertTrue(txt.replace(1, "erste", "zweite")); Assertions.assertTrue(txt.replace("zweite", "erste")); + Assertions.assertTrue(txt.add("Text Text hallo Text")); + Assertions.assertTrue(txt.replace("Text", "Test")); Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0)); Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1)); + Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2)); } /**