Guest User

Untitled

a guest
Jul 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class Person implements Comaparable<Person> {
  2. public Person(String name, int age) {
  3. this.name = name;
  4. this.age = age;
  5. }
  6. public String getName() { return this.name; }
  7. public int getAge() { return this.age; }
  8. /** Sorts Person objects by name, then age */
  9. public int compareTo() {
  10. // image a reasonable compareTo implemementation
  11. }
  12. }
  13.  
  14. // Some version of Java with no Comparable (and also assuming no Comparator, either)
  15. public class SomeService {
  16.  
  17. public List<Person> queryPeople(boolean sort) {
  18. List<People> people = findPeople();
  19. if (sort) {
  20. Collections.sort(people);
  21. }
  22. return people;
  23. }
  24. }
Add Comment
Please, Sign In to add comment