class WordCount implements Comparable { String word; Integer count; public WordCount(String w, Integer c) { word = w; count = c; } public String getWord() { return word; } public Integer getCount() { return count; } /** * The natural ordering for instances of this class is lexicographic * based on the value of the word string. * * This method is consistent with equals. */ public int compareTo(WordCount entry) { return entry.getWord().compareTo(word); } @Override public boolean equals(Object o) { if (!(o instanceof WordCount)) return false; WordCount entry = (WordCount)o; return word.equals(entry.word); } @Override public int hashCode() { return word.hashCode(); } }