All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.kvisco.util.Tokenizer

com.kvisco.util.Tokenizer

public class Tokenizer
Splits a String into tokens using a specified set of String delimiters. Delimeters are searched for in the that they appear in the delimiter list. If one delimiter is part of another delimiter, make sure you add them in the proper order for correct behavoir

Author:
Keith Visco

Variable Index

 o DEFAULT_DELIMITERS
The set of delimiters to use, if none are specified

Constructor Index

 o Tokenizer(String)
Creates a new Tokenizer using the given String and the default set of delimiters.
 o Tokenizer(String, String[])
Creates a new Tokenizer using the given String and the default set of delimiters

Method Index

 o advance(int)
Advances the index of this tokenizer ahead by the given offset
 o countTokens()
Counts the number of times nextToken can be called without returning null
 o getPosition()
 o hasMoreTokens()
Determines if there are any tokens available
 o hasToken(String)
Determines if the specified token is contained in the token list of this Tokenizer
 o isDelimiter(String)
Determines if the specified token is a delimiter for this Tokenizer
 o lookAhead(int)
Allows looking ahead for tokens without affecting the token sequence as called by nextToken or previousToken
 o nextToken()
Retrieves the next available token
 o previousToken()
Retrieves the previous token
 o resetPosition()
Resets the position of the token pointer to the beginning
 o setPosition(int)
Sets the current position of this tokenizer.
 o toString()

Variables

 o DEFAULT_DELIMITERS
 public static final String DEFAULT_DELIMITERS[]
The set of delimiters to use, if none are specified

Constructors

 o Tokenizer
 public Tokenizer(String pattern)
Creates a new Tokenizer using the given String and the default set of delimiters. The default delimiters are: " ", "\n", "\r", and "\t";

 o Tokenizer
 public Tokenizer(String pattern,
                  String delimiters[])
Creates a new Tokenizer using the given String and the default set of delimiters

Methods

 o advance
 public void advance(int offset)
Advances the index of this tokenizer ahead by the given offset

 o countTokens
 public int countTokens()
Counts the number of times nextToken can be called without returning null

 o getPosition
 public int getPosition()
 o hasMoreTokens
 public boolean hasMoreTokens()
Determines if there are any tokens available

Returns:
true if there are tokens available, otherwise false
 o hasToken
 public boolean hasToken(String token)
Determines if the specified token is contained in the token list of this Tokenizer

Parameters:
token - the String to look for in the token list
Returns:
true if the String argument is contained in this Tokenizer's token list, otherwise false
 o isDelimiter
 public boolean isDelimiter(String token)
Determines if the specified token is a delimiter for this Tokenizer

Parameters:
token - the String to compare to the delimiters
Returns:
true if the String argument is a delimiter
 o lookAhead
 public String lookAhead(int offset)
Allows looking ahead for tokens without affecting the token sequence as called by nextToken or previousToken

 o nextToken
 public String nextToken()
Retrieves the next available token

Returns:
the next available token or null if there are none
 o previousToken
 public String previousToken()
Retrieves the previous token

Returns:
the previous token or null if a previous token is not available
 o resetPosition
 public void resetPosition()
Resets the position of the token pointer to the beginning

 o setPosition
 public void setPosition(int position)
Sets the current position of this tokenizer.

Parameters:
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 beginning
 o toString
 public String toString()

All Packages  Class Hierarchy  This Package  Previous  Next  Index