public TemplateModelIterator iterator() {
final ArrayList matchingInputParts = this.matchingInputParts;
if (matchingInputParts == null) {
final Matcher matcher = pattern.matcher(input);
return new TemplateModelIterator() {
private int nextIdx = 0;
boolean hasFindInfo = matcher.find();
public boolean hasNext() {
final ArrayList matchingInputParts = RegexMatchModel.this.matchingInputParts;
if (matchingInputParts == null) {
return hasFindInfo;
} else {
return nextIdx < matchingInputParts.size();
}
}
public TemplateModel next() throws TemplateModelException {
final ArrayList matchingInputParts = RegexMatchModel.this.matchingInputParts;
if (matchingInputParts == null) {
if (!hasFindInfo) throw new _TemplateModelException("There were no more matches");
MatchWithGroups result = new MatchWithGroups(input, matcher);
nextIdx++;
hasFindInfo = matcher.find();
return result;
} else {
try {
return (TemplateModel) matchingInputParts.get(nextIdx++);
} catch (IndexOutOfBoundsException e) {
throw new _TemplateModelException(e, "There were no more matches");
}
}
}
};
} else {
return new TemplateModelIterator() {
private int nextIdx = 0;
public boolean hasNext() {
return nextIdx < matchingInputParts.size();