2022-11-24 13:59:26 +01:00
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.FileWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
2022-11-24 14:22:56 +01:00
|
|
|
import java.nio.file.Path;
|
2022-11-24 13:59:26 +01:00
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**GeneralMethods is a class for commen public methods.
|
|
|
|
*
|
|
|
|
* @auhtor Felix Wöstemeyer
|
|
|
|
*
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
|
|
|
public class GeneralMethods {
|
|
|
|
/**The method writeData saves the given data to a certain file.
|
|
|
|
*
|
|
|
|
* @param pathWrite the given filepath to write
|
|
|
|
* @param data the data to be saved
|
|
|
|
*/
|
|
|
|
public static void writeData(String pathWrite, ArrayList<String> data){
|
|
|
|
try{
|
|
|
|
BufferedWriter writer = new BufferedWriter(new FileWriter(pathWrite));
|
|
|
|
for (String d : data) {
|
|
|
|
writer.write(d);
|
|
|
|
writer.newLine();
|
|
|
|
}
|
|
|
|
writer.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-11-24 14:22:56 +01:00
|
|
|
|
|
|
|
/**
|
2022-11-24 14:50:28 +01:00
|
|
|
* Author: Sabine Gubitz
|
|
|
|
*
|
2022-11-24 14:22:56 +01:00
|
|
|
* The method read Data interprets a file and returns an useable list for other methods.
|
|
|
|
* Files to be read have to use : as a divider between attributes
|
|
|
|
*
|
|
|
|
* @param pathRead determines the filename of the file that will be read
|
|
|
|
* @return menueList, userList, orderList depending on Data read
|
|
|
|
*/
|
2022-11-24 14:50:28 +01:00
|
|
|
public ArrayList<String> readData(String pathRead) {
|
2022-11-24 14:22:56 +01:00
|
|
|
Path path = Paths.get(pathRead);
|
|
|
|
|
|
|
|
try {
|
|
|
|
List<String> rows = Files.readAllLines(path);
|
|
|
|
|
2022-11-24 14:50:28 +01:00
|
|
|
if (pathRead == "menue.txt") {
|
2022-11-24 14:22:56 +01:00
|
|
|
ArrayList<String> menueList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String row : rows) {
|
|
|
|
String[] parts = row.split(":");
|
|
|
|
|
|
|
|
String day = parts[0];
|
|
|
|
String date = parts[1];
|
|
|
|
String meat = parts[2];
|
|
|
|
String vegi = parts[3];
|
|
|
|
String vegan = parts[4];
|
|
|
|
String desert1 = parts[5];
|
|
|
|
String desert2 = parts[6];
|
|
|
|
menueList.add(day + "," + date + "," + meat + "," + vegi + "," + vegan + "," + desert1 + "," + desert2);
|
|
|
|
}
|
|
|
|
return menueList;
|
|
|
|
|
2022-11-24 14:50:28 +01:00
|
|
|
} else if (pathRead == "users.txt") {
|
2022-11-24 14:22:56 +01:00
|
|
|
ArrayList<String> userList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String row : rows) {
|
|
|
|
String[] parts = row.split(":");
|
|
|
|
|
|
|
|
String nameParent1 = parts[0];
|
|
|
|
String nameParent2 = parts[1];
|
|
|
|
String billAddress = parts[2];
|
|
|
|
String phonenumber = parts[3];
|
|
|
|
String nameChildren = parts[4];
|
2022-11-24 14:50:28 +01:00
|
|
|
String password = parts[5];
|
2022-11-24 14:22:56 +01:00
|
|
|
}
|
|
|
|
return userList;
|
|
|
|
|
2022-11-24 14:50:28 +01:00
|
|
|
} else if (pathRead == "orders.txt") {
|
2022-11-24 14:22:56 +01:00
|
|
|
ArrayList<String> orderList = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String row : rows) {
|
|
|
|
String[] parts = row.split(":");
|
|
|
|
|
|
|
|
String date = parts[0];
|
|
|
|
String meat = parts[1];
|
|
|
|
String meatCount = parts[2];
|
|
|
|
String vegi = parts[3];
|
|
|
|
String vegiCount = parts[4];
|
|
|
|
String vegan = parts[5];
|
|
|
|
String veganCount = parts[6];
|
|
|
|
String desert1 = parts[7];
|
|
|
|
String desert1Count = parts[8];
|
|
|
|
String desert2 = parts[9];
|
|
|
|
String desert2Count = parts[10];
|
|
|
|
}
|
|
|
|
return orderList;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The method writeData writes the data of a List into a txt file.
|
|
|
|
* @param pathWrite determines the filename of the file that will be written
|
|
|
|
* @param listToWrite determines which ArrayList is to be used for writing the file
|
|
|
|
*/
|
|
|
|
public void writeData2 (String pathWrite, ArrayList<String> listToWrite){
|
|
|
|
if (pathWrite == "users.txt") {
|
|
|
|
|
|
|
|
} else if (pathWrite == "orders.txt") {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2022-11-24 13:59:26 +01:00
|
|
|
}
|