com.ibm.dse.applsrv.aa
Class StringParser

java.lang.Object
  |
  +--com.ibm.dse.applsrv.aa.StringParser
Direct Known Subclasses:
DummyStringParser

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

This is an enhanced version of StringTokenizer.


Constructor Summary
StringParser(java.lang.String str)
          Constructs a string parser for the specified string.
StringParser(java.lang.String str, java.lang.String delim)
          Constructs a string parser for the specified string.
StringParser(java.lang.String str, java.lang.String delim, boolean returnTokens)
          Constructs a string tokenizer for the specified string.
 
Method Summary
 int countTokens()
          Calculates the number of times that this tokenizer's nextToken method can be called before it generates an exception.
 boolean hasMoreElements()
          Returns the same value as the hasMoreTokens method.
 boolean hasMoreTokens()
          Tests if there are more tokens available from this tokenizer's string.
 boolean isDelimiter(char c)
          Check if the specified character is a delimiter.
 java.lang.Object nextElement()
          Returns the same value as the nextToken method, except that its declared return value is Object rather than String.
 java.lang.String nextToken()
          Returns the next token from this string parser or nil if there are no more tokens.
 java.lang.String nextToken(java.lang.String delim)
          Returns the next token in this string tokenizer's string.
 java.lang.String rest()
          Returns the rest of the string.
 int[] restAsIntArray()
          Returns the rest of the string as an integer array.
 java.lang.Integer[] restAsIntegerArray()
          Returns the rest of the string as an integer array.
 java.lang.String[] restAsStringArray()
          Returns the rest of the string as a string array.
 Array restAsStringArrays(java.lang.String delimiter)
          Return the rest of the tokens as an array of string arrays delimited by the specified string.
 void rewind()
          Rewind the parser.
 boolean selectToken(int n)
          Set the read pointer before the n'th token (or EOF if the n'th token doesn't exist.
 void set(java.lang.String str)
          Reset the parse for a new string.
 java.lang.String source()
          Returns the original string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringParser

public StringParser(java.lang.String str)
Constructs a string parser for the specified string. The parser uses the default delimiter set, which is "\t\n\r": the space character, the tab character, the newline character, and the carriage-return character.
Parameters:
str - String - the string to be parsed.

StringParser

public StringParser(java.lang.String str,
                    java.lang.String delim)
Constructs a string parser for the specified string. The characters in the delim argument are the delimiters for separating tokens.
Parameters:
str - String - a string to be parsed.
delim - String - the delimiters.

StringParser

public StringParser(java.lang.String str,
                    java.lang.String delim,
                    boolean returnTokens)
Constructs a string tokenizer for the specified string. The characters in the delim argument are the delimiters for separating tokens.

If the returnTokens flag is true, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false, the delimiter characters are skipped and only serve as separators between tokens.

Parameters:
str - String - a string to be parsed.
delim - String - the delimiters.
returnTokens - boolean - flag indicating whether to return the delimiters as tokens.
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.
Returns:
int - the number of tokens remaining in the string using the current delimiter set.

hasMoreElements

public boolean hasMoreElements()
Returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.
Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
boolean - true if there are more tokens, false otherwise.

hasMoreTokens

public boolean hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
Returns:
boolean - true if there are more tokens available from this tokenizer's string, false otherwise.

isDelimiter

public boolean isDelimiter(char c)
Check if the specified character is a delimiter.
Parameters:
c - char - the character to check.
Returns:
boolean - true if the character is a delimiter else false.

nextElement

public java.lang.Object nextElement()
Returns the same value as the nextToken method, except that its declared return value is Object rather than String. It exists so that this class can implement the Enumeration interface.
Specified by:
nextElement in interface java.util.Enumeration
Returns:
Object - the next token in the string.
Throws:
java.util.NoSuchElementException - - if there are no more tokens in this parser's string.

nextToken

public java.lang.String nextToken()
Returns the next token from this string parser or nil if there are no more tokens.
Returns:
String - the next token from this string parser.

nextToken

public java.lang.String nextToken(java.lang.String delim)
Returns the next token in this string tokenizer's string. The new delimiter set remains the default after this call.
Parameters:
delim - String - the new delimiters.
Returns:
String - the next token, after switching to the new delimiter set.

rest

public java.lang.String rest()
Returns the rest of the string.
Returns:
String - the rest of the string.

restAsIntArray

public int[] restAsIntArray()
Returns the rest of the string as an integer array.
Returns:
int[] - the rest of the string as an int array.

restAsIntegerArray

public java.lang.Integer[] restAsIntegerArray()
Returns the rest of the string as an integer array.
Returns:
Integer[] - the rest of the string as an integer array.

restAsStringArray

public java.lang.String[] restAsStringArray()
Returns the rest of the string as a string array.
Returns:
String[] - the rest of the string as a string array.

restAsStringArrays

public Array restAsStringArrays(java.lang.String delimiter)
Return the rest of the tokens as an array of string arrays delimited by the specified string.
Parameters:
delimiter - String - the delimiter.
Returns:
Array - the array of string arrays extracted from this parser.

rewind

public void rewind()
Rewind the parser.

selectToken

public boolean selectToken(int n)
Set the read pointer before the n'th token (or EOF if the n'th token doesn't exist. Count from 1.
Parameters:
n - int - the token to select (counting from 1).
Returns:
boolean - true if n > 0 and the next nextToken() will succeed.

set

public void set(java.lang.String str)
Reset the parse for a new string. The parser uses the default delimiter set, which is "\t\n\r": the space character, the tab character, the newline character, and the carriage-return character.
Parameters:
str - String - the string to be parsed.

source

public java.lang.String source()
Returns the original string.
Returns:
String - the original string.