/** * scans textfile and returns and ArrayList of Meals * * @param path - path of the textfile * @return ArrayList of Meals */ public ArrayList<Meal> loadMeal(String path) { // ArrayList<Meal> mealList = new ArrayList<Meal>(); File file = new File(path); try { Scanner in = new Scanner(file); while (in.hasNext()) { String line = in.nextLine(); String[] m = line.split(","); Boolean courseExists = false; Boolean mealExists = false; if (m.length == 3) { m[0] = m[0].toLowerCase().trim(); m[1] = m[1].toLowerCase().trim(); int order = Integer.parseInt(m[2].trim()); // check if course exists for (Course course : courseList) { if (course.getName().equals(m[0])) { for (Meal meal : mealList) { if (meal.course.getName().equals(m[0]) && meal.getOrder() == order && meal.getMealType().equals(m[1])) { System.out.println(meal.course.getName() + " restriction already exist"); mealExists = true; break; } } System.out.println("!"); courseExists = true; // if(doesMealExists(m[1],course)){ // System.out.println(m[1]+" is "+m[0]); // } if (!mealExists) { Meal meal = new Meal(); meal.setMealType(m[1]); meal.addCourse(course); meal.setOrder(order); mealList.add(meal); } break; } } if (!courseExists) { System.out.println("the course: " + m[0] + " doesnt exist"); } } } in.close(); } catch (Exception ex) { ex.printStackTrace(); } return mealList; }