273 public MatchResult toMatchResult() {
274 return toMatchResult(text.toString());
275 }
276
277 private MatchResult toMatchResult(String text) {
278 return new ImmutableMatchResult(this.first,
279 this.last,
280 groupCount(),
281 this.groups.clone(),
282 text);
283 }
284
285 private static class ImmutableMatchResult implements MatchResult {
286 private final int first;
287 private final int last;
288 private final int[] groups;
289 private final int groupCount;
290 private final String text;
291
292 ImmutableMatchResult(int first, int last, int groupCount,
293 int groups[], String text)
294 {
295 this.first = first;
296 this.last = last;
297 this.groupCount = groupCount;
298 this.groups = groups;
299 this.text = text;
300 }
301
302 @Override
303 public int start() {
304 checkMatch();
305 return first;
306 }
307
308 @Override
309 public int start(int group) {
310 checkMatch();
311 if (group < 0 || group > groupCount)
312 throw new IndexOutOfBoundsException("No group " + group);
313 return groups[group * 2];
|
273 public MatchResult toMatchResult() {
274 return toMatchResult(text.toString());
275 }
276
277 private MatchResult toMatchResult(String text) {
278 return new ImmutableMatchResult(this.first,
279 this.last,
280 groupCount(),
281 this.groups.clone(),
282 text);
283 }
284
285 private static class ImmutableMatchResult implements MatchResult {
286 private final int first;
287 private final int last;
288 private final int[] groups;
289 private final int groupCount;
290 private final String text;
291
292 ImmutableMatchResult(int first, int last, int groupCount,
293 int[] groups, String text)
294 {
295 this.first = first;
296 this.last = last;
297 this.groupCount = groupCount;
298 this.groups = groups;
299 this.text = text;
300 }
301
302 @Override
303 public int start() {
304 checkMatch();
305 return first;
306 }
307
308 @Override
309 public int start(int group) {
310 checkMatch();
311 if (group < 0 || group > groupCount)
312 throw new IndexOutOfBoundsException("No group " + group);
313 return groups[group * 2];
|