Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
MikeZyeman 2021-11-12 08:25:00 +01:00
commit 71006eb86d
6 changed files with 77 additions and 15 deletions

View File

@ -0,0 +1,46 @@
#Texteditor
Texteditor is a program to edit a text by in- and output into the console.
#Usermanual
#ADD a Textline
```ADD```
First please enter the command add to add a new textline. Then enter the text you want to add .
```ADD [n]```
If you want to add a textline to a certain paragraph then please use the command add and then enter that paragraphnummber.
After that enter the text you want to add to that paragraph.
#DUMMY Text
```DUMMY```
First please enter the command dummy to enter a pre written text into the textline.
```DUMMY [n]```
If you want to enter a pre written dummy text into a specific paragraph then please enter the command dummy and then the paragraph that you want to use.
#REPLACE a Text
```REPLACE```
First please enter the command replace then enter the characters that you want to replace. After that please enter
the new characters that should replace the old characters.
```REPLACE [n]```
If you want to replace a text from a certain paragraph, please enter the command replace and then enter the characters you want to
replace. After you entered the characters you want to replace please enter now the new characters that should replace the
old characters.
#DELETE a Text
```DEL```
First please enter the command del to delete a text. Then please enter the text size you want to delete.
```DEL [n]```
If you want to delete a text from a certain paragraph then please enter the command del and then the paragraph that you want to delete.
#INDEX
``ÌNDEX``
First please enter the command index to show the index.
#Print the Text
```PRINT```
First please enter the command print to print out the current text you have.
#FORMAT the Text
```FORMAT```

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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");
}
}

View File

@ -17,7 +17,7 @@ class TextOutputTest {
text.add("Virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, septentr ionesimmensoslongusw ordos.");
text.add("Virtutedasjdhashdkjhakjdhakdshjkashd praecedunt, quod fere cotidianis proeliis cum");
//text.add("ordos.");
//text.add("1234");
text.add("1234");
text.add("12417575147517845 445264565");
text.add(" ");
//text.add("1eeeeeee8597389751");

View File

@ -58,8 +58,11 @@ public class TextTest {
Assertions.assertFalse(txt.replace(3, "alt", "neu"));
Assertions.assertTrue(txt.replace(1, "erste", "zweite"));
Assertions.assertTrue(txt.replace("zweite", "erste"));
Assertions.assertTrue(txt.add("Text Text hallo Text"));
Assertions.assertTrue(txt.replace("Text", "Test"));
Assertions.assertEquals("Das ist der zweite Beispiel Text.", txt.getText().get(0));
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2));
}
/**