Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
6ecda2c63c
File diff suppressed because one or more lines are too long
|
@ -25,9 +25,6 @@ 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;
|
||||||
|
@ -42,9 +39,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -102,9 +96,12 @@ public class Text {
|
||||||
* @return returns true if the paragraph is changed successfully
|
* @return returns true if the paragraph is changed successfully
|
||||||
*/
|
*/
|
||||||
public boolean replace(String oldChar, String newChar) {
|
public boolean replace(String oldChar, String newChar) {
|
||||||
|
if(paragraphExists((text.size()))) {
|
||||||
text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
|
text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method deletes a specific Paragraph. As a Parameter it uses a int.
|
* This method deletes a specific Paragraph. As a Parameter it uses a int.
|
||||||
|
@ -127,9 +124,12 @@ public class Text {
|
||||||
* @return True: if paragraph has been deleted.
|
* @return True: if paragraph has been deleted.
|
||||||
*/
|
*/
|
||||||
public boolean del() {
|
public boolean del() {
|
||||||
|
if(paragraphExists(text.size())){
|
||||||
text.remove(text.size() - 1);
|
text.remove(text.size() - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates a ArrayList<String>.
|
* This method creates a ArrayList<String>.
|
||||||
|
|
|
@ -5,7 +5,7 @@ public class TextInput {
|
||||||
private static final Scanner sc = new Scanner(System.in);
|
private static final Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public static String[] checkForInput() {
|
public static String[] checkForInput() {
|
||||||
return sc.nextLine().split(" ");
|
return sc.nextLine().toUpperCase().split(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTextInput() {
|
public static String getTextInput() {
|
||||||
|
|
|
@ -12,21 +12,25 @@ public class TextLogik {
|
||||||
textOutput = new TextOutput();
|
textOutput = new TextOutput();
|
||||||
String[] command;
|
String[] command;
|
||||||
|
|
||||||
textOutput.userInfoOutput("######################");
|
textOutput.userInfoOutput("#######################");
|
||||||
textOutput.userInfoOutput("#WELCOME TO THE EDITOR#");
|
textOutput.userInfoOutput("#WELCOME TO THE EDITOR#");
|
||||||
textOutput.userInfoOutput("######################");
|
textOutput.userInfoOutput("#######################");
|
||||||
do {
|
do {
|
||||||
textOutput.userInfoOutput("Please enter a Command: ");
|
textOutput.userInfoOutput("Please enter a Command: ");
|
||||||
command = TextInput.checkForInput();
|
command = TextInput.checkForInput();
|
||||||
|
|
||||||
switch (command[0]) {
|
switch (command[0]) {
|
||||||
case "ADD":
|
case "ADD":
|
||||||
|
String inputText = "";
|
||||||
|
while(inputText.length() == 0) {
|
||||||
textOutput.userInfoOutput("Please enter your text: ");
|
textOutput.userInfoOutput("Please enter your text: ");
|
||||||
|
inputText = TextInput.getTextInput();
|
||||||
|
}
|
||||||
if (command.length == 1) {
|
if (command.length == 1) {
|
||||||
checkIfSuccess(text.add(TextInput.getTextInput()));
|
checkIfSuccess(text.add(inputText));
|
||||||
} else if (isNumeric(command[1])) {
|
} else if (isNumeric(command[1])) {
|
||||||
int line = Integer.parseInt(command[1]);
|
int line = Integer.parseInt(command[1]);
|
||||||
checkIfSuccess(text.add(line, TextInput.getTextInput()));
|
checkIfSuccess(text.add(line, inputText));
|
||||||
} else {
|
} else {
|
||||||
textOutput.errorInvalidCommand();
|
textOutput.errorInvalidCommand();
|
||||||
}
|
}
|
||||||
|
@ -71,13 +75,19 @@ public class TextLogik {
|
||||||
textOutput.print(text.getText());
|
textOutput.print(text.getText());
|
||||||
break;
|
break;
|
||||||
case "REPLACE":
|
case "REPLACE":
|
||||||
|
String oldChar = "";
|
||||||
|
while (oldChar.length() == 0) {
|
||||||
textOutput.userInfoOutput("Please enter your text to replace: ");
|
textOutput.userInfoOutput("Please enter your text to replace: ");
|
||||||
if (command.length == 1){
|
oldChar = TextInput.getTextInput();
|
||||||
checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput()));
|
}
|
||||||
}else if(isNumeric(command[1])) {
|
textOutput.userInfoOutput("Please enter the new text: ");
|
||||||
|
String newChar = TextInput.getTextInput();
|
||||||
|
if (command.length == 1) {
|
||||||
|
checkIfSuccess(text.replace(oldChar, newChar));
|
||||||
|
} else if (isNumeric(command[1])) {
|
||||||
int line = Integer.parseInt(command[1]);
|
int line = Integer.parseInt(command[1]);
|
||||||
checkIfSuccess(text.replace(line, TextInput.getTextInput(), TextInput.getTextInput()));
|
checkIfSuccess(text.replace(line, oldChar, newChar));
|
||||||
}else {
|
} else {
|
||||||
textOutput.errorInvalidCommand();
|
textOutput.errorInvalidCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,9 +111,9 @@ public class TextLogik {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkIfSuccess(boolean method) {
|
private void checkIfSuccess(boolean method) {
|
||||||
if(method) {
|
if (method) {
|
||||||
textOutput.userInfoOutput("Command was successfull");
|
textOutput.userInfoOutput("Command was successfull");
|
||||||
}else {
|
} else {
|
||||||
textOutput.errorInvalidParagraph();
|
textOutput.errorInvalidParagraph();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,10 @@ public class TextOutput {
|
||||||
* @param text the ArrayList which is then formatted into the desired output.
|
* @param text the ArrayList which is then formatted into the desired output.
|
||||||
*/
|
*/
|
||||||
public void print(ArrayList<String> text) {
|
public void print(ArrayList<String> text) {
|
||||||
if (formatRaw) {
|
if(text.size() == 0) {
|
||||||
|
errorMissingText();
|
||||||
|
}
|
||||||
|
else if (formatRaw) {
|
||||||
printFormated(text);
|
printFormated(text);
|
||||||
} else {
|
} else {
|
||||||
toFormat(text);
|
toFormat(text);
|
||||||
|
@ -40,8 +43,8 @@ public class TextOutput {
|
||||||
* @param text the ArrayList which is used for the output.
|
* @param text the ArrayList which is used for the output.
|
||||||
*/
|
*/
|
||||||
private void toFormat(ArrayList<String> text) {
|
private void toFormat(ArrayList<String> text) {
|
||||||
int currentLength = 0;
|
|
||||||
for (String paragraph : text) {
|
for (String paragraph : text) {
|
||||||
|
int currentLength = 0;
|
||||||
String[] words = paragraph.split(" ");
|
String[] words = paragraph.split(" ");
|
||||||
int lastWordNumber = words.length;
|
int lastWordNumber = words.length;
|
||||||
int currentWordNumber = 0;
|
int currentWordNumber = 0;
|
||||||
|
@ -49,7 +52,16 @@ public class TextOutput {
|
||||||
currentWordNumber++;
|
currentWordNumber++;
|
||||||
if (word.length()<= columnWidth - currentLength) {
|
if (word.length()<= columnWidth - currentLength) {
|
||||||
System.out.print(word);
|
System.out.print(word);
|
||||||
if (!(lastWordNumber == currentWordNumber)) {
|
}
|
||||||
|
else {
|
||||||
|
if(currentWordNumber != 1) {
|
||||||
|
System.out.println();
|
||||||
|
currentLength = 0;
|
||||||
|
}
|
||||||
|
System.out.print(word);
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!(currentWordNumber == lastWordNumber)) {
|
||||||
System.out.print(" ");
|
System.out.print(" ");
|
||||||
currentLength = currentLength + word.length() + 1;
|
currentLength = currentLength + word.length() + 1;
|
||||||
}
|
}
|
||||||
|
@ -57,16 +69,6 @@ public class TextOutput {
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
System.out.println();
|
|
||||||
System.out.print(word);
|
|
||||||
if(!(currentWordNumber == lastWordNumber)) {
|
|
||||||
System.out.print(" ");
|
|
||||||
currentLength = word.length() + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,10 +115,15 @@ public class TextOutput {
|
||||||
* @param index ArrayList with words and in which part they have
|
* @param index ArrayList with words and in which part they have
|
||||||
*/
|
*/
|
||||||
public void indexOutput(ArrayList<String> index) {
|
public void indexOutput(ArrayList<String> index) {
|
||||||
|
if(index.size() == 0) {
|
||||||
|
userInfoOutput("index empty");
|
||||||
|
}
|
||||||
|
else {
|
||||||
for (String word : index) {
|
for (String word : index) {
|
||||||
System.out.println(word);
|
System.out.println(word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to give out the Error "Invalid Paragraph".
|
* Method to give out the Error "Invalid Paragraph".
|
||||||
|
@ -131,4 +138,11 @@ public class TextOutput {
|
||||||
public void errorInvalidCommand() {
|
public void errorInvalidCommand() {
|
||||||
System.err.println("Invalid Command");
|
System.err.println("Invalid Command");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to give out the Error "Missing Text".
|
||||||
|
*/
|
||||||
|
public void errorMissingText() {
|
||||||
|
System.err.println("Missing Text");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class TextOutputTest {
|
||||||
text.add("Virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, septentr ionesimmensoslongusw ordos.");
|
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("Virtutedasjdhashdkjhakjdhakdshjkashd praecedunt, quod fere cotidianis proeliis cum");
|
||||||
//text.add("ordos.");
|
//text.add("ordos.");
|
||||||
//text.add("1234");
|
text.add("1234");
|
||||||
text.add("12417575147517845 445264565");
|
text.add("12417575147517845 445264565");
|
||||||
text.add(" ");
|
text.add(" ");
|
||||||
//text.add("1eeeeeee8597389751");
|
//text.add("1eeeeeee8597389751");
|
||||||
|
|
|
@ -58,8 +58,11 @@ public class TextTest {
|
||||||
Assertions.assertFalse(txt.replace(3, "alt", "neu"));
|
Assertions.assertFalse(txt.replace(3, "alt", "neu"));
|
||||||
Assertions.assertTrue(txt.replace(1, "erste", "zweite"));
|
Assertions.assertTrue(txt.replace(1, "erste", "zweite"));
|
||||||
Assertions.assertTrue(txt.replace("zweite", "erste"));
|
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 zweite Beispiel Text.", txt.getText().get(0));
|
||||||
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
Assertions.assertEquals("Das ist der erste Beispiel Text.", txt.getText().get(1));
|
||||||
|
Assertions.assertEquals("Test Test hallo Test", txt.getText().get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,4 +95,10 @@ public class TextTest {
|
||||||
stringListe = txt.index();
|
stringListe = txt.index();
|
||||||
Assertions.assertEquals(0,stringListe.size());
|
Assertions.assertEquals(0,stringListe.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testing() {
|
||||||
|
txt.add("");
|
||||||
|
txt.index();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue