code: public void  processDocument(BufferedReader document) throws IOException {
          Queue<String> nextWords = new ArrayDeque<String>();
          Queue<String> prevWords = new ArrayDeque<String>();
  
          Iterator<String> documentTokens =
              IteratorFactory.tokenizeOrdered(document);
  
          String focus = null;
  
          // Rather than updating the matrix every time an occurrence is seen,
          // keep a thread-local count of what needs to be modified in the matrix
          // and update after the document has been processed.  This saves
          // potential contention from concurrent writes.
          Map<Pair<Integer>,Double> matrixEntryToCount =
              new HashMap<Pair<Integer>,Double>();
  
          //Load the first windowSize words into the Queue
          for(int i = 0;  i < windowSize && documentTokens.hasNext(); i++)
              nextWords.offer(documentTokens.next());
  
          while(!nextWords.isEmpty()) {
  
              // Load the top of the nextWords Queue into the focus word
              focus = nextWords.remove();
  
              // Add the next word to nextWords queue (if possible)
              if (documentTokens.hasNext())
                  nextWords.offer(documentTokens.next());
  
              // If the filter does not accept this word, skip the semantic
              // processing, continue with the next word
              if (!focus.equals(IteratorFactory.EMPTY_TOKEN)) {
                  int focusIndex = termToIndex.getDimension(focus);
                  // Only process co-occurrences with words with non-negative
                  // dimensions.
                  if (focusIndex >= 0) {
                      // in front of the focus word
                      int wordDistance = -windowSize + (windowSize - prevWords.size());
                      addTokens(prevWords, focusIndex, wordDistance, matrixEntryToCount);
                  }
              }
  
              // last, put this focus word in the prev words and shift off the
              // front if it is larger than the window
              prevWords.offer(focus);
              if (prevWords.size() > windowSize)
                  prevWords.remove();
          }
  
          // Once the document has been processed, update the co-occurrence matrix
          // accordingly.
          for (Map.Entry<Pair<Integer>,Double> e : matrixEntryToCount.entrySet()){
              Pair<Integer> p = e.getKey();
              cooccurrenceMatrix.addAndGet(p.x, p.y, e.getValue());
          }
      }
docs: {@inheritDoc}