@NotThreadSafe public class TokenStream extends Object
| 限定符和类型 | 类和说明 |
|---|---|
protected class |
TokenStream.CaseInsensitiveToken
An immutable
TokenStream.Token that implements matching using case-insensitive logic. |
class |
TokenStream.CaseInsensitiveTokenFactory
An implementation of
TokenStream.Tokens that creates TokenStream.CaseInsensitiveToken objects. |
protected class |
TokenStream.CaseSensitiveToken
An immutable
TokenStream.Token that implements matching using case-sensitive logic. |
class |
TokenStream.CaseSensitiveTokenFactory
An implementation of
TokenStream.Tokens that creates TokenStream.CaseSensitiveToken objects. |
static class |
TokenStream.CharacterArrayStream
An implementation of
TokenStream.CharacterStream that works with a single character array. |
static interface |
TokenStream.CharacterStream
Interface used by a
TokenStream.Tokenizer to iterate through the characters in the content input
to the TokenStream. |
static class |
TokenStream.Marker
An opaque marker for a position within the token stream.
|
static interface |
TokenStream.Token
The interface defining a token, which references the characters in the actual input character
stream.
|
protected class |
TokenStream.TokenFactory
An implementation of
TokenStream.Tokens that creates TokenStream.CaseSensitiveToken objects. |
static interface |
TokenStream.Tokenizer
Interface for a Tokenizer component responsible for processing the characters in a
TokenStream.CharacterStream and constructing the appropriate TokenStream.Token objects. |
static interface |
TokenStream.Tokens
A factory for Token objects, used by a
TokenStream.Tokenizer to create tokens in the correct
order. |
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
ANY_TYPE |
static String |
ANY_VALUE |
protected String |
inputString |
| 构造器和说明 |
|---|
TokenStream(String content,
TokenStream.Tokenizer tokenizer,
boolean caseSensitive) |
| 限定符和类型 | 方法和说明 |
|---|---|
String |
consume()
Return the value of this token and move to the next token.
|
boolean |
hasNext()
Determine if this stream has another token to be consumed.
|
protected List<TokenStream.Token> |
initializeTokens(List<TokenStream.Token> tokens)
Method to allow subclasses to pre-process the set of tokens and return the correct tokens to
use.
|
TokenStream.Marker |
mark()
Obtain a marker that records the current position so that the stream can be
rewind(Marker) back to the mark even after having been advanced beyond the mark. |
boolean |
matches(int type,
String expected)
Determine if the current token matches the expected type and a value.
|
boolean |
matches(String expected)
Determine if the current token matches the expected value.
|
boolean |
matchesAnyOf(String[] options)
Determine if the next token matches one of the supplied values.
|
String |
peek() |
boolean |
rewind(TokenStream.Marker marker)
Reset the stream back to the position described by the supplied marker.
|
TokenStream |
start()
Begin the token stream, including (if required) the tokenization of the input content.
|
protected void |
throwNoMoreContent() |
String |
toString() |
public static final int ANY_TYPE
protected final String inputString
public TokenStream(String content, TokenStream.Tokenizer tokenizer, boolean caseSensitive)
public TokenStream start() throws ParsingException
ParsingException - if an error occurs during tokenization of the contentprotected List<TokenStream.Token> initializeTokens(List<TokenStream.Token> tokens)
tokens - the tokenspublic TokenStream.Marker mark()
rewind(Marker) back to the mark even after having been advanced beyond the mark.IllegalStateException - if this method was called before the stream was startedNoSuchElementException - if there are no more tokenspublic boolean rewind(TokenStream.Marker marker)
marker - the markerpublic String consume() throws ParsingException, IllegalStateException
ParsingException - if there is no such token to consumeIllegalStateException - if this method was called before the stream was startedprotected void throwNoMoreContent()
throws ParsingException
ParsingExceptionpublic String peek() throws IllegalStateException
public boolean matches(String expected) throws IllegalStateException
The ANY_VALUE constant can be used as a wildcard.
expected - the expected value of the current tokenIllegalStateException - if this method was called before the stream was startedpublic boolean matches(int type,
String expected)
throws IllegalStateException
The ANY_VALUE constant can be used as a wildcard.
type - the expected type of the curent tokenexpected - the expected value of the current tokenIllegalStateException - if this method was called before the stream was startedpublic boolean matchesAnyOf(String[] options) throws IllegalStateException
options - the options for the value of the current tokenIllegalStateException - if this method was called before the stream was startedpublic boolean hasNext()
IllegalStateException - if this method was called before the stream was startedCopyright © 2025 The Apache Software Foundation. All rights reserved.