2022-12-07 12:02:02 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data is a class to edit files.
|
|
|
|
* @author Madeleine Vigier
|
|
|
|
* @version 1.1
|
|
|
|
*/
|
|
|
|
public class Data {
|
|
|
|
private String pathRead;
|
|
|
|
|
|
|
|
public Data(String pathRead) {
|
|
|
|
this.pathRead = pathRead;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* load() is a methode to split a file into lines, save lines in a arraylist
|
|
|
|
* @return Arraylist userlist
|
|
|
|
* @author Madeleine Vigier
|
|
|
|
* @version 1.1
|
|
|
|
*/
|
|
|
|
public ArrayList<User> readData() {
|
|
|
|
Path path = Paths.get(pathRead);
|
|
|
|
|
|
|
|
try {
|
|
|
|
List<String> rows = Files.readAllLines(path);
|
|
|
|
//muss noch angepasst werden
|
|
|
|
if (pathRead.equals("menue.txt")) {
|
|
|
|
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 null;//menueList;
|
|
|
|
//ist angepasst
|
|
|
|
} else if (pathRead.equals("users.txt")){
|
|
|
|
ArrayList<User> 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];
|
|
|
|
String password = parts[5];
|
|
|
|
userList.add(new User(nameParent1,nameParent2,billAddress,phonenumber,nameChildren,password));
|
|
|
|
}
|
|
|
|
return userList;
|
|
|
|
//muss noch angepasst werden
|
|
|
|
} else if (pathRead.equals("orders.txt")) {
|
|
|
|
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 null;//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
|
|
|
|
*/
|
2022-12-07 12:14:54 +01:00
|
|
|
public void writeData(String pathWrite, ArrayList<String> listToWrite){
|
2022-12-07 12:02:02 +01:00
|
|
|
if (pathWrite.equals("users.txt")) {
|
|
|
|
|
|
|
|
} else if (pathWrite.equals("orders.txt")) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|