1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
139 */
140 public void getElements(Vector<Element> elemVec) {
141 switch (type) {
142 case '*':
143 case '?':
144 case '+':
145 ((ContentModel)content).getElements(elemVec);
146 break;
147 case ',':
148 case '|':
149 case '&':
150 for (ContentModel m=(ContentModel)content; m != null; m=m.next){
151 m.getElements(elemVec);
152 }
153 break;
154 default:
155 elemVec.addElement((Element)content);
156 }
157 }
158
159 private boolean valSet[];
160 private boolean val[];
161 // A cache used by first(). This cache was found to speed parsing
162 // by about 10% (based on measurements of the 4-12 code base after
163 // buffering was fixed).
164
165 /**
166 * Return true if the token could potentially be the
167 * first token in the input stream.
168 *
169 * @param token the token
170 *
171 * @return {@code true} if the token could potentially be the first token
172 * in the input stream
173 */
174 public boolean first(Object token) {
175 switch (type) {
176 case '*':
177 case '?':
178 case '+':
179 return ((ContentModel)content).first(token);
180
247 }
248 }
249
250 /**
251 * Convert to a string.
252 *
253 * @return the string representation of this {@code ContentModel}
254 */
255 public String toString() {
256 switch (type) {
257 case '*':
258 return content + "*";
259 case '?':
260 return content + "?";
261 case '+':
262 return content + "+";
263
264 case ',':
265 case '|':
266 case '&':
267 char data[] = {' ', (char)type, ' '};
268 String str = "";
269 for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
270 str = str + m;
271 if (m.next != null) {
272 str += new String(data);
273 }
274 }
275 return "(" + str + ")";
276
277 default:
278 return content.toString();
279 }
280 }
281 }
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
139 */
140 public void getElements(Vector<Element> elemVec) {
141 switch (type) {
142 case '*':
143 case '?':
144 case '+':
145 ((ContentModel)content).getElements(elemVec);
146 break;
147 case ',':
148 case '|':
149 case '&':
150 for (ContentModel m=(ContentModel)content; m != null; m=m.next){
151 m.getElements(elemVec);
152 }
153 break;
154 default:
155 elemVec.addElement((Element)content);
156 }
157 }
158
159 private boolean[] valSet;
160 private boolean[] val;
161 // A cache used by first(). This cache was found to speed parsing
162 // by about 10% (based on measurements of the 4-12 code base after
163 // buffering was fixed).
164
165 /**
166 * Return true if the token could potentially be the
167 * first token in the input stream.
168 *
169 * @param token the token
170 *
171 * @return {@code true} if the token could potentially be the first token
172 * in the input stream
173 */
174 public boolean first(Object token) {
175 switch (type) {
176 case '*':
177 case '?':
178 case '+':
179 return ((ContentModel)content).first(token);
180
247 }
248 }
249
250 /**
251 * Convert to a string.
252 *
253 * @return the string representation of this {@code ContentModel}
254 */
255 public String toString() {
256 switch (type) {
257 case '*':
258 return content + "*";
259 case '?':
260 return content + "?";
261 case '+':
262 return content + "+";
263
264 case ',':
265 case '|':
266 case '&':
267 char[] data = {' ', (char)type, ' '};
268 String str = "";
269 for (ContentModel m = (ContentModel)content ; m != null ; m = m.next) {
270 str = str + m;
271 if (m.next != null) {
272 str += new String(data);
273 }
274 }
275 return "(" + str + ")";
276
277 default:
278 return content.toString();
279 }
280 }
281 }
|