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
|
2022-12-14 20:38:33 +01:00
|
|
|
* @version 1.3
|
2022-12-07 12:02:02 +01:00
|
|
|
*/
|
|
|
|
public class Data {
|
|
|
|
private String pathRead;
|
|
|
|
|
|
|
|
public Data(String pathRead) {
|
|
|
|
this.pathRead = pathRead;
|
|
|
|
}
|
2022-12-14 20:38:33 +01:00
|
|
|
/**
|
|
|
|
* readUser() is a method to split user.txt into lines and save them in an arraylist
|
|
|
|
* @return Arraylist userList
|
|
|
|
* @author Madeleine Vigier, Sabine Gubitz
|
|
|
|
* @version 1.3
|
|
|
|
*/
|
|
|
|
public ArrayList<User> readUser(){
|
|
|
|
List<String> rows = getRows();
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-07 12:02:02 +01:00
|
|
|
|
|
|
|
/**
|
2022-12-14 20:38:33 +01:00
|
|
|
* readMenue() is a method to split menue.txt into lines and save them in an arraylist
|
|
|
|
* @return Arraylist menuelist
|
2022-12-14 13:17:46 +01:00
|
|
|
* @author Madeleine Vigier, Sabine Gubitz
|
2022-12-14 20:38:33 +01:00
|
|
|
* @version 1.3
|
2022-12-07 12:02:02 +01:00
|
|
|
*/
|
2022-12-14 20:38:33 +01:00
|
|
|
public ArrayList<Menue> readMenue(){
|
|
|
|
ArrayList<Menue> menueList = new ArrayList<>();
|
|
|
|
List<String> rows = getRows();
|
2022-12-07 12:02:02 +01:00
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
for (String row : rows) {
|
|
|
|
String[] parts = row.split(";");
|
2022-12-07 12:02:02 +01:00
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
String date = parts[1];
|
|
|
|
String dish = parts[2];
|
|
|
|
String sideDish = parts[3];
|
|
|
|
String typ = parts[4];
|
|
|
|
String desertV = parts[5];
|
|
|
|
String desert = parts[6];
|
|
|
|
String allergens = parts[7];
|
2022-12-14 13:17:46 +01:00
|
|
|
|
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
boolean eggs = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
eggs = true;
|
|
|
|
}
|
|
|
|
allergens = parts[8];
|
|
|
|
boolean peanuts = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
peanuts = true;
|
|
|
|
}
|
|
|
|
allergens = parts[9];
|
|
|
|
boolean fish = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
fish = true;
|
|
|
|
}
|
|
|
|
allergens = parts[10];
|
|
|
|
boolean grains = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
grains = true;
|
|
|
|
}
|
|
|
|
allergens = parts[11];
|
|
|
|
boolean crustaceans = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
crustaceans = true;
|
|
|
|
}
|
|
|
|
allergens = parts[12];
|
|
|
|
boolean lupines = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
lupines = true;
|
|
|
|
}
|
|
|
|
allergens = parts[13];
|
|
|
|
boolean milk = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
milk = true;
|
|
|
|
}
|
|
|
|
allergens = parts[14];
|
|
|
|
boolean nuts = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
nuts = true;
|
|
|
|
}
|
|
|
|
allergens = parts[15];
|
|
|
|
boolean sulfurDioxideAndSulfite = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
sulfurDioxideAndSulfite = true;
|
|
|
|
}
|
|
|
|
allergens = parts[16];
|
|
|
|
boolean celeriac = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
celeriac = true;
|
|
|
|
}
|
|
|
|
allergens = parts[17];
|
|
|
|
boolean mustards = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
mustards = true;
|
|
|
|
}
|
|
|
|
allergens = parts[18];
|
|
|
|
boolean sesame = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
sesame = true;
|
|
|
|
}
|
|
|
|
allergens = parts[19];
|
|
|
|
boolean soy = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
soy = true;
|
|
|
|
}
|
|
|
|
allergens = parts[20];
|
|
|
|
boolean molluscs = false;
|
|
|
|
if (allergens != "") {
|
|
|
|
molluscs = true;
|
|
|
|
}
|
|
|
|
String additives = parts[21];
|
|
|
|
boolean antioxidant = false;
|
|
|
|
if (additives != "") {
|
|
|
|
antioxidant = true;
|
|
|
|
}
|
|
|
|
additives = parts[22];
|
|
|
|
boolean artificialColours = false;
|
|
|
|
if (additives != "") {
|
|
|
|
artificialColours = true;
|
|
|
|
}
|
|
|
|
additives = parts[23];
|
|
|
|
boolean flavourEnhancer = false;
|
|
|
|
if (additives != "") {
|
|
|
|
flavourEnhancer = true;
|
|
|
|
}
|
|
|
|
additives = parts[24];
|
|
|
|
boolean preservatives = false;
|
|
|
|
if (additives != "") {
|
|
|
|
preservatives = true;
|
|
|
|
}
|
|
|
|
additives = parts[25];
|
|
|
|
boolean nitrate = false;
|
|
|
|
if (additives != "") {
|
|
|
|
nitrate = true;
|
|
|
|
}
|
|
|
|
additives = parts[26];
|
|
|
|
boolean picklingSalt = false;
|
|
|
|
if (additives != "") {
|
|
|
|
picklingSalt = true;
|
|
|
|
}
|
|
|
|
additives = parts[27];
|
|
|
|
boolean phosphate = false;
|
|
|
|
if (additives != "") {
|
|
|
|
phosphate = true;
|
|
|
|
}
|
|
|
|
additives = parts[28];
|
|
|
|
boolean artificialSweetener = false;
|
|
|
|
if (additives != "") {
|
|
|
|
artificialSweetener = true;
|
|
|
|
}
|
2022-12-14 13:17:46 +01:00
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
menueList.add(new Menue(date, dish, sideDish, typ, desertV, desert, eggs, peanuts, fish, grains,
|
|
|
|
crustaceans, lupines, milk, nuts, sulfurDioxideAndSulfite, celeriac, mustards, sesame,
|
|
|
|
soy, molluscs, antioxidant, artificialColours, flavourEnhancer, preservatives, nitrate,
|
|
|
|
picklingSalt, phosphate, artificialSweetener));
|
|
|
|
}
|
|
|
|
return menueList;
|
|
|
|
}
|
2022-12-14 20:50:57 +01:00
|
|
|
|
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
/**
|
2022-12-14 20:50:57 +01:00
|
|
|
* readOrder() is a method to split order.txt into lines and save them in an arraylist
|
2022-12-14 20:38:33 +01:00
|
|
|
* @return Arraylist orderlist
|
|
|
|
* @author Madeleine Vigier, Sabine Gubitz
|
|
|
|
* @version 1.2
|
|
|
|
*/
|
|
|
|
public ArrayList<Order> readOrder(){
|
2022-12-07 12:02:02 +01:00
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
ArrayList<String> orderList = new ArrayList<>();
|
|
|
|
List<String> rows = getRows();
|
2022-12-07 12:02:02 +01:00
|
|
|
|
|
|
|
for (String row : rows) {
|
2022-12-14 20:38:33 +01:00
|
|
|
String[] parts = row.split(";");
|
2022-12-07 12:02:02 +01:00
|
|
|
|
|
|
|
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];
|
2022-12-14 13:17:46 +01:00
|
|
|
String desertV = parts[7];
|
|
|
|
String desertVCount = parts[8];
|
|
|
|
String desert = parts[9];
|
|
|
|
String desertCount = parts[10];
|
|
|
|
//orderList.add(new Order(date, meat, meatCount,vegi, vegiCount, vegan, veganCount, desertV,
|
|
|
|
// desertVCount, desert, desertCount))
|
2022-12-07 12:02:02 +01:00
|
|
|
}
|
|
|
|
return null;//orderList
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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")) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 20:38:33 +01:00
|
|
|
/**
|
|
|
|
* The method gets the rows by reading all lines of the path
|
|
|
|
* @return ArrayList rows
|
|
|
|
* @author Madeleine Vigier
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
|
|
|
private List<String> getRows() {
|
|
|
|
Path path = Paths.get(pathRead);
|
|
|
|
List<String> rows = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
rows = Files.readAllLines(path);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return rows;
|
|
|
|
}
|
2022-12-07 12:02:02 +01:00
|
|
|
}
|
2022-12-14 20:38:33 +01:00
|
|
|
|