private boolean addWord(String word,SparseVector vec,Integer value){
  Integer indx=wordIndex.get(word);
  if (indx == null) {
    Integer index_for_new_word;
    if ((index_for_new_word=wordIndex.putIfAbsent(word,-1)) == null) {
      index_for_new_word=currentLength.getAndIncrement();
      wordIndex.put(word,index_for_new_word);
    }
    if (index_for_new_word < 0)     return false;
    AtomicInteger termCount=new AtomicInteger(0), tmp=null;
    tmp=termDocumentFrequencys.putIfAbsent(index_for_new_word,termCount);
    if (tmp != null)     termCount=tmp;
    termCount.incrementAndGet();
    int newLen=Math.max(index_for_new_word + 1,vec.length());
    vec.setLength(newLen);
    vec.set(index_for_new_word,value);
  }
 else {
    if (indx < 0)     return false;
    AtomicInteger toInc=termDocumentFrequencys.get(indx);
    if (toInc == null) {
      toInc=termDocumentFrequencys.putIfAbsent(indx,new AtomicInteger(1));
      if (toInc == null)       toInc=termDocumentFrequencys.get(indx);
    }
    toInc.incrementAndGet();
    if (vec.length() <= indx)     vec.setLength(indx + 1);
    vec.set(indx,value);
  }
  return true;
}

private boolean addWord ( String word , SparseVector vec , Integer value ) { Integer indx = wordIndex . get ( word ) ; if ( indx == null ) { Integer index_for_new_word ; if ( ( index_for_new_word = wordIndex . putIfAbsent ( word , - 1 ) ) == null ) { index_for_new_word = currentLength . getAndIncrement ( ) ; wordIndex . put ( word , index_for_new_word ) ; } if ( index_for_new_word < 0 ) return false ; AtomicInteger termCount = new AtomicInteger ( 0 ) , tmp = null ; tmp = termDocumentFrequencys . putIfAbsent ( index_for_new_word , termCount ) ; if ( tmp != null ) termCount = tmp ; termCount . incrementAndGet ( ) ; int newLen = Math . max ( index_for_new_word + 1 , vec . length ( ) ) ; vec . setLength ( newLen ) ; vec . set ( index_for_new_word , value ) ; } else { if ( indx < 0 ) return false ; AtomicInteger toInc = termDocumentFrequencys . get ( indx ) ; if ( toInc == null ) { toInc = termDocumentFrequencys . putIfAbsent ( indx , new AtomicInteger ( 1 ) ) ; if ( toInc == null ) toInc = termDocumentFrequencys . get ( indx ) ; } toInc . incrementAndGet ( ) ; if ( vec . length ( ) <= indx ) vec . setLength ( indx + 1 ) ; vec . set ( indx , value ) ; } return true ; }
does the work to add a given word to the sparse vector . may not succeed in race conditions when two ore more threads are trying to add a word at the same time .
