Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
7683868668
8 files changed
+66
-71
No files matched your search
File renamed without changes.
@@ -1 +1 @@
|
||||
<mxfile host="drawio-plugin" modified="2021-11-11T10:08:36.751Z" agent="5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" etag="RFuHruWxcTLuDEr7c7r0" version="14.7.4" type="embed"><diagram id="eWy9IwHxbh3JgAdMnOEg" name="Seite-1"><mxGraphModel dx="610" dy="527" 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="180" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-13" value="+ ArrayList<String> text" 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-12" vertex="1"><mxGeometry y="26" width="220" height="26" 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="52" width="220" height="8" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-15" value="+ add() +dummy(n) + replace(n) + index():ArrayList + getText() + del(n) - createWordlist(HashMap):HashMap - 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="60" 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 SystemOut out " 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)" 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="SystemOut" 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="433" width="160" height="140" as="geometry"/></mxCell><mxCell id="9L6EbMpzsWciNYXeLQUw-21" value="int Line 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<String>{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 + dummy(int:n):boolean + replace(int:n, String, String):boolean + index():ArrayList<String> + getText():ArrayList<String> + del(int:n):boolean - createWordlist(HashMap<String, ArrayList<Integer>>):HashMap<String, ArrayList<Integer>> - 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} - 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 - isNumeric(String):boolean - checkIfSuccess(boolean)" style="text;strokeColor=none;fillColor=none;align=left;verticalAlign=top;spacingLeft=4;spaLine truncated
|
||||
+18
-6
@@ -25,6 +25,9 @@ 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;
|
||||
@@ -39,7 +42,10 @@ public class Text {
|
||||
* @return returns true if the paragraph is added successfully
|
||||
*/
|
||||
public boolean add(String text) {
|
||||
this.text.add(text);
|
||||
if(text.length() < 1) {
|
||||
return false;
|
||||
}
|
||||
this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,8 +101,11 @@ public class Text {
|
||||
* @return returns true if the paragraph is changed successfully
|
||||
*/
|
||||
public boolean replace(String oldChar, String newChar) {
|
||||
text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
|
||||
return true;
|
||||
if(paragraphExists((text.size()))) {
|
||||
text.set((text.size() - 1), text.get(text.size() - 1).replace(oldChar, newChar));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,8 +129,11 @@ public class Text {
|
||||
* @return True: if paragraph has been deleted.
|
||||
*/
|
||||
public boolean del() {
|
||||
text.remove(text.size() - 1);
|
||||
return true;
|
||||
if(paragraphExists(text.size())){
|
||||
text.remove(text.size() - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +179,7 @@ public class Text {
|
||||
String firstLetter;
|
||||
String restLetters;
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/\n]+");
|
||||
String[] words = text.get(i).trim().toLowerCase().split("[ :;.,!?><+*}{)('/\n]+");
|
||||
for (String word : words) {
|
||||
//Words get formatted consistently
|
||||
counter = 1;
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ public class TextInput {
|
||||
private static final Scanner sc = new Scanner(System.in);
|
||||
|
||||
public static String[] checkForInput() {
|
||||
return sc.nextLine().split(" ");
|
||||
return sc.nextLine().toUpperCase().split(" ");
|
||||
}
|
||||
|
||||
public static String getTextInput() {
|
||||
|
||||
+24
-14
@@ -12,11 +12,16 @@ public class TextLogik {
|
||||
textOutput = new TextOutput();
|
||||
String[] command;
|
||||
|
||||
textOutput.userInfoOutput("######################");
|
||||
textOutput.userInfoOutput("#WELCOME TO THE EDITOR#");
|
||||
textOutput.userInfoOutput("######################");
|
||||
do {
|
||||
textOutput.userInfoOutput("Please enter a Command: ");
|
||||
command = TextInput.checkForInput();
|
||||
|
||||
switch (command[0]) {
|
||||
case "ADD":
|
||||
textOutput.userInfoOutput("Please enter your text: ");
|
||||
if (command.length == 1) {
|
||||
checkIfSuccess(text.add(TextInput.getTextInput()));
|
||||
} else if (isNumeric(command[1])) {
|
||||
@@ -29,10 +34,10 @@ public class TextLogik {
|
||||
break;
|
||||
case "DEL":
|
||||
if (command.length == 1) {
|
||||
text.del();
|
||||
checkIfSuccess(text.del());
|
||||
} else if (isNumeric(command[1])) {
|
||||
int line = Integer.parseInt(command[1]);
|
||||
text.del(line);
|
||||
checkIfSuccess(text.del(line));
|
||||
} else {
|
||||
textOutput.errorInvalidCommand();
|
||||
}
|
||||
@@ -51,9 +56,9 @@ public class TextLogik {
|
||||
break;
|
||||
case "FORMAT":
|
||||
if (command.length > 1 && "RAW".equals(command[1])) {
|
||||
textOutput.formatRaw();
|
||||
checkIfSuccess(textOutput.formatRaw());
|
||||
} else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) {
|
||||
textOutput.formatFix(Integer.parseInt(command[2]));
|
||||
checkIfSuccess(textOutput.formatFix(Integer.parseInt(command[2])));
|
||||
} else {
|
||||
textOutput.errorInvalidCommand();
|
||||
}
|
||||
@@ -63,17 +68,22 @@ public class TextLogik {
|
||||
textOutput.indexOutput(text.index());
|
||||
break;
|
||||
case "PRINT":
|
||||
|
||||
textOutput.print(text.getText());
|
||||
|
||||
break;
|
||||
case "REPLACE":
|
||||
if (command.length == 1){
|
||||
checkIfSuccess(text.replace(TextInput.getTextInput(), TextInput.getTextInput()));
|
||||
}else if(isNumeric(command[1])) {
|
||||
String oldChar = "";
|
||||
while (oldChar.length() == 0) {
|
||||
textOutput.userInfoOutput("Please enter your text to replace: ");
|
||||
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]);
|
||||
checkIfSuccess(text.replace(line, TextInput.getTextInput(), TextInput.getTextInput()));
|
||||
}else {
|
||||
checkIfSuccess(text.replace(line, oldChar, newChar));
|
||||
} else {
|
||||
textOutput.errorInvalidCommand();
|
||||
}
|
||||
|
||||
@@ -97,9 +107,9 @@ public class TextLogik {
|
||||
}
|
||||
|
||||
private void checkIfSuccess(boolean method) {
|
||||
if(method) {
|
||||
textOutput.userInfoOutput("Command was successfully");
|
||||
}else {
|
||||
if (method) {
|
||||
textOutput.userInfoOutput("Command was successfull");
|
||||
} else {
|
||||
textOutput.errorInvalidParagraph();
|
||||
}
|
||||
}
|
||||
|
||||
+12
-49
@@ -33,43 +33,6 @@ public class TextOutput {
|
||||
|
||||
}
|
||||
|
||||
private void toFormatold(ArrayList<String> text) {
|
||||
for (String paragraph : text) {
|
||||
String[] words = paragraph.split(" ");
|
||||
int currentLength = 0;
|
||||
for (String word : words) {
|
||||
if (word.length() > columnWidth) {
|
||||
String[] letters = word.split("");
|
||||
int letterLenght = letters.length;
|
||||
int lettersPrinted = 0;
|
||||
do {
|
||||
currentLength = 0;
|
||||
for (int i = 0; i < columnWidth; i++) {
|
||||
if (letterLenght > 0) {
|
||||
System.out.print(letters[lettersPrinted]);
|
||||
letterLenght--;
|
||||
lettersPrinted++;
|
||||
currentLength++;
|
||||
}
|
||||
}
|
||||
if (!(letterLenght == 0)) {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
while (letterLenght >= columnWidth);
|
||||
|
||||
} else {
|
||||
if (word.length() >= columnWidth - currentLength) {
|
||||
currentLength = 0;
|
||||
System.out.println();
|
||||
}
|
||||
System.out.print(word + " ");
|
||||
currentLength += word.length() + 1;
|
||||
}
|
||||
}
|
||||
System.out.println(); //added
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next
|
||||
* paragraph.
|
||||
@@ -77,8 +40,8 @@ public class TextOutput {
|
||||
* @param text the ArrayList which is used for the output.
|
||||
*/
|
||||
private void toFormat(ArrayList<String> text) {
|
||||
int currentLength = 0;
|
||||
for (String paragraph : text) {
|
||||
int currentLength = 0;
|
||||
String[] words = paragraph.split(" ");
|
||||
int lastWordNumber = words.length;
|
||||
int currentWordNumber = 0;
|
||||
@@ -86,21 +49,21 @@ public class TextOutput {
|
||||
currentWordNumber++;
|
||||
if (word.length()<= columnWidth - currentLength) {
|
||||
System.out.print(word);
|
||||
if (!(lastWordNumber == currentWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = currentLength + word.length() + 1;
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
if(currentWordNumber != 1) {
|
||||
System.out.println();
|
||||
}
|
||||
currentLength = 0;
|
||||
}
|
||||
System.out.print(word);
|
||||
|
||||
}
|
||||
if(!(currentWordNumber == lastWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = currentLength + word.length() + 1;
|
||||
}
|
||||
else {
|
||||
System.out.println();
|
||||
System.out.print(word);
|
||||
if(!(currentWordNumber == lastWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = word.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,9 @@ class TextOutputTest {
|
||||
@Test
|
||||
public void print() {
|
||||
textOutput.print(text);
|
||||
System.out.println("fertig");
|
||||
textOutput.formatRaw();
|
||||
textOutput.print(text);
|
||||
System.out.println("fertig");
|
||||
}
|
||||
}
|
||||
@@ -92,4 +92,10 @@ public class TextTest {
|
||||
stringListe = txt.index();
|
||||
Assertions.assertEquals(0,stringListe.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testing() {
|
||||
txt.add("");
|
||||
txt.index();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user