private List generatePersonList()

in use-cases/vaccination-scheduling/src/main/java/org/acme/vaccinationscheduler/bootstrap/DemoDataGenerator.java [169:227]


    private List<Person> generatePersonList(Random random,
            LocalDate windowStartDate, int windowDaysLength, double pinnedAppointmentRatio,
            List<VaccineType> vaccineTypeList, List<VaccinationCenter> vaccinationCenterList,
            List<Appointment> appointmentList) {
        int personListSize = appointmentList.size() * 6 / 5; // 20% too many
        List<Person> personList = new ArrayList<>(personListSize);
        long personId = 0L;
        DistanceCalculator distanceCalculator = new EuclideanDistanceCalculator();
        List<Appointment> shuffledAppointmentList;
        int pinnedAppointmentSize;
        if (pinnedAppointmentRatio <= 0.0) {
            shuffledAppointmentList = null;
            pinnedAppointmentSize = 0;
        } else {
            LocalDate windowEndDate = windowStartDate.plusDays(windowDaysLength - 1);
            shuffledAppointmentList = appointmentList.stream()
                    .filter(appointment -> appointment.getDateTime().toLocalDate().isBefore(windowEndDate))
                    .collect(Collectors.toList());
            Collections.shuffle(shuffledAppointmentList, random);
            pinnedAppointmentSize = Math.min((int) (appointmentList.size() * pinnedAppointmentRatio),
                    shuffledAppointmentList.size());
        }
        for (int i = 0; i < personListSize; i++) {
            int lastNameI = i / PERSON_FIRST_NAMES.length;
            String name = PERSON_FIRST_NAMES[i % PERSON_FIRST_NAMES.length]
                    + " " + (lastNameI < 26 ? ((char) ('A' + lastNameI)) + "." : lastNameI - 25);
            Location location = pickLocation(random);
            LocalDate birthdate = MINIMUM_BIRTH_DATE.plusDays(random.nextInt(BIRTH_DATE_RANGE_LENGTH));
            int age = (int) YEARS.between(birthdate, windowStartDate);
            boolean healthcareWorker = random.nextDouble() < 0.05;
            if (healthcareWorker) {
                name = "Dr. " + name;
            }
            long priorityRating = age + (healthcareWorker ? 1_000 : 0);
            boolean firstDoseInjected = random.nextDouble() < 0.25;
            Person person;
            if (!firstDoseInjected) {
                person = new Person(Long.toString(personId++), name, location, birthdate, priorityRating);
            } else {
                VaccineType firstDoseVaccineType = pickVaccineType(random, age, vaccineTypeList);
                VaccinationCenter preferredVaccinationCenter = (random.nextDouble() > 0.10) ? null
                        : vaccinationCenterList.stream()
                        .sorted(Comparator.comparing(vc -> distanceCalculator.calculateDistance(location, vc.getLocation())))
                        .skip(1).findFirst().orElse(null);
                LocalDate idealDate = windowStartDate.plusDays(random.nextInt(windowDaysLength));
                LocalDate readyDate = idealDate.minusDays(2);
                LocalDate dueDate = idealDate.plusDays(windowDaysLength - 2);
                person = new Person(Long.toString(personId++), name, location, birthdate, priorityRating,
                        2, firstDoseVaccineType, null, null, preferredVaccinationCenter, readyDate, idealDate, dueDate);

            }
            if (i < pinnedAppointmentSize) {
                person.setAppointment(shuffledAppointmentList.get(i));
                person.setPinned(true);
            }
            personList.add(person);
        }
        return personList;
    }