/** Return true if the content model could match an empty input stream. */ public boolean empty() { switch (type) { case '*': case '?': return true; case '+': case '|': for (ContentModel m = (ContentModel) content; m != null; m = m.next) { if (m.empty()) { return true; } } return false; case ',': case '&': for (ContentModel m = (ContentModel) content; m != null; m = m.next) { if (!m.empty()) { return false; } } return true; default: return false; } }
/** Return true if the token could potentially be the first token in the input stream. */ public boolean first(Object token) { switch (type) { case '*': case '?': case '+': return ((ContentModel) content).first(token); case ',': for (ContentModel m = (ContentModel) content; m != null; m = m.next) { if (m.first(token)) { return true; } if (!m.empty()) { return false; } } return false; case '|': case '&': { Element e = (Element) token; if (valSet == null) { valSet = new boolean[Element.maxIndex + 1]; val = new boolean[Element.maxIndex + 1]; // All Element instances are created before this ever executes } if (valSet[e.index]) { return val[e.index]; } for (ContentModel m = (ContentModel) content; m != null; m = m.next) { if (m.first(token)) { val[e.index] = true; break; } } valSet[e.index] = true; return val[e.index]; } default: return (content == token); // PENDING: refer to comment in ContentModelState /* if (content == token) { return true; } Element e = (Element)content; if (e.omitStart() && e.content != null) { return e.content.first(token); } return false; */ } }
/** Update elemVec with the list of elements that are part of the this contentModel. */ public void getElements(Vector<Element> elemVec) { switch (type) { case '*': case '?': case '+': ((ContentModel) content).getElements(elemVec); break; case ',': case '|': case '&': for (ContentModel m = (ContentModel) content; m != null; m = m.next) { m.getElements(elemVec); } break; default: elemVec.addElement((Element) content); } }