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.10.2.2 $
21: */package java.util.regex;
22:
23: /**
24: * Represents node accepting single character from the given char class.
25: *
26: * @author Nikolay A. Kuznetsov
27: * @version $Revision: 1.10.2.2 $
28: */
29:
30: class RangeSet extends LeafSet {
31:
32: private AbstractCharClass chars;
33:
34: private boolean alt = false;
35:
36: public RangeSet(AbstractCharClass cs, AbstractSet next) {
37: super (next);
38: this .chars = cs.getInstance();
39: this .alt = cs.alt;
40: }
41:
42: public RangeSet(AbstractCharClass cc) {
43: this .chars = cc.getInstance();
44: this .alt = cc.alt;
45: }
46:
47: public int accepts(int strIndex, CharSequence testString) {
48: return chars.contains(testString.charAt(strIndex)) ? 1 : -1;
49: }
50:
51: protected String getName() {
52: return "range:" + (alt ? "^ " : " ") + chars.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
53: }
54:
55: public boolean first(AbstractSet set) {
56: if (set instanceof CharSet) {
57: return AbstractCharClass.intersects(chars, ((CharSet) set)
58: .getChar());
59: } else if (set instanceof RangeSet) {
60: return AbstractCharClass.intersects(chars,
61: ((RangeSet) set).chars);
62: } else if (set instanceof SupplRangeSet) {
63: return AbstractCharClass.intersects(chars,
64: ((SupplRangeSet) set).getChars());
65: } else if (set instanceof SupplCharSet) {
66: return false;
67: }
68: return true;
69: }
70:
71: protected AbstractCharClass getChars() {
72: return chars;
73: }
74: }
|