TextLogik remove duplicated code
This commit is contained in:
		
							parent
							
								
									6b0eabea71
								
							
						
					
					
						commit
						bc4dd38db4
					
				| 
						 | 
					@ -102,8 +102,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 +130,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;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,13 +71,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 +107,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();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,4 +92,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