import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.sql.Array; 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 */ 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 */ public ArrayList readMenu() { List rows = getRows(); ArrayList menuList = 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 ingredient = parts[4]; List ingredients = new ArrayList<>(); if (!ingredient.isEmpty()) { ingredients.add("a"); //eggs } ingredient = parts[5]; if (!ingredient.isEmpty()) { ingredients.add("d"); //peanuts } ingredient = parts[6]; if (!ingredient.isEmpty()) { ingredients.add("m"); //fish } ingredient = parts[7]; if (!ingredient.isEmpty()) { ingredients.add("g"); //grains } ingredient = parts[8]; if (!ingredient.isEmpty()) { ingredients.add("f"); //crustaceans } ingredient = parts[9]; if (!ingredient.isEmpty()) { ingredients.add("n"); //lupines } ingredient = parts[10]; if (!ingredient.isEmpty()) { ingredients.add("c"); //milk } ingredient = parts[11]; if (!ingredient.isEmpty()) { ingredients.add("k"); //nuts } ingredient = parts[12]; if (!ingredient.isEmpty()) { ingredients.add("j"); //sulfurDioxideAndSulfite } ingredient = parts[13]; if (!ingredient.isEmpty()) { ingredients.add("l"); //celeriac } ingredient = parts[14]; if (!ingredient.isEmpty()) { ingredients.add("h"); //mustards } ingredient = parts[15]; if (!ingredient.isEmpty()) { ingredients.add("i"); //sesame } ingredient = parts[16]; if (!ingredient.isEmpty()) { ingredients.add("b");//soy } ingredient = parts[17]; if (!ingredient.isEmpty()) { ingredients.add("e");//molluscs } ingredient = parts[18]; if (!ingredient.isEmpty()) { ingredients.add("4"); //antioxidant } ingredient = parts[19]; if (!ingredient.isEmpty()) { ingredients.add("5"); } ingredient = parts[20]; if (!ingredient.isEmpty()) { ingredients.add("6"); //flavourEnhancer } ingredient = parts[21]; if (!ingredient.isEmpty()) { ingredients.add("8"); // preservatives } ingredient = parts[22]; if (!ingredient.isEmpty()) { ingredients.add("3"); //nitrate } ingredient = parts[23]; if (!ingredient.isEmpty()) { ingredients.add("1");//picklingSalt } ingredient = parts[24]; if (!ingredient.isEmpty()) { ingredients.add("7"); //artificialSweetener } ingredient = parts[25]; if (!ingredient.isEmpty()) { ingredients.add("2"); //phosphate } String end = parts[26]; //endpoint menuList.add(new Menu(date, dish, sideDish, typ, ingredients)); } return menuList; } /** * readOrder() is a method to split order.txt into lines and save them in an arraylist * * @return Arraylist orderlist * @author Madeleine Vigier, Sabine Gubitz */ 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]; int meatCount = Integer.parseInt(parts[2]); String vegi = parts[3]; int vegiCount = Integer.parseInt(parts[4]); String vegan = parts[5]; int veganCount = Integer.parseInt(parts[6]); String desertV = parts[7]; int desertVCount = Integer.parseInt(parts[8]); String desert = parts[9]; int desertCount = Integer.parseInt(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 */ private List getRows() { Path path = Paths.get(pathRead); List rows = new ArrayList<>(); try { rows = Files.readAllLines(path); } catch (IOException e) { e.printStackTrace(); } return rows; } }