01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Nikolay A. Kuznetsov
20: * @version $Revision: 1.4.2.2 $
21: */package java.util.regex;
22:
23: import java.util.ArrayList;
24:
25: /**
26: * This class represent atomic group (?>X), once X matches,
27: * this match become unchangeable till the end of the match.
28: *
29: * @author Nikolay A. Kuznetsov
30: * @version $Revision: 1.4.2.2 $
31: */
32: class AtomicJointSet extends NonCapJointSet {
33:
34: public AtomicJointSet(ArrayList children, FSet fSet) {
35: super (children, fSet);
36: }
37:
38: /**
39: * Returns stringIndex+shift, the next position to match
40: */
41: public int matches(int stringIndex, CharSequence testString,
42: MatchResultImpl matchResult) {
43: int start = matchResult.getConsumed(groupIndex);
44: matchResult.setConsumed(groupIndex, stringIndex);
45:
46: int size = children.size();
47: for (int i = 0; i < size; i++) {
48: AbstractSet e = (AbstractSet) children.get(i);
49: int shift = e.matches(stringIndex, testString, matchResult);
50: if (shift >= 0) {
51: // AtomicFset always returns true, but saves the index to run
52: // this next.match() from;
53: return next.matches(((AtomicFSet) fSet).getIndex(),
54: testString, matchResult);
55: }
56: }
57:
58: matchResult.setConsumed(groupIndex, start);
59: return -1;
60: }
61:
62: public void setNext(AbstractSet next) {
63: this .next = next;
64: }
65:
66: public AbstractSet getNext() {
67: return next;
68: }
69:
70: protected String getName() {
71: return "NonCapJointSet"; //$NON-NLS-1$
72: }
73: }
|