com.rubecula.util
Class PushbackStringTokenizer

java.lang.Object
  extended byjava.util.StringTokenizer
      extended bycom.rubecula.util.PushbackStringTokenizer
All Implemented Interfaces:
java.util.Enumeration

public class PushbackStringTokenizer
extends java.util.StringTokenizer

Class to implement StringTokenizer with a one-deep pushback buffer.

Version:
$Revision: 1.1 $
Author:
Robin Hillyard

Nested Class Summary
(package private) static class PushbackStringTokenizer.Test
          Test class.
 
Field Summary
private  boolean _NextTokenInBuffer
          Whether or not the pushback buffer should be used by the next call to next().
private  java.lang.String _TokenBuffer
          The pushback buffer.
 
Fields inherited from class java.util.StringTokenizer
 
Constructor Summary
PushbackStringTokenizer(java.lang.String str)
          Constructor which in turn invokes StringTokenizer(str).
PushbackStringTokenizer(java.lang.String str, java.lang.String delim)
          Constructor which in turn invokes StringTokenizer(str,delim).
PushbackStringTokenizer(java.lang.String str, java.lang.String delim, boolean returnDelims)
          Constructor which in turn invokes StringTokenizer(str,delim,returnDelims).
 
Method Summary
 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.
 java.lang.String nextToken()
          Returns the next token from this string tokenizer.
 java.lang.String nextToken(java.lang.String delim)
           
 void pushbackToken()
          Push a token back into the tokenizer.
 
Methods inherited from class java.util.StringTokenizer
hasMoreElements, nextElement
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_TokenBuffer

private java.lang.String _TokenBuffer
The pushback buffer.


_NextTokenInBuffer

private boolean _NextTokenInBuffer
Whether or not the pushback buffer should be used by the next call to next().

Constructor Detail

PushbackStringTokenizer

public PushbackStringTokenizer(java.lang.String str,
                               java.lang.String delim,
                               boolean returnDelims)
Constructor which in turn invokes StringTokenizer(str,delim,returnDelims).

Parameters:
str - The string to tokenize.
delim - The set of delimiters.
returnDelims - Whether to return delimiters along with the tokens.

PushbackStringTokenizer

public PushbackStringTokenizer(java.lang.String str,
                               java.lang.String delim)
Constructor which in turn invokes StringTokenizer(str,delim).

Parameters:
str - The string to tokenize.
delim - The set of delimiters.

PushbackStringTokenizer

public PushbackStringTokenizer(java.lang.String str)
Constructor which in turn invokes StringTokenizer(str).

Parameters:
str - The string to tokenize.
Method Detail

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 to nextToken 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 java.lang.String nextToken()
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.

nextToken

public java.lang.String nextToken(java.lang.String delim)
Parameters:
delim - the new delimiters (ignored).
Returns:
the next token, after switching to the new delimiter set (not returned).
Throws:
java.lang.RuntimeException - not implemented (always thrown).

countTokens

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

Returns:
the number of tokens remaining in the string using the current delimiter set.
See Also:
nextToken()

pushbackToken

public void pushbackToken()
Push a token back into the tokenizer.

Throws:
java.lang.RuntimeException - if next() has not yet been called.