Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public Comparator<RideMatchInfo> getComparator() {
  2.  
  3. switch(user.preferredMatch) {
  4.  
  5. case CHEAPER:
  6. return new Comparator<RideMatchInfo>() {
  7.  
  8. @Override
  9. public int compare(RideMatchInfo o1, RideMatchInfo o2) {
  10.  
  11. if(o1.getCost() < o2.getCost())
  12. return -1;
  13. else
  14. return 1;
  15.  
  16. }
  17. };
  18.  
  19. case CLOSER:
  20. return new Comparator<RideMatchInfo>() {
  21.  
  22. @Override
  23. public int compare(RideMatchInfo o1, RideMatchInfo o2) {
  24.  
  25. Location driverloc, riderloc;
  26.  
  27. driverloc = o1.getWhere(RideRole.DRIVER);
  28. riderloc = o1.getWhere(RideRole.PASSENGER);
  29. double dist1 = Math.sqrt( (driverloc.getX()-riderloc.getX()) * (driverloc.getX()-riderloc.getX())
  30. + (driverloc.getY()-riderloc.getY()) * (driverloc.getY()-riderloc.getY()) );
  31.  
  32. driverloc = o2.getWhere(RideRole.DRIVER);
  33. riderloc = o2.getWhere(RideRole.PASSENGER);
  34. double dist2 = Math.sqrt( (driverloc.getX()-riderloc.getX()) * (driverloc.getX()-riderloc.getX())
  35. + (driverloc.getY()-riderloc.getY()) * (driverloc.getY()-riderloc.getY()) );
  36.  
  37. if(dist1 < dist2)
  38. return -1;
  39. else
  40. return 1;
  41. }
  42. };
  43.  
  44. default: //Better rating
  45. return new Comparator<RideMatchInfo>() {
  46.  
  47. @Override
  48. public int compare(RideMatchInfo o1, RideMatchInfo o2) {
  49.  
  50. float stars1,stars2;
  51. stars1 = o1.getStars(RideRole.PASSENGER) + o1.getStars(RideRole.DRIVER);
  52. stars2 = o2.getStars(RideRole.PASSENGER) + o2.getStars(RideRole.DRIVER);
  53.  
  54. if(stars1 < stars2)
  55. return -1;
  56. else
  57. return 1;
  58.  
  59. }
  60. };
  61.  
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement