code: private final int getIndexFor(String word) {
          Integer index = termToIndex.get(word);
          if (index == null) {     
              synchronized(this) {
                  // recheck to see if the term was added while blocking
                  index = termToIndex.get(word);
                  // if another thread has not already added this word while the
                  // current thread was blocking waiting on the lock, then add it.
                  if (index == null) {
                      int i = wordIndexCounter++;
                      termToIndex.put(word, i);
                      return i; // avoid the auto-boxing to assign i to index
                  }
              }
          }
          return index;
      }
docs: Returns the index in the co-occurence matrix for this word.  If the word
  was not previously assigned an index, this method adds one for it and
  returns that index.