change in Method add in Text.java

This commit is contained in:
schrom01 2021-11-11 16:19:30 +01:00
parent 55fd84380b
commit 65af721a7a
1 changed files with 6 additions and 0 deletions

View File

@ -25,6 +25,9 @@ public class Text {
* @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) { public boolean add(int paragraphNumber, String text) {
if(text.length() < 1) {
return false;
}
if (paragraphExists(paragraphNumber)) { if (paragraphExists(paragraphNumber)) {
this.text.add((paragraphNumber - 1), text); this.text.add((paragraphNumber - 1), text);
return true; return true;
@ -39,6 +42,9 @@ public class Text {
* @return returns true if the paragraph is added successfully * @return returns true if the paragraph is added successfully
*/ */
public boolean add(String text) { public boolean add(String text) {
if(text.length() < 1) {
return false;
}
this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]","")); this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
return true; return true;
} }