Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+9
-5
@@ -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();
|
||||
}
|
||||
|
||||
+18
-3
@@ -14,7 +14,10 @@ public class TextOutput {
|
||||
* @param text the ArrayList which is then formatted into the desired output.
|
||||
*/
|
||||
public void print(ArrayList<String> 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<String> index) {
|
||||
for (String word : index) {
|
||||
System.out.println(word);
|
||||
if(index.size() == 0) {
|
||||
userInfoOutput("index empty");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user