fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class University implements Serializable {
  8. private List<Student> values = new ArrayList<Student>();
  9.  
  10. public static final class Student implements Serializable {
  11. private int id;
  12. private String name;
  13. private String location;
  14. private Date date;
  15.  
  16. public String getName() { return name; }
  17. public int getId() { return id; }
  18.  
  19. Student(int id, String name, String location, Date date) {
  20. this.id = id;
  21. this.name = name;
  22. this.location = location;
  23. this.date = date;
  24. }
  25.  
  26. // Problem occurs even with getters!!
  27. }
  28. }
  29.  
  30. class Invoker implements Serializable {
  31. public static void main(String[] args) {
  32. List<University.Student> students = new ArrayList<>();
  33.  
  34. Map<String, Integer> locationOrder = students.stream().collect(HashMap::new,
  35. (m, s) -> m.putIfAbsent(s.getName(), m.size()),
  36. (m1, m2) -> m2.keySet().forEach(l -> m1.putIfAbsent(l, m1.size())));
  37.  
  38. students.sort(Comparator.comparingInt((University.Student s) -> locationOrder.get(s.getName())).thenComparing(s -> s.getId()));
  39. }
  40. }
  41.  
Success #stdin #stdout 0.24s 33868KB
stdin
Standard input is empty
stdout
Standard output is empty