private Node addRec(final CharSequence s,final int offset,final int length,final Node e){
  if (e == null) {
    modified=true;
    size++;
    return new Node(s,offset,length,true,1);
  }
  char c;
  int i;
  Node n=null;
  final char[] path=e.path;
  for (i=0; i < path.length - 1; i++) {
    c=s.charAt(offset + i);
    if (c < path[i]) {
      n=new Node(path,0,i + 1,false,e.numNodes + 1);
      n.middle=e;
      e.removePathPrefix(i + 1);
      n.left=addRec(s,offset + i,length - i,null);
      break;
    }
 else     if (c > path[i]) {
      n=new Node(path,0,i + 1,false,e.numNodes + 1);
      n.middle=e;
      e.removePathPrefix(i + 1);
      n.right=addRec(s,offset + i,length - i,null);
      break;
    }
 else {
      if (i == length - 1) {
        n=new Node(s,offset,length,true,e.numNodes + 1);
        n.middle=e;
        e.removePathPrefix(length);
        size++;
        modified=true;
        break;
      }
    }
  }
  if (i < path.length - 1)   return n;
  c=s.charAt(offset + i);
  if (c < path[i]) {
    e.left=addRec(s,offset + i,length - i,e.left);
    if (modified)     e.numNodes++;
  }
 else   if (c > path[i]) {
    e.right=addRec(s,offset + i,length - i,e.right);
    if (modified)     e.numNodes++;
  }
 else {
    if (i == length - 1) {
      if (modified=!e.isWord) {
        e.numNodes++;
        size++;
      }
      e.isWord=true;
    }
 else {
      e.middle=addRec(s,offset + i + 1,length - i - 1,e.middle);
      if (modified)       e.numNodes++;
    }
  }
  return e;
}

private Node addRec ( final CharSequence s , final int offset , final int length , final Node e ) { if ( e == null ) { modified = true ; size ++ ; return new Node ( s , offset , length , true , 1 ) ; } char c ; int i ; Node n = null ; final char [ ] path = e . path ; for ( i = 0 ; i < path . length - 1 ; i ++ ) { c = s . charAt ( offset + i ) ; if ( c < path [ i ] ) { n = new Node ( path , 0 , i + 1 , false , e . numNodes + 1 ) ; n . middle = e ; e . removePathPrefix ( i + 1 ) ; n . left = addRec ( s , offset + i , length - i , null ) ; break ; } else if ( c > path [ i ] ) { n = new Node ( path , 0 , i + 1 , false , e . numNodes + 1 ) ; n . middle = e ; e . removePathPrefix ( i + 1 ) ; n . right = addRec ( s , offset + i , length - i , null ) ; break ; } else { if ( i == length - 1 ) { n = new Node ( s , offset , length , true , e . numNodes + 1 ) ; n . middle = e ; e . removePathPrefix ( length ) ; size ++ ; modified = true ; break ; } } } if ( i < path . length - 1 ) return n ; c = s . charAt ( offset + i ) ; if ( c < path [ i ] ) { e . left = addRec ( s , offset + i , length - i , e . left ) ; if ( modified ) e . numNodes ++ ; } else if ( c > path [ i ] ) { e . right = addRec ( s , offset + i , length - i , e . right ) ; if ( modified ) e . numNodes ++ ; } else { if ( i == length - 1 ) { if ( modified = ! e . isWord ) { e . numNodes ++ ; size ++ ; } e . isWord = true ; } else { e . middle = addRec ( s , offset + i + 1 , length - i - 1 , e . middle ) ; if ( modified ) e . numNodes ++ ; } } return e ; }
inserts the given character sequence , starting at the given position , in the given subtree .
