From 547db948935ac73134ee6fb5b88f3fde32d02394 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 12 Nov 2021 08:39:09 +0100 Subject: [PATCH 1/3] text java createwordlist method clean up --- src/Text.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Text.java b/src/Text.java index 0f9c165..33274b5 100644 --- a/src/Text.java +++ b/src/Text.java @@ -140,7 +140,7 @@ public class Text { */ public ArrayList index() { HashMap> wordbook = new HashMap<>(); - wordbook = createWordlist(wordbook); + createWordlist(wordbook); String input; ArrayList output = new ArrayList<>(); ArrayList values; @@ -168,7 +168,7 @@ public class Text { * * @return HashMap> */ - private HashMap> createWordlist(HashMap> wordbook) { + private void createWordlist(HashMap> wordbook) { int counter; ArrayList numbersList; String firstLetter; @@ -187,7 +187,6 @@ public class Text { counter = numbersList.get(0); numbersList.remove(0); numbersList.add(0, counter + 1); - if (numbersList.get(numbersList.size() - 1) < i + 1) { numbersList.add(i + 1); } @@ -199,7 +198,6 @@ public class Text { wordbook.put(word, numbersList); } } - return wordbook; } } From 8225111671a55be9a89fdb4bb6c8a852d6cb9d37 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 12 Nov 2021 08:50:03 +0100 Subject: [PATCH 2/3] added unique error message to invalid format length --- src/Text.java | 1 - src/TextLogik.java | 2 +- src/TextOutput.java | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Text.java b/src/Text.java index 33274b5..c1391da 100644 --- a/src/Text.java +++ b/src/Text.java @@ -166,7 +166,6 @@ public class Text { /** * This method counts all Words in text and adds the count together with the paragraph where the word is been used to a Hashmap. * - * @return HashMap> */ private void createWordlist(HashMap> wordbook) { int counter; diff --git a/src/TextLogik.java b/src/TextLogik.java index 9bd8f88..376ed96 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -62,7 +62,7 @@ public class TextLogik { if (command.length > 1 && "RAW".equals(command[1])) { checkIfSuccess(textOutput.formatRaw()); } else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) { - checkIfSuccess(textOutput.formatFix(Integer.parseInt(command[2]))); + textOutput.formatFix(Integer.parseInt(command[2])); } else { textOutput.errorInvalidCommand(); } diff --git a/src/TextOutput.java b/src/TextOutput.java index 653e050..0083d52 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -89,14 +89,14 @@ public class TextOutput { * @param length the paragraph length when printing the text. * @return returns true if successful and false if and invalid length has been submitted. */ - public boolean formatFix(int length) { + public void formatFix(int length) { if(length > 0) { formatRaw = false; columnWidth = length; - return true; + userInfoOutput("Command was successfull"); } else { - return false; + System.err.println("Minimum length has to be greater than 0"); } } From d3e26c61aac2913af52187e51b111759215a1cc4 Mon Sep 17 00:00:00 2001 From: amadoste Date: Fri, 12 Nov 2021 08:56:31 +0100 Subject: [PATCH 3/3] Corrections to Javadocs have been made. --- src/Text.java | 36 ++++++++++++++++++------------------ src/TextEditor.java | 4 ++++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Text.java b/src/Text.java index c1391da..21a3df7 100644 --- a/src/Text.java +++ b/src/Text.java @@ -8,10 +8,10 @@ public class Text { private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"; /** - * Method to check if a specific Paragraph exists + * Method to check if a specific paragraph exists. * - * @param paragraphNumber the number of the paragraph which should be checked - * @return returns true if the paragraph exists + * @param paragraphNumber the number of the paragraph which should be checked. + * @return returns true if the paragraph exists. */ private boolean paragraphExists(int paragraphNumber) { return ((paragraphNumber > 0) && (paragraphNumber <= this.text.size())); @@ -20,9 +20,9 @@ public class Text { /** * Method to add a paragraph at a specific position. * - * @param paragraphNumber number of paragraph where the new text should be added + * @param paragraphNumber number of paragraph where the new text should be added. * @param text the Text which should be added. - * @return returns true if the given paragraph exists and is added successfully + * @return returns true if the given paragraph exists and is added successfully. */ public boolean add(int paragraphNumber, String text) { if (paragraphExists(paragraphNumber)) { @@ -35,8 +35,8 @@ public class Text { /** * Method to add a paragraph at the end of the existing text. * - * @param text the Text which should be added. - * @return returns true if the paragraph is added successfully + * @param text the text which should be added. + * @return returns true if the paragraph is added successfully. */ public boolean add(String text) { this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]","")); @@ -46,7 +46,7 @@ public class Text { /** * Method to get all paragraph of the existing instance. * - * @return returns a ArrayList with all paragraphs inside. + * @return returns an ArrayList with all paragraphs inside. */ public ArrayList getText() { @@ -56,8 +56,8 @@ public class Text { /** * Method to add a dummy text paragraph at a specific position. * - * @param paragraphNumber number of paragraph where the dummy text should be added - * @return returns true if the given paragraph exists and is added successfully + * @param paragraphNumber number of paragraph where the dummy text should be added. + * @return returns true if the given paragraph exists and is added successfully. */ public boolean dummy(int paragraphNumber) { return add(paragraphNumber, dummyText); @@ -66,19 +66,19 @@ public class Text { /** * Method to add a dummy text paragraph at the end of the existing text. * - * @return returns true if the paragraph is added successfully + * @return returns true if the paragraph is added successfully. */ public boolean dummy() { return add(dummyText); } /** - * Method to replace characters in a specific paragraph + * Method to replace characters in a specific paragraph. * * @param paragraphNumber number of paragraph which should be changed. * @param oldChar the old character. * @param newChar the new character. - * @return returns true if the given paragraph exists and is changed successfully + * @return returns true if the given paragraph exists and is changed successfully. */ public boolean replace(int paragraphNumber, String oldChar, String newChar) { if (paragraphExists(paragraphNumber)) { @@ -96,7 +96,7 @@ public class Text { * @return returns true if the paragraph is changed successfully */ public boolean replace(String oldChar, String newChar) { - if(paragraphExists((text.size()))) { + if(paragraphExists(text.size())) { text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar)); return true; } @@ -104,8 +104,8 @@ public class Text { } /** - * This method deletes a specific Paragraph. As a Parameter it uses a int. - * If the Parameter is valid it deletes the specific Pararaph otherwise returns false + * This method deletes a specific paragraph. As a parameter it uses a int. + * If the parameter is valid it deletes the specific pararaph otherwise it will return false. * * @param paragraphNumber the Paragraph which should be deleted. * @return False: If the int is not a valid paragraph. || True: If the int is a valid paragraph number @@ -134,7 +134,7 @@ public class Text { /** * This method creates a ArrayList. * Every word which is used in the text more than 3 times - * will be added to the ArrayList with the paragraphes where the word is been used. + * will be added to the ArrayList with the paragraphs where the word has been used. * * @return ArrayList */ @@ -164,7 +164,7 @@ public class Text { } /** - * This method counts all Words in text and adds the count together with the paragraph where the word is been used to a Hashmap. + * This method counts all words in text and adds the count together with the paragraph where the word has been used to a Hashmap. * */ private void createWordlist(HashMap> wordbook) { diff --git a/src/TextEditor.java b/src/TextEditor.java index e9b9b48..9839adb 100644 --- a/src/TextEditor.java +++ b/src/TextEditor.java @@ -1,5 +1,9 @@ public class TextEditor { + /** + * Main Method that is connected to the TextLogik class. + * @param args there are no arguments needed. + */ public static void main(String[] args) { TextLogik t = new TextLogik();