Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /**
  2. * Compares Word objects by their values. Sorts from most to least frequent.
  3. *
  4. * @author mimidoan
  5. * @version 12/9/16
  6. *
  7. */
  8. package project5;
  9.  
  10. import java.util.Comparator;
  11.  
  12. public class Frequency implements Comparator<Word> {
  13.  
  14. @Override
  15. /**
  16. * Overrides compare Method to compare Word Objects
  17. *
  18. * @return int
  19. */
  20. public int compare(Word o1, Word o2) {
  21. if (o1.getValue() < o2.getValue()) {
  22. return 1;
  23. } else if (o1.getValue() > o2.getValue()) {
  24. return -1;
  25. } else {
  26. // compares by alphabetical order if values are the same
  27. return o1.getKey().compareTo(o2.getKey());
  28. }
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement