T
- the type of token to be parsedpublic class CharSequenceTokenScanner<T> extends java.lang.Object
If token representations are allowed to be longer than one character, each representation must be separated by one ore more whitespace characters.
Constructor and Description |
---|
CharSequenceTokenScanner(java.lang.CharSequence sequence,
TokenSet<T> tokenSet,
boolean allowWhitespace,
T defaultToken)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Indicates whether an additional token can be parsed with the next call of
next() . |
boolean |
isDefaultTokenUsed()
Indicates whether a string representation not found in the token set was replaced by the default token in any call
of
next() until now. |
boolean |
isDefaultTokenUsedNow()
Indicates whether a string representation not found in the token set was replaced by the default token in the last
call of
next() . |
T |
next()
Returns the next token from parsed from the underlying character sequence.
|
public CharSequenceTokenScanner(java.lang.CharSequence sequence, TokenSet<T> tokenSet, boolean allowWhitespace, T defaultToken)
sequence
- the sequence to parse tokens fromtokenSet
- the token set containing the tokens to be parsedallowWhitespace
- Specify true
here to allow whitespace between token representations or false
if not. Note that specifying false will lead to a IllegalArgumentException
if the specified token set
contains representations longer than one character.defaultToken
- a default token to be returned if invalid token representations are found (If null
is specified here, next()
will throw an exception if an invalid representation is found.)java.lang.IllegalArgumentException
- if allowWhitespace
was set to false
although tokenSet
contains token representations that are longer than one characterpublic boolean hasNext()
next()
.true
if additional tokens can be parsed or false
if the end of the underlying
character sequence has been reachedpublic T next() throws InvalidTokenRepresentationException
Token representations not found in the underlying token set are replaced by a default token, if one
was specified. Use isDefaultTokenUsedNow()
to determine whether that was the case in the
last call of the method.
null
if the end of the underlying character sequence was reached.InvalidTokenRepresentationException
- if no according token could be found for the current
string representation and no default token was definedpublic boolean isDefaultTokenUsedNow()
next()
.true
if an according replacement happened, false
if no replacement needed to be done until now.isDefaultTokenUsed()
public boolean isDefaultTokenUsed()
next()
until now.true
if an according replacement happened, false
if no replacement needed to be done until now.isDefaultTokenUsedNow()