Example #1
0
  private static List<FoodSchedule> schedule(
      List<String> breakfastParticipants,
      List<String> snackParticipants,
      List<DateTime> fridaysAvailable) {
    // shuffle both lists
    Collections.shuffle(breakfastParticipants);
    List<String> modifiableBreakfast = new ArrayList<String>(breakfastParticipants);
    Collections.shuffle(snackParticipants);
    List<String> modifiableSnack = new ArrayList<String>(snackParticipants);

    // while not empty, schedule
    int participantCount = breakfastParticipants.size();

    List<FoodSchedule> schedule = new ArrayList<FoodSchedule>();
    for (int i = 0; i < participantCount; i += 2) {
      String bp1 = modifiableBreakfast.remove(0);
      String bp2 = modifiableBreakfast.remove(0);
      String sp1 = modifiableSnack.remove(0);
      String sp2 = modifiableSnack.remove(0);
      DateTime friday = fridaysAvailable.remove(0);
      FoodSchedule fs = new FoodSchedule();
      fs.setDateTime(friday);
      fs.setBreakfastParticipantIds(Arrays.asList(bp1, bp2));
      fs.setSnackParticipantIds(Arrays.asList(sp1, sp2));
      schedule.add(fs);
    }
    return schedule;
  }