コード例 #1
0
  @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);
    }
  }
コード例 #2
0
  @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;
  }