|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.mmm.util.collection.base.AbstractIterator<String>
net.sf.mmm.util.lang.api.StringTokenizer
public class StringTokenizer
This is a rewrite of the awkward StringTokenizer
provided
by the JDK. This implementation returns
an empty
String
if a duplicate delimiter is detected. Further it implements
Iterable
and can be used in enhanced for-loops.
ATTENTION:
Returning an empty String
also for duplicated delimited might NOT
always be desired (especially when delimiter is whitespace).
Field Summary | |
---|---|
private char[] |
delimiters
The characters that will be detected as delimiters. |
private char[] |
escapeEnd
The string to end escaping of a token. |
private char[] |
escapeStart
The string to start escaping of a token. |
private int |
index
The current index in string . |
private char[] |
string
The string to be tokenized |
Constructor Summary | |
---|---|
StringTokenizer(char[] string,
char... delimiters)
The constructor. |
|
StringTokenizer(char[] string,
String escapeStart,
String escapeEnd,
char... delimiters)
The constructor. |
|
StringTokenizer(String string,
char... delimiters)
The constructor. |
|
StringTokenizer(String string,
String delimiters)
The constructor. |
|
StringTokenizer(String string,
String escapeStart,
String escapeEnd,
char... delimiters)
The constructor that allows escaping. |
Method Summary | |
---|---|
private static boolean |
containsDelimiter(char[] escape,
char[] delimiters)
This method checks that the given escape sequence does NOT
contain any of the delimiters . |
protected boolean |
containsSubstring(char[] substring,
int startIndex)
This method tests if the string contains the given
substring starting at the given index . |
protected String |
findNext()
This method tries to find the next element. |
boolean |
hasMoreTokens()
|
Iterator<String> |
iterator()
|
String |
nextToken()
|
String |
toString()
|
Methods inherited from class net.sf.mmm.util.collection.base.AbstractIterator |
---|
findFirst, hasNext, next, remove |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final char[] string
private final char[] delimiters
private final char[] escapeStart
private final char[] escapeEnd
private int index
string
.
Constructor Detail |
---|
public StringTokenizer(String string, char... delimiters)
string
- is the string to be tokenized.delimiters
- are the characters that will be detected as delimiters.public StringTokenizer(String string, String delimiters)
string
- is the string to be tokenized.delimiters
- is a String
with all the characters that will be
detected as delimiters.public StringTokenizer(String string, String escapeStart, String escapeEnd, char... delimiters) throws NlsIllegalArgumentException
new StringTokenizer("{[foo,{[bar,thing]}]},some", "{[", "]}", ',').next()will return "foo,{[bar,thing]}".
string
- is the string to be tokenized.escapeStart
- is the string used to start escaping of a token. The
string has to be free of delimiters
.escapeEnd
- is the string used to end escaping of a token. The string
has to be free of delimiters
.delimiters
- are the characters that will be detected as delimiters.
NlsIllegalArgumentException
- if escapeStart
or
escapeEnd
is an empty string or contains a character
of delimiters
, or one of them is null
while the other is not, or both are not null
but
equal
to each other.public StringTokenizer(char[] string, String escapeStart, String escapeEnd, char... delimiters) throws NlsIllegalArgumentException
string
- is the string to be tokenized.escapeStart
- is the string used to start escaping of a token. May NOT
be the empty string. The string has to be free of
delimiters
.escapeEnd
- is the string used to end escaping of a token. May NOT be
the empty string.The string has to be free of
delimiters
.delimiters
- are the characters that will be detected as delimiters.
NlsIllegalArgumentException
- if escapeStart
or
escapeEnd
is an empty string or contains a character
of delimiters
, or one of them is null
while the other is not, or both are not null
but
equal
to each other.StringTokenizer(String, String, String, char...)
public StringTokenizer(char[] string, char... delimiters)
string
- is the string to be tokenized.delimiters
- are the characters that will be detected as delimiters.Method Detail |
---|
private static boolean containsDelimiter(char[] escape, char[] delimiters)
escape
sequence does NOT
contain any of the delimiters
.
escape
- is the escape-sequence to check.delimiters
- are the delimiters that should NOT be contained in
escape
.
true
if escape
contains a character of
delimiters
, false
otherwise.public Iterator<String> iterator()
iterator
in interface Iterable<String>
protected String findNext()
next
element.
findNext
in class AbstractIterator<String>
null
if done
.protected boolean containsSubstring(char[] substring, int startIndex)
string
contains the given
substring
starting at the given index
.
substring
- is the substring to check for.startIndex
- is the start index in string
.
true
if the given substring
was found at
index
.public boolean hasMoreTokens()
true
if AbstractIterator.next()
is available,
false
otherwise.StringTokenizer.hasMoreTokens()
public String nextToken()
next
token.StringTokenizer.nextToken()
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |