Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student{
- ....
- private StudentUnion;
- ....
- }
- public class StudentUnionComparator implements Comparator<StudentUnion>{
- public int compare(StudentUnion s1, StudentUnion s2){
- ....
- return result // 1 or 0;
- }
- }
- public class StudentUnion implements Comparable<StudentUnion> {
- public int compareTo(StudentUnion s) {
- ....
- return result // 1 or 0;
- }
- }
- public class Student implements Comparable<Student> {
- public int compareTo(Student s) {
- int result = studentUnion.compareTo(s.studentUnion);
- if (result != 0)
- return result;
- // use another field like name to break ties on StudentUnion
- return name.compareTo(name);
- }
- }
- public class StudentComparator implements Comparator<Student> {
- public int compare(Student s1, Student s2) {
- return s1.getStudentUnion().compareTo(s2.getStudentUnion();
- }
- }
- public class CommonComparator implements Comparator<Object> {
- public int compare(Object s1, Object s2){
- ....
- return result // 1 or 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement