mardi 24 juillet 2018

How to get random objects from a stream and return it

I have List with some users from google and now in stream I say for every google user make new HRVacationUser ( witch is model ) and give me ( their email, some random date, some random date ) which random date is for random holiday. But in that case i set each user is on vacantion. How can I take random user from google users and set random date for holiday, so I can make a request in the database - give me this user which is in holiday?

public List<HRVacationUser> listVacationGoogleUsers(List<GoogleUser> allGoogleUsers){
        LocalDate date = LocalDate.now();
        List<HRVacationUser> collectHRUser = allGoogleUsers.stream()
                .map(user ->
                        new HRVacationUser(user.getPrimaryEmail(), date.minusDays(ThreadLocalRandom.current().nextInt(1,5)), date.plusDays(ThreadLocalRandom.current().nextInt(1, 5))))
                .collect(toList());
        return collectHRUser;
    }




Aucun commentaire:

Enregistrer un commentaire