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

# Conflicts:
#	src/TextEditor.java
This commit is contained in:
MikeZyeman 2021-11-12 09:08:01 +01:00
commit fde32d8605
4 changed files with 31 additions and 33 deletions

View File

@ -8,10 +8,10 @@ public class Text {
private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"; private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";
/** /**
* Method to check if a specific Paragraph exists * Method to check if a specific paragraph exists.
* *
* @param paragraphNumber the number of the paragraph which should be checked * @param paragraphNumber the number of the paragraph which should be checked.
* @return returns true if the paragraph exists * @return returns true if the paragraph exists.
*/ */
private boolean paragraphExists(int paragraphNumber) { private boolean paragraphExists(int paragraphNumber) {
return ((paragraphNumber > 0) && (paragraphNumber <= this.text.size())); return ((paragraphNumber > 0) && (paragraphNumber <= this.text.size()));
@ -20,9 +20,9 @@ public class Text {
/** /**
* Method to add a paragraph at a specific position. * Method to add a paragraph at a specific position.
* *
* @param paragraphNumber number of paragraph where the new text should be added * @param paragraphNumber number of paragraph where the new text should be added.
* @param text the Text which should be added. * @param text the Text which should be added.
* @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 (paragraphExists(paragraphNumber)) { if (paragraphExists(paragraphNumber)) {
@ -35,8 +35,8 @@ public class Text {
/** /**
* Method to add a paragraph at the end of the existing text. * Method to add a paragraph at the end of the existing text.
* *
* @param text the Text which should be added. * @param text the text which should be added.
* @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) {
this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]","")); this.text.add(text.replaceAll("[^A-Za-z0-9 .,:?!\"'-]",""));
@ -46,7 +46,7 @@ public class Text {
/** /**
* Method to get all paragraph of the existing instance. * Method to get all paragraph of the existing instance.
* *
* @return returns a ArrayList<String> with all paragraphs inside. * @return returns an ArrayList<String> with all paragraphs inside.
*/ */
public ArrayList<String> getText() { public ArrayList<String> getText() {
return text; return text;
@ -55,8 +55,8 @@ public class Text {
/** /**
* Method to add a dummy text paragraph at a specific position. * Method to add a dummy text paragraph at a specific position.
* *
* @param paragraphNumber number of paragraph where the dummy text should be added * @param paragraphNumber number of paragraph where the dummy text should be added.
* @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 dummy(int paragraphNumber) { public boolean dummy(int paragraphNumber) {
return add(paragraphNumber, dummyText); return add(paragraphNumber, dummyText);
@ -65,19 +65,19 @@ public class Text {
/** /**
* Method to add a dummy text paragraph at the end of the existing text. * Method to add a dummy text paragraph at the end of the existing text.
* *
* @return returns true if the paragraph is added successfully * @return returns true if the paragraph is added successfully.
*/ */
public boolean dummy() { public boolean dummy() {
return add(dummyText); return add(dummyText);
} }
/** /**
* Method to replace characters in a specific paragraph * Method to replace characters in a specific paragraph.
* *
* @param paragraphNumber number of paragraph which should be changed. * @param paragraphNumber number of paragraph which should be changed.
* @param oldChar the old character. * @param oldChar the old character.
* @param newChar the new character. * @param newChar the new character.
* @return returns true if the given paragraph exists and is changed successfully * @return returns true if the given paragraph exists and is changed successfully.
*/ */
public boolean replace(int paragraphNumber, String oldChar, String newChar) { public boolean replace(int paragraphNumber, String oldChar, String newChar) {
if (paragraphExists(paragraphNumber)) { if (paragraphExists(paragraphNumber)) {
@ -95,7 +95,7 @@ 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()))) { 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;
} }
@ -103,8 +103,8 @@ public class Text {
} }
/** /**
* 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.
* If the Parameter is valid it deletes the specific Pararaph otherwise returns false * If the parameter is valid it deletes the specific pararaph otherwise it will return false.
* *
* @param paragraphNumber the Paragraph which should be deleted. * @param paragraphNumber the Paragraph which should be deleted.
* @return False: If the int is not a valid paragraph. || True: If the int is a valid paragraph number * @return False: If the int is not a valid paragraph. || True: If the int is a valid paragraph number
@ -133,13 +133,13 @@ public class Text {
/** /**
* This method creates a ArrayList<String>. * This method creates a ArrayList<String>.
* Every word which is used in the text more than 3 times * Every word which is used in the text more than 3 times
* will be added to the ArrayList with the paragraphes where the word is been used. * will be added to the ArrayList with the paragraphs where the word has been used.
* *
* @return ArrayList<String> * @return ArrayList<String>
*/ */
public ArrayList<String> index() { public ArrayList<String> index() {
HashMap<String,ArrayList<Integer>> wordbook = new HashMap<>(); HashMap<String,ArrayList<Integer>> wordbook = new HashMap<>();
wordbook = createWordlist(wordbook); createWordlist(wordbook);
String input; String input;
ArrayList<String> output = new ArrayList<>(); ArrayList<String> output = new ArrayList<>();
ArrayList<Integer> values; ArrayList<Integer> values;
@ -163,11 +163,10 @@ public class Text {
} }
/** /**
* This method counts all Words in text and adds the count together with the paragraph where the word is been used to a Hashmap. * This method counts all words in text and adds the count together with the paragraph where the word has been used to a Hashmap.
* *
* @return HashMap<String, ArrayList < Integer>>
*/ */
private HashMap<String, ArrayList<Integer>> createWordlist(HashMap<String,ArrayList<Integer>> wordbook) { private void createWordlist(HashMap<String,ArrayList<Integer>> wordbook) {
int counter; int counter;
ArrayList<Integer> numbersList; ArrayList<Integer> numbersList;
String firstLetter; String firstLetter;
@ -186,7 +185,6 @@ public class Text {
counter = numbersList.get(0); counter = numbersList.get(0);
numbersList.remove(0); numbersList.remove(0);
numbersList.add(0, counter + 1); numbersList.add(0, counter + 1);
if (numbersList.get(numbersList.size() - 1) < i + 1) { if (numbersList.get(numbersList.size() - 1) < i + 1) {
numbersList.add(i + 1); numbersList.add(i + 1);
} }
@ -198,7 +196,6 @@ public class Text {
wordbook.put(word, numbersList); wordbook.put(word, numbersList);
} }
} }
return wordbook;
} }
} }

View File

@ -1,15 +1,16 @@
/** /**
* MainKlasse TextEditor * Main class TextEditor
*/ */
public class TextEditor { public class TextEditor {
/** /**
* Run Methode * Main Method that is connected to the TextLogik class.
* <p> * @param args there are no arguments needed.
* Startet das Programm auf
*
* @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
TextLogik t = new TextLogik(); TextLogik t = new TextLogik();
} }
} }

View File

@ -62,7 +62,7 @@ public class TextLogik {
if (command.length > 1 && "RAW".equals(command[1])) { if (command.length > 1 && "RAW".equals(command[1])) {
checkIfSuccess(textOutput.formatRaw()); checkIfSuccess(textOutput.formatRaw());
} else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) { } else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) {
checkIfSuccess(textOutput.formatFix(Integer.parseInt(command[2]))); textOutput.formatFix(Integer.parseInt(command[2]));
} else { } else {
textOutput.errorInvalidCommand(); textOutput.errorInvalidCommand();
} }

View File

@ -89,14 +89,14 @@ public class TextOutput {
* @param length the paragraph length when printing the text. * @param length the paragraph length when printing the text.
* @return returns true if successful and false if and invalid length has been submitted. * @return returns true if successful and false if and invalid length has been submitted.
*/ */
public boolean formatFix(int length) { public void formatFix(int length) {
if(length > 0) { if(length > 0) {
formatRaw = false; formatRaw = false;
columnWidth = length; columnWidth = length;
return true; userInfoOutput("Command was successfull");
} }
else { else {
return false; System.err.println("Minimum length has to be greater than 0");
} }
} }