#340 Grouping Users by Registration Date

Companies:
Aston
Themes:
JavaStreams & LambdasPractice

Group the List<User> data by user registration date (registrationDate):

  1. Users registered at the same time must be placed in a List<User>
  2. The final result must be the data structure Map<LocalDateTime, List<User>>
public class Main {

    public static void main(String[] args) throws InterruptedException {
        var users = List.of(
                User.of("jerry-Smith_43", "Jerry", "Smith", LocalDateTime.of(2020, 7, 23, 17, 30), List.of(Role.of("USER", List.of("READ", "CREATE", "UPDATE")))),
                User.of("rick-sunches-the-best-15", "Rick", "Sunches", LocalDateTime.of(2020, 7, 23, 17, 30), List.of(Role.of("ADMIN", List.of("READ", "CREATE", "UPDATE", "DELETE")))),
                User.of("mortyEvil", "Morty", "Smith Evil", LocalDateTime.of(2021, 8, 17, 20, 30), List.of(Role.of("ADMIN", List.of("READ", "CREATE", "UPDATE", "DELETE")))));
        ...
    }
}

@AllArgsConstructor(staticName = "of")
@Data
public class User {

    private String username;

    private String firstName;

    private String lastName;

    private LocalDateTime registrationDate;

    private List<Role> roles;

}

@AllArgsConstructor(staticName = "of")
@Data
public class Role {

    private String roleName;

    private List<String> privileges;

}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in