import java.util.*; import java.io.*; public class Thesaurus { protected TreeMap> thesaurusMap; /** * Initializes this Thesaurus object. * */ public Thesaurus() { thesaurusMap = new TreeMap>(); } // default constructor /** * Adds a specified line of synonyms to this Thesaurus object. * The worstTime(n) is O(log n). * * @param line - the specified line of synonyms to be added to this * Thesaurus object. * */ public void add (String line) { LinkedList synonymList = new LinkedList(); StringTokenizer st = new StringTokenizer (line); String word = st.nextToken(); while (st.hasMoreTokens()) synonymList.add (st.nextToken()); thesaurusMap.put (word, synonymList); } // method add /** * Finds the LinkedList of synonyms of a specified word in this Thesaurus. * The worstTime(n) is O(log n). * * @param word - the specified word, whose synonyms are to be * returned. * * @return the LinkedList of synonyms of word. * */ public LinkedList getSynonyms (String word) { return thesaurusMap.get (word); } // method getSynonyms } // class Thesaurus