Advertisement
Guest User

Untitled

a guest
Nov 26th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public class Student{
  2. ....
  3. private StudentUnion;
  4. ....
  5. }
  6.  
  7. public class StudentUnionComparator implements Comparator<StudentUnion>{
  8. public int compare(StudentUnion s1, StudentUnion s2){
  9. ....
  10. return result // 1 or 0;
  11. }
  12. }
  13.  
  14. public class StudentUnion implements Comparable<StudentUnion> {
  15.  
  16. public int compareTo(StudentUnion s) {
  17. ....
  18. return result // 1 or 0;
  19. }
  20. }
  21.  
  22. public class Student implements Comparable<Student> {
  23. public int compareTo(Student s) {
  24. int result = studentUnion.compareTo(s.studentUnion);
  25. if (result != 0)
  26. return result;
  27. // use another field like name to break ties on StudentUnion
  28. return name.compareTo(name);
  29. }
  30. }
  31.  
  32. public class StudentComparator implements Comparator<Student> {
  33. public int compare(Student s1, Student s2) {
  34. return s1.getStudentUnion().compareTo(s2.getStudentUnion();
  35. }
  36. }
  37.  
  38. public class CommonComparator implements Comparator<Object> {
  39. public int compare(Object s1, Object s2){
  40. ....
  41. return result // 1 or 0;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement