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.3 */ public class Data { private String pathRead; public Data(String pathRead) { this.pathRead = pathRead; } /** * 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 readUser() { List rows = getRows(); ArrayList 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; } /** * readMenue() is a method to split menue.txt into lines and save them in an arraylist * * @return Arraylist menuelist * @author Madeleine Vigier, Sabine Gubitz * @version 1.3 */ public ArrayList readMenue() { List rows = getRows(); ArrayList menueList = new ArrayList<>(); for (String row : rows) { String[] parts = row.split(";"); String date = parts[0]; String dish = parts[1]; String sideDish = parts[2]; String typ = parts[3]; String allergens = parts[4]; boolean eggs = false; if (!allergens.isEmpty()) { eggs = true; } allergens = parts[5]; boolean peanuts = false; if (!allergens.isEmpty()) { peanuts = true; } allergens = parts[6]; boolean fish = false; if (!allergens.isEmpty()) { fish = true; } allergens = parts[7]; boolean grains = false; if (!allergens.isEmpty()) { grains = true; } allergens = parts[8]; boolean crustaceans = false; if (!allergens.isEmpty()) { crustaceans = true; } allergens = parts[9]; boolean lupines = false; if (!allergens.isEmpty()) { lupines = true; } allergens = parts[10]; boolean milk = false; if (!allergens.isEmpty()) { milk = true; } allergens = parts[11]; boolean nuts = false; if (!allergens.isEmpty()) { nuts = true; } allergens = parts[12]; boolean sulfurDioxideAndSulfite = false; if (!allergens.isEmpty()) { sulfurDioxideAndSulfite = true; } allergens = parts[13]; boolean celeriac = false; if (!allergens.isEmpty()) { celeriac = true; } allergens = parts[14]; boolean mustards = false; if (!allergens.isEmpty()) { mustards = true; } allergens = parts[15]; boolean sesame = false; if (!allergens.isEmpty()) { sesame = true; } allergens = parts[16]; boolean soy = false; if (!allergens.isEmpty()) { soy = true; } allergens = parts[17]; boolean molluscs = false; if (!allergens.isEmpty()) { molluscs = true; } String additives = parts[18]; boolean antioxidant = false; if (!additives.isEmpty()) { antioxidant = true; } additives = parts[19]; boolean artificialColours = false; if (!additives.isEmpty()) { artificialColours = true; } additives = parts[20]; boolean flavourEnhancer = false; if (!additives.isEmpty()) { flavourEnhancer = true; } additives = parts[21]; boolean preservatives = false; if (!additives.isEmpty()) { preservatives = true; } additives = parts[22]; boolean nitrate = false; if (!additives.isEmpty()) { nitrate = true; } additives = parts[23]; boolean picklingSalt = false; if (!additives.isEmpty()) { picklingSalt = true; } additives = parts[24]; boolean phosphate = false; if (!additives.isEmpty()) { phosphate = true; } additives = parts[25]; boolean artificialSweetener = false; if (!additives.isEmpty()) { artificialSweetener = true; } menueList.add(new Menue(date, dish, sideDish, typ, eggs, peanuts, fish, grains, crustaceans, lupines, milk, nuts, sulfurDioxideAndSulfite, celeriac, mustards, sesame, soy, molluscs, antioxidant, artificialColours, flavourEnhancer, preservatives, nitrate, picklingSalt, artificialSweetener, phosphate)); } return menueList; } /** * readOrder() is a method to split order.txt into lines and save them in an arraylist * * @return Arraylist orderlist * @author Madeleine Vigier, Sabine Gubitz * @version 1.2 */ public ArrayList readOrder() { ArrayList orderList = new ArrayList<>(); List rows = getRows(); 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 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)) } 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 */ public void writeData(String pathWrite, ArrayList listToWrite) { if (pathWrite.equals("users.txt")) { } else if (pathWrite.equals("orders.txt")) { } } /** * The method gets the rows by reading all lines of the path * * @return ArrayList rows * @author Madeleine Vigier * @version 1.0 */ private List getRows() { Path path = Paths.get(pathRead); List rows = new ArrayList<>(); try { rows = Files.readAllLines(path); } catch (IOException e) { e.printStackTrace(); } return rows; } }