changes in Methods dummy and replace.

static block to read dummy text file added
This commit is contained in:
schrom01 2021-10-29 17:06:10 +02:00
parent 108da09e5f
commit daa403cac0
3 changed files with 43 additions and 13 deletions

View File

@ -1 +1 @@
<mxfile host="app.diagrams.net" modified="2021-10-29T08:29:02.099Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36" etag="ptGALD8eWbvsmJseSY9z" version="15.6.2" type="device"><diagram id="eWy9IwHxbh3JgAdMnOEg" name="Seite-1">7VvbUuM4EP2aVDEPUL4nPJLAslSFHXYyWwOPwlZsLbLllRWS8PUrWfLdCQbiYlL4JWW1Lpb6HHW32srInIWbawri4JZ4EI8MzduMzMuRYTiTMf8Vgq0UmLYtBT5FnhTphWCBXqASakq6Qh5MKg0ZIZihuCp0SRRBl1VkgFKyrjZbElx9awx82BAsXICb0l/IY4GUToxxIf8TIj/I3qw757ImBFljtZIkAB5Zl0Tm1cicUUKYfAo3M4iF7jK9yH5/7KjNJ0ZhxLp0OJ87V4+38Uvyy0V/PdzD+d//rE8VGM8Ar9SCf8INu/IQI1RNm20zXSRrFGIQ8dJ0SSK2UDU6LwOM/Ig/u3wykHLBM6QMcTVeqApGYi51A4S9OdiSlZhywoD7lJWmAaHohQ8LsBqTV1OmGGE4lRYL0ZOLNS6lMOFt7jI96DXRLdhUGs5BwpTAJRiDOEGP+TJCQH0UTQljJFSNmmpWmhcrhJuSSKn9GpIQMrrlTVStrRiQbwFVXheEylkSlMjkKBlQHPbzkQuY+YNC+g2ojxuoN7DGKMU5YZQ85cwXKloijGcEc3qYlxFJG2XgY7hkLdCHyPNwOlgMXBT5PwUVLk/1QjJPO16aheSH0oIQUcIAAxIkgQgGjxDfkQQxRMT4VLadxgRFLFWVPR3Zl6mEshmJ+CIAStGDHPw1FARowXXvBnkdbIUuZ2oncCc9YTtpYBtT9AwYTPEFHBlRS/gYhnbL1XKyYJQrXOlMGE0/+dagA188y+lQg//tj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gp2bzfmaaXc2k8Xsz05mYx8nM7L7CsTDzAx65qxGc/NZMe3d0OK4zrb/o8L8QL+Z28CPYWA8euFno38fXp2aTV69aGUpWkZeaGYF90WZO0myD4Nu/kLGtyiaCFSM7qKmdWedldupnmma9xk9RuoMU8aWL5GcqbDF8Nab0bAnltcAmHd/Gs/SvSqUG6ui9k4a6Zlbpk9FpF90se7KvPX+QU+jIMV4s/tEtmxd/izev/gc=</diagram></mxfile>
<mxfile host="app.diagrams.net" modified="2021-10-29T09:15:44.799Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36" etag="eR9aW1ZoS3LHMXKP3oGi" version="15.6.2" type="device"><diagram id="eWy9IwHxbh3JgAdMnOEg" name="Seite-1">7VvbcuI4EP0aqjIPSfkOPAbIzqaK7GSH2ZrMo2ILWxvZ8soiQL5+JUu+G8bJ4MpQ8QtltVrC6nPU3WrEyJyHu88UxMEd8SAeGZq3G5mLkWFMJwb/FIK9FNjaWAp8ijwp0gvBCr1AJdSUdIM8mFQUGSGYobgqdEkUQZdVZIBSsq2qrQmufmsMfNgQrFyAm9LvyGOBlE6McSH/EyI/yL5Zd6ayJwSZslpJEgCPbEsi82ZkzikhTD6FuznEwnaZXeS4Pw705i9GYcS6DJgunZvHu/gl+e6iv348wOXf/2wvbTnLM8AbteBvcMduPMQIVa/N9pktki0KMYh4a7YmEVupHp23AUZ+xJ9d/jKQcsEzpAxxM16rDkZiLnUDhL0l2JONeOWEAfcpa80CQtELnxZgNSfvpkwxwnAqGisxkos1LqUw4Tr3mR30mugO7CqKS5AwJXAJxiBO0GO+jBBQH0UzwhgJlVLTzMryYoVwVxIps3+GJISM7rnKLuO8HKG2gJm1twWhcpYEJTI5SgYUh/185gJm/qCQfgXq4wbqDawxSnFOGCVPOfOFidYI4znBnB7mIiKpUgY+hmvWAn2IPA+nk8XARZH/TVBhcakXkmU6cGEWkq/KCkJECQMMSJAEIhg8Q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NZyFcUGzvVNMKqF5PkytWogjCNiSZ6bSKzNpG0TGOilHn5sn+BjB3uu38UMmaXxM6OjFqdjMbbyGjXkmOrnvP2TcYOdyU+ChmzOsO5k9Ecv9EzvjsZ2252nDUZPZAE0FNv83Zmml3dpPF7M9OZmOfJzOz6wrkw8xciclcnOPmtmfbm7HBcZ1p/2eF/IV4t7eBrsLN+eOB2pX8Zf740m7z6qZehZBN5qZsR2Bc6S5JWGwTf/oWM7VU1EWwYOUBN7cqaltmpX2ma9TN+itY9pIgvXRQ/U2GL46sxpWdPKG8JNun4Op6l/00qKaij90Ea6ppZpU9Gp0N0s+zJMX3+IF+hI8d4s/gLt1Qv/gdv3vwP</diagram></mxfile>

View File

@ -1,9 +1,30 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Text {
private ArrayList<String> text = new ArrayList<>();
private String dummyText = "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.";
private static final String dummyTextFileName = "dummytext.txt";
private static String dummyText = "";
/**
* Static block to get Dummytext from file.
*/
static {
File dummyTextFile = new File(dummyTextFileName);
try {
Scanner scanner = new Scanner(dummyTextFile);
while(scanner.hasNextLine()) {
dummyText = dummyText + scanner.nextLine() + " ";
}
} catch (FileNotFoundException e) {
dummyText = "File " + dummyTextFileName + " not found.";
}
}
/**
* Method to add a paragraph at a specific position.
@ -12,8 +33,8 @@ public class Text {
* @return returns true if the given paragraph exists and is added successfully
*/
public boolean add(int paragraphNumber, String text) {
if(paragraphNumber < this.text.size()) {
this.text.add(paragraphNumber, text);
if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) {
this.text.add((paragraphNumber - 1), text);
return true;
}
return false;
@ -47,25 +68,34 @@ public class Text {
}
/**
*
* @param paragraphNumber
* @param oldString
* @param replaceString
* @return
* Method to replace characters in a specific paragraph
* @param paragraphNumber number of paragraph which should be changed.
* @param oldChar the old character.
* @param newChar the new character.
* @return returns true if the given paragraph exists and is changed successfully
*/
public boolean replace(int paragraphNumber, String oldString, String replaceString) {
if(paragraphNumber < this.text.size()) {
public boolean replace(int paragraphNumber, String oldChar, String newChar) {
if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) {
text.set((paragraphNumber - 1), text.get(paragraphNumber - 1).replace(oldChar, newChar));
return true;
}
return false;
}
public boolean replace(String oldString, String replaceString) {
/**
* Method to replace characters in the last paragraph
* @param oldChar the old character.
* @param newChar the new character.
* @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;
}
public boolean del(int paragraphNumber) {
if(paragraphNumber < this.text.size()) {
if(paragraphNumber > 0 && (paragraphNumber <= this.text.size())) {
//paragraph hier löschen.
return true;
}