fork download
  1. import java.time.LocalDate;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Comparator;
  6. import java.util.List;
  7. import java.util.function.Function;
  8. import java.util.stream.Collectors;
  9.  
  10. public class Main {
  11. public static void main(String[] args) throws Exception {
  12. List<NotificationCnavOP> notificationCnavOPList = new ArrayList<>(
  13. Arrays.asList(
  14. new NotificationCnavOP(1, "01/01/2000", 1),
  15. new NotificationCnavOP(2, "01/01/2001", 2),
  16. new NotificationCnavOP(2, "01/01/2002", 3),
  17. new NotificationCnavOP(2, "01/01/2001", 2)));
  18.  
  19. List<NotificationCnavOP> result =
  20. notificationCnavOPList
  21. .stream()
  22. .sorted(Comparator.comparing(NotificationCnavOP::getId)
  23. .thenComparing(e -> LocalDate.parse(e.getDate(), DateTimeFormatter.ofPattern("dd/MM/yyyy")))
  24. .thenComparing(NotificationCnavOP::getCxalap))
  25. .collect(Collectors.toMap(NotificationCnavOP::getId, Function.identity(), (e1, e2) -> e1))
  26. .values()
  27. .stream()
  28. .collect(Collectors.toList());
  29.  
  30. System.out.println(result);
  31. }
  32. }
  33.  
  34. class NotificationCnavOP {
  35. private int id;
  36. private String date;
  37. private int cxalap;
  38.  
  39. public NotificationCnavOP(int id, String date, int cxalap) {
  40. this.id = id;
  41. this.date = date;
  42. this.cxalap = cxalap;
  43. }
  44.  
  45. public int getId() {
  46. return id;
  47. }
  48.  
  49. public String getDate() {
  50. return date;
  51. }
  52.  
  53. public int getCxalap() {
  54. return cxalap;
  55. }
  56.  
  57. @Override
  58. public String toString() {
  59. return "[" + id + ", " + date + ", " + cxalap + "]";
  60. }
  61. }
Success #stdin #stdout 0.2s 56916KB
stdin
Standard input is empty
stdout
[[1, 01/01/2000, 1], [2, 01/01/2001, 2]]