StringSplitter instead@Deprecated public class StringSplitter extends Object
Unlike the String.split(String) method, this utility returns tokens
as they are split on the fly so the caller can process them in place. The
traditional String.split(String) approach must make at least two
passes over the string [O(n^2)] whereas this approach is guarantee to make a
single pass [O(n)].
String string = "Please split this string by space";
StringSplitter splitter = new StringSplitter(string);
while (splitter.hasNext()) {
String next = splitter.next();
}
| Modifier and Type | Field and Description |
|---|---|
protected int |
options
Deprecated.
An integer that contains bits representing
split
options that have been enabled. |
protected int |
pos
Deprecated.
The current position of the splitter.
|
| Constructor and Description |
|---|
StringSplitter(String string)
Deprecated.
Construct a new instance.
|
StringSplitter(String string,
char delimiter)
Deprecated.
Construct a new instance.
|
StringSplitter(String string,
char delimiter,
SplitOption... options)
Deprecated.
Construct a new instance.
|
StringSplitter(String string,
SplitOption... options)
Deprecated.
Construct a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
atEndOfLine()
Deprecated.
Return
true if SplitOption.SPLIT_ON_NEWLINE is
enabled and the last token
returned by next() is followed immediately by a line break. |
protected boolean |
confirmSetNext()
Deprecated.
Before an attempt is made to
set the next token do
some analysis on the internal state of the splitter to see if its
actually appropriate to do so. |
boolean |
hasNext()
Deprecated.
Return
true if this splitter has any remaining substrings. |
protected boolean |
isReadyToSplit()
Deprecated.
Determine, based on state factors that are recorded within the class, if
the splitter is actually ready to split the string on an instance of the
delimiter.
|
String |
next()
Deprecated.
Return the next substring that results from splitting the original source
string.
|
void |
reset()
Deprecated.
Reset the splitter.
|
String[] |
toArray()
Deprecated.
Return an array that contains all the tokens after traversing through the
entire split process.
|
protected void |
updateIsReadyToSplit(char c)
Deprecated.
Given a character
c that is processed by the splitter, update the
state that determines whether the splitter would actually be ready to
split in the event that it encounters a delimiter character. |
protected final int options
split
options that have been enabled. To check whether an option is enabled do
return (options & (1 << option.mask())) != 0;
protected int pos
public StringSplitter(String string)
string - the string to splitpublic StringSplitter(String string, char delimiter)
string - the string to splitdelimiter - the delimiter upon which to splitpublic StringSplitter(String string, char delimiter, SplitOption... options)
string - the string to splitdelimiter - the delimiter upon which to splitoptions - an array of options to supplement the
split behaviourpublic StringSplitter(String string, SplitOption... options)
string - the string to splitoptions - an array of options to supplement the
split behaviourpublic boolean atEndOfLine()
true if SplitOption.SPLIT_ON_NEWLINE is
enabled and the last token
returned by next() is followed immediately by a line break.
Otherwise, return false.true if the last token returned was at the end of linepublic boolean hasNext()
true if this splitter has any remaining substrings.true if there is another elementpublic String next()
public void reset()
public String[] toArray()
protected boolean confirmSetNext()
set the next token do
some analysis on the internal state of the splitter to see if its
actually appropriate to do so. If the next token should not be set,
return false from this method and also optionally change the
pos pointer to rewind the splitter.true if the splitter is indeed ready to set the next
tokenprotected boolean isReadyToSplit()
true, but a
subclass can use it for awareness of certain conditions that would mean a
string should not be split on an instance of the delimiter (i.e. if the
delimiter occurs within quotes).true if the splitter is actually ready to perform a splitprotected void updateIsReadyToSplit(char c)
c that is processed by the splitter, update the
state that determines whether the splitter would actually be ready to
split in the event that it encounters a delimiter character.c -