org.nukesoft.bot2.botutil
Class ExtendedStringTokenizer

java.lang.Object
  |
  +--org.nukesoft.bot2.botutil.ExtendedStringTokenizer

public class ExtendedStringTokenizer
extends Object

The ExtendedStringTokenizer class us used much the same way as a StringTokenizer, but provides some enhanced functionality usefull to writing command parsers. These include token peeking, parsing quoted strings as single tokens, and returning the rest of the token stream as a single string.

Author:
Ryan Michela

Constructor Summary
ExtendedStringTokenizer(String str)
           
 
Method Summary
 boolean containsToken(String token)
          Determines if this tokenizer's input string contains a given token.
 boolean containsTokenIgnoreCase(String token)
          Determines if this tokenizer's input string contains a given token.
 int countTokens()
          Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.
 boolean hasMoreTokens()
          Tests if there are more tokens available from this tokenizer's string.
 String nextQuotedToken()
          Returns the next quoted token from this string tokenizer.
 String nextToken()
          Returns the next token from this string tokenizer.
 String peekNextToken()
          Returns the next token from this string tokenizer without actually removing the token from the token stream.
 String restTokens()
          Returns all remaining tokens in a single string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendedStringTokenizer

public ExtendedStringTokenizer(String str)
Method Detail

countTokens

public int countTokens()
Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception. This does not take quoted tokens into account. The current position is not advanced.

Returns:
The number of tokens remaining in the string.

hasMoreTokens

public boolean hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string. If this method returns true, then a subsequent call tonextToken with no argument will successfully return a token.

Returns:
TRUE if and only if there is at least one token in the string after the current position; FALSE otherwise.

nextToken

public String nextToken()
                 throws NoSuchElementException
Returns the next token from this string tokenizer.

Returns:
The next token from this string tokenizer.
Throws:
NoSuchElementException - if there are no more tokens in this tokenizer's string.

nextQuotedToken

public String nextQuotedToken()
                       throws NoSuchElementException
Returns the next quoted token from this string tokenizer. That is, if the next token starts a quoted string, the entire quoted string will be returned sans quote characters, otherwise, the next token will be returned.

Returns:
The next quoted token from this string tokenizer.
Throws:
NoSuchElementException - if there are no more tokens in this tokenizer's string.

peekNextToken

public String peekNextToken()
                     throws NoSuchElementException
Returns the next token from this string tokenizer without actually removing the token from the token stream.

Returns:
The next token from this string tokenizer.
Throws:
NoSuchElementException - if there are no more tokens in this tokenizer's string.

restTokens

public String restTokens()
Returns all remaining tokens in a single string. If there are no more tokens remaining, an empty string is returned.

Returns:
The remaining tokens.

containsToken

public boolean containsToken(String token)
Determines if this tokenizer's input string contains a given token.

Parameters:
token - The token to test.
Returns:
TRUE if the token is present, FALSE otherwise.

containsTokenIgnoreCase

public boolean containsTokenIgnoreCase(String token)
Determines if this tokenizer's input string contains a given token. Case is ignored in durring comparison.

Parameters:
token - The token to test.
Returns:
TRUE if the token is present, FALSE otherwise.