hades.utils
Class StringTokenizer

java.lang.Object
  extended byhades.utils.StringTokenizer
All Implemented Interfaces:
java.util.Enumeration

public class StringTokenizer
extends java.lang.Object
implements java.util.Enumeration

modified version of java.util.StringTokenizer with 'restOfLine' methods.

StringTokenizer is a class that controls simple linear tokenization of a String. The set of delimiters, which defaults to common whitespace characters, may be specified at creation time or on a per-token basis.

Example usage:

	String s = "this is a test";
	StringTokenizer st = new StringTokenizer(s);
	while (st.hasMoreTokens()) {
		println(st.nextToken());
	}
 
Prints the following on the console:
	this
	is
	a
	test
 


Constructor Summary
StringTokenizer(java.lang.String str)
          Constructs a StringTokenizer on the specified String, using the default delimiter set (which is " \t\n\r").
StringTokenizer(java.lang.String str, java.lang.String delim)
          Constructs a StringTokenizer on the specified String, using the specified delimiter set.
StringTokenizer(java.lang.String str, java.lang.String delim, boolean returnTokens)
          Constructs a StringTokenizer on the specified String, using the specified delimiter set.
 
Method Summary
 int countTokens()
          Returns the next number of tokens in the String using the current deliminter set.
 int currentPosition()
          return the current postion in the input String
 boolean hasMoreElements()
          Returns true if the Enumeration has more elements.
 boolean hasMoreTokens()
          Returns true if more tokens exist.
 java.lang.Object nextElement()
          Returns the next element in the Enumeration.
 java.lang.String nextToken()
          Returns the next token of the String.
 java.lang.String nextToken(java.lang.String delim)
          Returns the next token, after switching to the new delimiter set.
 java.lang.String restOfLine()
          return the so-far-unparsed rest of the input String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTokenizer

public StringTokenizer(java.lang.String str,
                       java.lang.String delim,
                       boolean returnTokens)
Constructs a StringTokenizer on the specified String, using the specified delimiter set.

Parameters:
str - the input String
delim - the delimiter String
returnTokens - returns delimiters as tokens or skip them

StringTokenizer

public StringTokenizer(java.lang.String str,
                       java.lang.String delim)
Constructs a StringTokenizer on the specified String, using the specified delimiter set.

Parameters:
str - the input String
delim - the delimiter String

StringTokenizer

public StringTokenizer(java.lang.String str)
Constructs a StringTokenizer on the specified String, using the default delimiter set (which is " \t\n\r").

Parameters:
str - the String
Method Detail

hasMoreTokens

public boolean hasMoreTokens()
Returns true if more tokens exist.


nextToken

public java.lang.String nextToken()
Returns the next token of the String.

Throws:
java.util.NoSuchElementException - If there are no more tokens in the String.

nextToken

public java.lang.String nextToken(java.lang.String delim)
Returns the next token, after switching to the new delimiter set. The new delimiter set remains the default after this call.

Parameters:
delim - the new delimiters

hasMoreElements

public boolean hasMoreElements()
Returns true if the Enumeration has more elements.

Specified by:
hasMoreElements in interface java.util.Enumeration

nextElement

public java.lang.Object nextElement()
Returns the next element in the Enumeration.

Specified by:
nextElement in interface java.util.Enumeration
Throws:
java.util.NoSuchElementException - If there are no more elements in the enumeration.

countTokens

public int countTokens()
Returns the next number of tokens in the String using the current deliminter set. This is the number of times nextToken() can return before it will generate an exception. Use of this routine to count the number of tokens is faster than repeatedly calling nextToken() because the substrings are not constructed and returned for each token.


currentPosition

public int currentPosition()
return the current postion in the input String


restOfLine

public java.lang.String restOfLine()
return the so-far-unparsed rest of the input String