/** * Allocates a word in the dictionary * @param word The word to add */ protected void putWord(String word) { String code = getCode(word); Vector list = (Vector) mainDictionary.get(code); if (list != null) { list.addElement(word); } else { list = new Vector(); list.addElement(word); mainDictionary.put(code, list); } }
/** * Returns true if the word is correctly spelled against the current word list. */ public boolean isCorrect(String word) { List possible = getWords(getCode(word)); if (possible.contains(word)) return true; //JMH should we always try the lowercase version. If I dont then capitalized //words are always returned as incorrect. else if (possible.contains(word.toLowerCase())) return true; return false; } }
/** * Allocates a word, if it is not already present in the dictionary. A word * with a different case is considered the same. * @param word The word to add */ protected void putWordUnique(String word) { String code = getCode(word); Vector list = (Vector) mainDictionary.get(code); if (list != null) { boolean isAlready = false; for (int i = 0; i < list.size(); i++) { if (word.equalsIgnoreCase((String) list.elementAt(i))) { isAlready = true; break; } } if (!isAlready) list.addElement(word); } else { list = new Vector(); list.addElement(word); mainDictionary.put(code, list); } }