private List<String> listOfUniversityNames(List<University> universities) {
   List<String> listUniversityNames = new ArrayList<>(universities.size());
   for (University university : universities) {
     listUniversityNames.add(university.getName());
   }
   return listUniversityNames;
 }
 private boolean deleteNonServerUniversity(List<String> incomingUniversityNames) {
   boolean changed = false;
   List<University> mealsInDbAndServer = universityDao.notInNamesList(incomingUniversityNames);
   for (University university : mealsInDbAndServer) {
     universityDao.delete(university.getId());
     changed = true;
   }
   return changed;
 }
  private boolean insertUniversities(
      List<University> mealsInDbAndServer, List<University> serverUniversities) {
    boolean changed = false;
    List<String> dbListNames = listOfUniversityNames(mealsInDbAndServer);

    for (University serverUniversity : serverUniversities) {
      if (!dbListNames.contains(serverUniversity.getName())) {
        universityDao.insert(serverUniversity);
        changed = true;
      }
    }
    return changed;
  }
 public University selectUniversity(University currentUniversity) {
   if (universityDao.count() == 1) {
     currentUniversity = universityDao.fetchAll().get(0);
   } else if (universityDao.count() > 1) {
     if (currentUniversity == null) {
       currentUniversity = universityDao.orderByName().get(0);
     } else {
       // Current University may not exist in the database if it was deleted
       University university = universityDao.findByName(currentUniversity.getName());
       if (university == null) {
         currentUniversity = universityDao.orderByName().get(0);
       }
     }
   }
   return currentUniversity;
 }
  private boolean syncMealsServer(
      List<University> mealsInDbAndServer, List<University> incomingUniversities) {
    boolean changed = false;

    for (University databaseUniversity : mealsInDbAndServer) {
      for (University serverUniversity : incomingUniversities) {
        if (serverUniversity.getName().equals(databaseUniversity.getName())) {
          serverUniversity.setId(databaseUniversity.getId());
        }
      }
    }

    for (University university : incomingUniversities) {
      boolean changedMeal = mealService.syncMeals(university.getMeals(), university);
      if (changedMeal) changed = true;
    }
    return changed;
  }