@Override public void addWord(final String word) { // synchronizing is necessary as this is a write access Set<ISpellDictionary> copy; synchronized (fDictionaries) { copy = new HashSet<>(fDictionaries); } final String addable = word.toLowerCase(); for (final Iterator<ISpellDictionary> iterator = copy.iterator(); iterator.hasNext(); ) { ISpellDictionary dictionary = iterator.next(); if (dictionary.acceptsWords()) dictionary.addWord(addable); } }
@Override public final boolean isCorrect(final String word) { // synchronizing is necessary as this is called from execute Set<ISpellDictionary> copy; synchronized (fDictionaries) { copy = new HashSet<>(fDictionaries); } if (fIgnored.contains(word.toLowerCase())) return true; ISpellDictionary dictionary = null; for (final Iterator<ISpellDictionary> iterator = copy.iterator(); iterator.hasNext(); ) { dictionary = iterator.next(); if (dictionary.isCorrect(word)) return true; } return false; }
@Override public boolean acceptsWords() { // synchronizing might not be needed here since acceptWords is // a read-only access and only called in the same thread as // the modifying methods add/checkWord (?) Set<ISpellDictionary> copy; synchronized (fDictionaries) { copy = new HashSet<>(fDictionaries); } ISpellDictionary dictionary = null; for (final Iterator<ISpellDictionary> iterator = copy.iterator(); iterator.hasNext(); ) { dictionary = iterator.next(); if (dictionary.acceptsWords()) return true; } return false; }
@Override public Set<RankedWordProposal> getProposals(final String word, final boolean sentence) { // synchronizing might not be needed here since getProposals is // a read-only access and only called in the same thread as // the modifing methods add/removeDictionary (?) Set<ISpellDictionary> copy; synchronized (fDictionaries) { copy = new HashSet<>(fDictionaries); } ISpellDictionary dictionary = null; final HashSet<RankedWordProposal> proposals = new HashSet<>(); for (final Iterator<ISpellDictionary> iterator = copy.iterator(); iterator.hasNext(); ) { dictionary = iterator.next(); proposals.addAll(dictionary.getProposals(word, sentence)); } return proposals; }