1 /*
2 * Copyright (c) 1998, 2000, 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
75 /**
76 * Return the content model that is relevant to the current state.
77 */
78 public ContentModel getModel() {
79 ContentModel m = model;
80 for (int i = 0; i < value; i++) {
81 if (m.next != null) {
82 m = m.next;
83 } else {
84 return null;
85 }
86 }
87 return m;
88 }
89
90 /**
91 * Check if the state can be terminated. That is there are no more
92 * tokens required in the input stream.
93 * @return true if the model can terminate without further input
94 */
95 public boolean terminate() {
96 switch (model.type) {
97 case '+':
98 if ((value == 0) && !(model).empty()) {
99 return false;
100 }
101 case '*':
102 case '?':
103 return (next == null) || next.terminate();
104
105 case '|':
106 for (ContentModel m = (ContentModel)model.content ; m != null ; m = m.next) {
107 if (m.empty()) {
108 return (next == null) || next.terminate();
109 }
110 }
111 return false;
112
113 case '&': {
114 ContentModel m = (ContentModel)model.content;
115
116 for (int i = 0 ; m != null ; i++, m = m.next) {
117 if ((value & (1L << i)) == 0) {
118 if (!m.empty()) {
119 return false;
120 }
|
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
75 /**
76 * Return the content model that is relevant to the current state.
77 */
78 public ContentModel getModel() {
79 ContentModel m = model;
80 for (int i = 0; i < value; i++) {
81 if (m.next != null) {
82 m = m.next;
83 } else {
84 return null;
85 }
86 }
87 return m;
88 }
89
90 /**
91 * Check if the state can be terminated. That is there are no more
92 * tokens required in the input stream.
93 * @return true if the model can terminate without further input
94 */
95 @SuppressWarnings("fallthrough")
96 public boolean terminate() {
97 switch (model.type) {
98 case '+':
99 if ((value == 0) && !(model).empty()) {
100 return false;
101 }
102 // Fall through
103 case '*':
104 case '?':
105 return (next == null) || next.terminate();
106
107 case '|':
108 for (ContentModel m = (ContentModel)model.content ; m != null ; m = m.next) {
109 if (m.empty()) {
110 return (next == null) || next.terminate();
111 }
112 }
113 return false;
114
115 case '&': {
116 ContentModel m = (ContentModel)model.content;
117
118 for (int i = 0 ; m != null ; i++, m = m.next) {
119 if ((value & (1L << i)) == 0) {
120 if (!m.empty()) {
121 return false;
122 }
|