moka.util
Class StringTokenizer

java.lang.Object
  |
  +--moka.lang.Object
        |
        +--moka.util.StringTokenizer

public class StringTokenizer
extends Object

The string tokenizer class allows an application to break a string into tokens. The delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.

Since:
MDK1.0a

Field Summary
 int currentPosition
          The index of the current char in the string.
 
Constructor Summary
StringTokenizer(java.lang.String str)
          Constructs a string tokenizer for the specified string.
StringTokenizer(java.lang.String str, java.lang.String delim)
          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.
 void finalize()
          Frees the memory of system ressources used by this StringTokenizer object.
 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)
          Returns the next token in this string tokenizer's string.
 void setCurrentPosition(int currentPosition)
          Sets the current position to the specified index.
 
Methods inherited from class moka.lang.Object
equals, getClassName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentPosition

public int currentPosition
The index of the current char in the string. Should be only read.

Constructor Detail

StringTokenizer

public StringTokenizer(java.lang.String str)
Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiters, which is the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. If the string object risk to be used later, use a copy of the string object instead of the original, the string being finalized before the method returns.

Parameters:
str - a string to be parsed.

StringTokenizer

public StringTokenizer(java.lang.String str,
                       java.lang.String delim)
Constructs a string tokenizer for the specified string. The characters in the delim argument is the delimiters for separating tokens. If the string objects risk to be used later, use a copy of the string objects instead of the originals, the strings being finalized before the method returns.

Parameters:
str - a string to be parsed.
delim - the delimiter.
Method Detail

finalize

public void finalize()
Frees the memory of system ressources used by this StringTokenizer object.

Overrides:
finalize in class Object

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.

nextToken

public java.lang.String nextToken(java.lang.String delim)
Returns the next token in this string tokenizer's string. First, the set of characters considered to be delimiters by this StringTokenizer object is changed to be the characters in the string delim. Then the next token in the string after the current position is returned. The current position is advanced beyond thoken. The new delimiter set remains the default after this call. If the string object risk to be used later, use a copy of the string object instead of the original, the string being finalized before the method returns.

Parameters:
delim - the new delimiters.
Returns:
the next token, after switching to the new delimiter set.

countTokens

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

Returns:
the number of tokens remaining in the string using the current delimiter set.

setCurrentPosition

public void setCurrentPosition(int currentPosition)
Sets the current position to the specified index. currentPosition the new current position.