public class Tokenizer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
DEFAULT_DELIMITERS
The set of delimiters to use, if none are specified
|
Constructor and Description |
---|
Tokenizer(java.lang.String pattern)
Creates a new Tokenizer using the given String and the
default set of delimiters.
|
Tokenizer(java.lang.String pattern,
java.lang.String[] delimiters)
Creates a new Tokenizer using the given String and the
default set of delimiters
|
Modifier and Type | Method and Description |
---|---|
void |
advance(int offset)
Advances the index of this tokenizer ahead by the given offset
|
int |
countTokens()
Counts the number of times nextToken can be called without
returning null
|
int |
getPosition() |
boolean |
hasMoreTokens()
Determines if there are any tokens available
|
boolean |
hasToken(java.lang.String token)
Determines if the specified token is contained in
the token list of this Tokenizer
|
boolean |
isDelimiter(java.lang.String token)
Determines if the specified token is a delimiter for
this Tokenizer
|
java.lang.String |
lookAhead(int offset)
Allows looking ahead for tokens without affecting the
token sequence as called by nextToken or previousToken
|
java.lang.String |
nextToken()
Retrieves the next available token
|
java.lang.String |
previousToken()
Retrieves the previous token
|
void |
resetPosition()
Resets the position of the token pointer to the beginning
|
void |
setPosition(int position)
Sets the current position of this tokenizer.
|
java.lang.String |
toString() |
public static final java.lang.String[] DEFAULT_DELIMITERS
public Tokenizer(java.lang.String pattern)
public Tokenizer(java.lang.String pattern, java.lang.String[] delimiters)
public void advance(int offset)
public int countTokens()
public int getPosition()
public boolean hasMoreTokens()
public boolean hasToken(java.lang.String token)
token
- the String to look for in the token listpublic boolean isDelimiter(java.lang.String token)
token
- the String to compare to the delimiterspublic java.lang.String lookAhead(int offset)
public java.lang.String nextToken()
public java.lang.String previousToken()
public void resetPosition()
public void setPosition(int position)
position
- the index value to set the current position to.
if position is greater than the number of tokens, the tokenizer
is advanced to the end. If the given position is less than 0,
the tokenizer is positioned at the beginningpublic java.lang.String toString()
toString
in class java.lang.Object