|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectTask.Support.CoreSupport.TheStringTokenizer.Tokenizer
public class TheStringTokenizer.Tokenizer
This class simply takes an input String or StringBuffer and tokenizes the input based on a delimiter String.
Usage:String input = "20,LOR;ispq.com;490030,LOR;ispq.com;4900 40,LOR;ispq.com;490"; String delim = " "; Tokenizer t = new Tokenizer(); t.set( input , delim ); //this is for input with tokens System.out.println( "***valid input with tokens***" ); System.out.println( "input:"+input ); Tokenizer t = new Tokenizer( input , delim ); System.out.println( "hasTokens():"+t.hasTokens() ); String[] strRay = t.getTokens(); for( int i=0; i
Output:Note: Definition of a token
***valid input with tokens input:20,LOR;ispq.com;490030,LOR;ispq.com;4900 40,LOR;ispq.com;490 hasTokens():true token:20,LOR;ispq.com;4900 <--token1 token:30,LOR;ispq.com;4900 <--token2 40,LOR;ispq.com;490 <--remainder
This class is different from the StringTokenizer class. Unlike the StringTokenizer class (which just looks for chars in the String to break up the String into tokens), the Tokenizer class looks for delimiters to break up words( and it there MUST be trailing delimiters to get the last token, or else it will be the remainder).
For example: t.set( "LOR;ispq.com;4900" , ";" ); will yield {"LOR","ispq.com"} when getTokens() is called. Whereas StringTokenizer would return {"LOR", "ispq.com","4900"}
Note: dependenciesTheStringTokenizer class depends on this class, so be sure to check this class if Tokenzier is modified.
| Field Summary | |
|---|---|
protected java.lang.String |
delim
|
protected java.lang.String |
input
|
protected java.lang.String |
remainder
|
| Constructor Summary | |
|---|---|
TheStringTokenizer.Tokenizer()
|
|
| Method Summary | |
|---|---|
java.lang.StringBuffer |
getRemainderOfInput()
This method returns an empty StringBuffer if there is no remainder in this Tokenizer object. |
java.lang.String[] |
getTokens()
Returns all the tokens in the current message buffer, that are delimited by the String. |
boolean |
hasRemainder()
Determines whether there is any data left over in the message buffer after all the tokens have been extracted from it. |
boolean |
hasTokens()
Returns true if there tokens exist in the message buffer. |
TheStringTokenizer.Tokenizer |
set(java.lang.StringBuffer sb,
java.lang.String delim)
same as set( String , String ), only it converts the StringBuffer to a String before calling the other set() |
TheStringTokenizer.Tokenizer |
set(java.lang.String input,
java.lang.String delim)
This method sets up the Tokenizer to process the given message buffer and delim (delimiter) string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String input
protected java.lang.String delim
protected java.lang.String remainder
| Constructor Detail |
|---|
public TheStringTokenizer.Tokenizer()
| Method Detail |
|---|
public TheStringTokenizer.Tokenizer set(java.lang.String input,
java.lang.String delim)
input - message buffer that contains the untokenized data received from the socketdelim - delimiter string used to delimit the tokens in the message buffer.
public TheStringTokenizer.Tokenizer set(java.lang.StringBuffer sb,
java.lang.String delim)
public boolean hasTokens()
public java.lang.String[] getTokens()
public boolean hasRemainder()
public java.lang.StringBuffer getRemainderOfInput()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||