changed TextLogik.java error handling
This commit is contained in:
parent
13cbaba268
commit
9874bf4129
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue