Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Compares Word objects by their values. Sorts from most to least frequent.
- *
- * @author mimidoan
- * @version 12/9/16
- *
- */
- package project5;
- import java.util.Comparator;
- public class Frequency implements Comparator<Word> {
- @Override
- /**
- * Overrides compare Method to compare Word Objects
- *
- * @return int
- */
- public int compare(Word o1, Word o2) {
- if (o1.getValue() < o2.getValue()) {
- return 1;
- } else if (o1.getValue() > o2.getValue()) {
- return -1;
- } else {
- // compares by alphabetical order if values are the same
- return o1.getKey().compareTo(o2.getKey());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement