From fae272844467b692e9b4464a32b138702261f58b Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 30 Oct 2021 15:15:43 +0200 Subject: [PATCH] added Method paragraphExists changes in Classdiagram --- src/Text.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Text.java b/src/Text.java index e16e82b..ff35eb0 100644 --- a/src/Text.java +++ b/src/Text.java @@ -25,6 +25,14 @@ public class Text { } } + /** + * Method to check if a specific Paragraph exists + * @param paragraphNumber to 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())); + } /** * Method to add a paragraph at a specific position. @@ -33,7 +41,7 @@ public class Text { * @return returns true if the given paragraph exists and is added successfully */ public boolean add(int paragraphNumber, String text) { - if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) { + if(paragraphExists(paragraphNumber)) { this.text.add((paragraphNumber - 1), text); return true; } @@ -75,7 +83,7 @@ public class Text { * @return returns true if the given paragraph exists and is changed successfully */ public boolean replace(int paragraphNumber, String oldChar, String newChar) { - if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) { + if(paragraphExists(paragraphNumber)) { text.set((paragraphNumber - 1), text.get(paragraphNumber - 1).replace(oldChar, newChar)); return true; } @@ -95,7 +103,7 @@ public class Text { public boolean del(int paragraphNumber) { - if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) { + if(paragraphExists(paragraphNumber)) { //paragraph hier löschen. return true; }