private static string GetCollationQuery(String origQuery, java.util.List /*<SpellCheckCorrection>*/ corrections) { var collation = new java.lang.StringBuilder(origQuery); int offset = 0; for (var iter = corrections.iterator(); iter.hasNext();) { SpellCheckCorrection correction = (SpellCheckCorrection)iter.next(); Token tok = correction.getOriginal(); // we are replacing the query in order, but injected terms might cause // illegal offsets due to previous replacements. if (tok.getPositionIncrement() == 0) { continue; } collation.replace(tok.startOffset() + offset, tok.endOffset() + offset, correction.getCorrection()); offset += correction.getCorrection().Length - (tok.endOffset() - tok.startOffset()); } return(collation.toString()); }