Merge remote-tracking branch 'origin/main'

This commit is contained in:
amadoste committed 2021-11-11 23:37:18 +01:00
commit 6ecda2c63c
7 files changed
+75 -42

No files matched your search

+1 -1
View File
@@ -1 +1 @@
<mxfile host="drawio-plugin" modified="2021-11-11T15:14:21.551Z" agent="5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" etag="JafT3Sc43sJtv75s3ZIq" version="14.7.4" type="embed"><diagram id="eWy9IwHxbh3JgAdMnOEg" name="Seite-1"><mxGraphModel dx="873" dy="754" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="9L6EbMpzsWciNYXeLQUw-5" value="TextEditor" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="50" y="350" width="220" height="60" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-7" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-5" vertex="1"><mxGeometry y="26" width="220" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-8" value="private static void Main(String[] args)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-5" vertex="1"><mxGeometry y="34" width="220" height="26" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-12" value="Text" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="690" y="210" width="220" height="189" as="geometry"/></mxCell><mxCell id="2" value="- text:ArrayList&lt;String&gt;{final}&#10;- dummyText{final}" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontStyle=0" vertex="1" parent="9L6EbMpzsWciNYXeLQUw-12"><mxGeometry y="26" width="220" height="35" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-14" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-12" vertex="1"><mxGeometry y="61" width="220" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-15" value="+ add():boolean&#10;+dummy(int:n):boolean&#10;+ replace(int:n):boolean&#10;+ index():ArrayList&#10;+ getText()&#10;+ del(int:n):boolean&#10;- createWordlist(HashMap):HashMap&#10;- paragraphExists():boolean" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;shadow=0;" parent="9L6EbMpzsWciNYXeLQUw-12" vertex="1"><mxGeometry y="69" width="220" height="120" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-16" value="EditorLogik" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="380" y="347" width="160" height="150" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-17" value="Text text&#10;TextOutput textOut&#10;" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-16" vertex="1"><mxGeometry y="26" width="160" height="74" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-18" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-16" vertex="1"><mxGeometry y="100" width="160" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-19" value="- isNumeric(String):boolean&#10;- checkIfSuccess():boolean" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-16" vertex="1"><mxGeometry y="108" width="160" height="42" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-20" value="TextOutput" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="69Line truncated <mxfile host="drawio-plugin" modified="2021-11-11T15:44:16.764Z" agent="5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36" etag="8tmA9X3Hm-2oii_iS7md" version="14.7.4" type="embed"><diagram id="eWy9IwHxbh3JgAdMnOEg" name="Seite-1"><mxGraphModel dx="1110" dy="479" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="9L6EbMpzsWciNYXeLQUw-5" value="TextEditor" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="50" y="350" width="220" height="60" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-7" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-5" vertex="1"><mxGeometry y="26" width="220" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-8" value="private static void Main(String[] args)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-5" vertex="1"><mxGeometry y="34" width="220" height="26" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-12" value="Text" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="690" y="210" width="520" height="204" as="geometry"/></mxCell><mxCell id="3" value="- text:ArrayList&lt;String&gt;{final}" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontStyle=0" vertex="1" parent="9L6EbMpzsWciNYXeLQUw-12"><mxGeometry y="26" width="520" height="20" as="geometry"/></mxCell><mxCell id="2" value="- dummyText{final}" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontStyle=4" parent="9L6EbMpzsWciNYXeLQUw-12" vertex="1"><mxGeometry y="46" width="520" height="20" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-14" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-12" vertex="1"><mxGeometry y="66" width="520" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-15" value="+ add(int:n, String):boolean&#10;+ dummy(int:n):boolean&#10;+ replace(int:n, String, String):boolean&#10;+ index():ArrayList&lt;String&gt;&#10;+ getText():ArrayList&lt;String&gt;&#10;+ del(int:n):boolean&#10;- createWordlist(HashMap&lt;String, ArrayList&lt;Integer&gt;&gt;):HashMap&lt;String, ArrayList&lt;Integer&gt;&gt;&#10;- paragraphExists(int):boolean" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;shadow=0;" parent="9L6EbMpzsWciNYXeLQUw-12" vertex="1"><mxGeometry y="74" width="520" height="130" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-16" value="TextLogik" style="swimlane;fontStyle=1;align=center;verticalAlign=top;childLayout=stackLayout;horizontal=1;startSize=26;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;" parent="1" vertex="1"><mxGeometry x="380" y="347" width="170" height="114" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-17" value="- text Text{final}&#10;- textOutput Textoutput{final}" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-16" vertex="1"><mxGeometry y="26" width="170" height="30" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-18" value="" style="line;strokeWidth=1;fillColor=none;align=left;verticalAlign=middle;spacingTop=-1;spacingLeft=3;spacingRight=3;rotatable=0;labelPosition=right;points=[];portConstraint=eastwest;" parent="9L6EbMpzsWciNYXeLQUw-16" vertex="1"><mxGeometry y="56" width="170" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-19" value="+ TextLogik&#10;- isNumeric(String):boolean&#10;- checkIfSuccess(boolean)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spaLine truncated
+10 -10
View File
@@ -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,8 +96,11 @@ 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) {
text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar)); if(paragraphExists((text.size()))) {
return true; text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
return true;
}
return false;
} }
/** /**
@@ -127,8 +124,11 @@ public class Text {
* @return True: if paragraph has been deleted. * @return True: if paragraph has been deleted.
*/ */
public boolean del() { public boolean del() {
text.remove(text.size() - 1); if(paragraphExists(text.size())){
return true; text.remove(text.size() - 1);
return true;
}
return false;
} }
/** /**
+1 -1
View File
@@ -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() {
+23 -13
View File
@@ -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":
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) { 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":
textOutput.userInfoOutput("Please enter your text to replace: "); String oldChar = "";
if (command.length == 1){ while (oldChar.length() == 0) {
checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput())); textOutput.userInfoOutput("Please enter your text to replace: ");
}else if(isNumeric(command[1])) { oldChar = TextInput.getTextInput();
}
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();
} }
} }
+30 -16
View File
@@ -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,24 +52,23 @@ 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)) { }
System.out.print(" "); else {
currentLength = currentLength + word.length() + 1; if(currentWordNumber != 1) {
}
else {
System.out.println(); System.out.println();
} currentLength = 0;
}
System.out.print(word);
}
if(!(currentWordNumber == lastWordNumber)) {
System.out.print(" ");
currentLength = currentLength + word.length() + 1;
} }
else { else {
System.out.println(); System.out.println();
System.out.print(word);
if(!(currentWordNumber == lastWordNumber)) {
System.out.print(" ");
currentLength = word.length() + 1;
}
} }
} }
System.out.println();
} }
} }
@@ -113,8 +115,13 @@ 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) {
for (String word : index) { if(index.size() == 0) {
System.out.println(word); userInfoOutput("index empty");
}
else {
for (String word : index) {
System.out.println(word);
}
} }
} }
@@ -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");
}
} }
+1 -1
View File
@@ -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");
+9
View File
@@ -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();
}
} }