sjm.parse.tokens
Class TokenStringSource
java.lang.Object
|
+--sjm.parse.tokens.TokenStringSource
- public class TokenStringSource
- extends java.lang.Object
A TokenStringSource enumerates over a specified reader,
returning TokenStrings delimited by a specified delimiter.
For example,
String s = "I came; I saw; I left in peace;";
TokenStringSource tss =
new TokenStringSource(new Tokenizer(s), ";");
while (tss.hasMoreTokenStrings()) {
System.out.println(tss.nextTokenString());
}
prints out:
I came
I saw
I left in peace
- Version:
- 1.0
- Author:
- Steven J. Metsker
Constructor Summary |
TokenStringSource(Tokenizer tokenizer,
java.lang.String delimiter)
Constructs a TokenStringSource that will read TokenStrings
using the specified tokenizer, delimited by the specified
delimiter. |
Method Summary |
protected void |
ensureCacheIsLoaded()
The design of nextTokenString is that is
always returns a cached value. |
boolean |
hasMoreTokenStrings()
Returns true if the source has more TokenStrings. |
protected void |
loadCache()
Loads the next TokenString into the cache, or sets the
cache to null if the source is out of tokens. |
static void |
main(java.lang.String[] args)
Shows the example in the class comment. |
TokenString |
nextTokenString()
Returns the next TokenString from the source. |
protected java.util.Vector |
nextVector()
Returns a Vector of the tokens in the source up to either
the delimiter or the end of the source. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
tokenizer
protected Tokenizer tokenizer
delimiter
protected java.lang.String delimiter
cachedTokenString
protected TokenString cachedTokenString
TokenStringSource
public TokenStringSource(Tokenizer tokenizer,
java.lang.String delimiter)
- Constructs a TokenStringSource that will read TokenStrings
using the specified tokenizer, delimited by the specified
delimiter.
- Parameters:
tokenizer
- a tokenizer to read tokens fromdelimiter
- the character that fences off where one
TokenString ends and the next begins
ensureCacheIsLoaded
protected void ensureCacheIsLoaded()
- The design of
nextTokenString
is that is
always returns a cached value. This method will (at least
attempt to) load the cache if the cache is empty.
hasMoreTokenStrings
public boolean hasMoreTokenStrings()
- Returns true if the source has more TokenStrings.
- Returns:
- true, if the source has more TokenStrings that
have not yet been popped with
nextTokenString
.
loadCache
protected void loadCache()
- Loads the next TokenString into the cache, or sets the
cache to null if the source is out of tokens.
main
public static void main(java.lang.String[] args)
- Shows the example in the class comment.
- Parameters:
args
- ignored
nextTokenString
public TokenString nextTokenString()
- Returns the next TokenString from the source.
- Returns:
- the next TokenString from the source
nextVector
protected java.util.Vector nextVector()
- Returns a Vector of the tokens in the source up to either
the delimiter or the end of the source.
- Returns:
- a Vector of the tokens in the source up to either
the delimiter or the end of the source.