public class StringTokenizer extends AbstractIterator<String> implements Iterable<String>
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. String
also for duplicated delimited might NOT always be desired (especially when
delimiter is whitespace).Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 to tokenize 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() |
findFirst, hasNext, next, remove
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
forEachRemaining
private final char[] string
private final char[] delimiters
private final char[] escapeStart
private final char[] escapeEnd
private int index
string
.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.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.protected String findNext()
AbstractIterator
next
element.findNext
in class AbstractIterator<String>
null
if done
.protected boolean containsSubstring(char[] substring, int startIndex)
substring
starting at the given
index
.substring
- is the substring to check for.startIndex
- is the start index in the string to tokenize.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()
Copyright © 2001–2016 mmm-Team. All rights reserved.