public Concordance getConcordance(Pattern p, int win){
return getConcordance(new Pattern[]{p}, win);
}
public Concordance getConcordance(Pattern[] p, int win){
Concordance conc = new ConcordanceImpl(win);
Set<Integer> startingIndices = getMatchStartingIndices(p);
int tot = size();
for (Integer start : startingIndices) {
Token middle = null;
if (p.length > 1)
middle = createSingleFakeToken(start, start+p.length);
else
middle = get(start);
int st = Math.max(0, start-win);
TokenList leftTL = new TokenListImpl();
if (st != start){ // can go further left
for (int ii = st; ii < start; ii++)
leftTL.add(get(ii));
}
int end = Math.min(tot, start+p.length+win);
TokenList rightTL = new TokenListImpl();
if (end != start+p.length){ // can go further right
for (int ii = start+p.length; ii < end; ii++)
rightTL.add(get(ii));
}
ConcordanceLine line = new ConcordanceLineImpl(leftTL, middle, rightTL);
conc.addLine(line);
}
return conc;
}