Class StringTokenIterator
java.lang.Object
com.twelvemonkeys.util.AbstractTokenIterator
com.twelvemonkeys.util.StringTokenIterator
- All Implemented Interfaces:
TokenIterator, Enumeration<String>, Iterator<String>
StringTokenIterator, a drop-in replacement for
StringTokenizer.
StringTokenIterator has the following features:
- Iterates over a strings, 20-50% faster than
StringTokenizer(and magnitudes faster thanString.split(..)orPattern.split(..)) - Implements the
Iteratorinterface - Optionally returns delimiters
- Optionally returns empty elements
- Optionally iterates in reverse
- Resettable
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/StringTokenIterator.java#1 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final char[]static final intprivate final booleanprivate final booleanprivate final charStores the value of the delimiter character with the highest value.private final intprivate Stringprivate Stringprivate intprivate final booleanstatic final intprivate final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionStringTokenIterator(String pString) Creates a StringTokenIteratorprivateStringTokenIterator(String pString, char[] pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) Implementation.StringTokenIterator(String pString, String pDelimiters) Creates a StringTokenIteratorStringTokenIterator(String pString, String pDelimiters, boolean pIncludeDelimiters) Creates a StringTokenIteratorStringTokenIterator(String pString, String pDelimiters, int pDirection) Creates a StringTokenIteratorStringTokenIterator(String pString, String pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) Creates a StringTokenIterator -
Method Summary
Modifier and TypeMethodDescriptionprivate Stringprivate Stringprivate StringbooleanhasNext()Returnstrueif the iteration has more elements.private static charinitMaxDelimiter(char[] pDelimiters) Returns the highest char in the delimiter set.next()Returns the next element in the iteration.voidreset()Resets this iterator.private intprivate intprivate static char[]toCharArray(String pDelimiters) Methods inherited from class AbstractTokenIterator
hasMoreElements, hasMoreTokens, nextElement, nextToken, removeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Enumeration
asIteratorMethods inherited from interface Iterator
forEachRemaining
-
Field Details
-
string
-
delimiters
private final char[] delimiters -
position
private int position -
maxPosition
private final int maxPosition -
next
-
nextDelimiter
-
includeDelimiters
private final boolean includeDelimiters -
includeEmpty
private final boolean includeEmpty -
reverse
private final boolean reverse -
FORWARD
public static final int FORWARD- See Also:
-
REVERSE
public static final int REVERSE- See Also:
-
maxDelimiter
private final char maxDelimiterStores the value of the delimiter character with the highest value. It is used to optimize the detection of delimiter characters.
-
-
Constructor Details
-
StringTokenIterator
Creates a StringTokenIterator- Parameters:
pString- the string to be parsed.
-
StringTokenIterator
-
StringTokenIterator
-
StringTokenIterator
-
StringTokenIterator
public StringTokenIterator(String pString, String pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) Creates a StringTokenIterator- Parameters:
pString- the string to be parsed.pDelimiters- the delimiters.pDirection- iteration direction.pIncludeDelimiters- flag indicating whether to return delimiters as tokens.pIncludeEmpty- flag indicating whether to return empty tokens
-
StringTokenIterator
private StringTokenIterator(String pString, char[] pDelimiters, int pDirection, boolean pIncludeDelimiters, boolean pIncludeEmpty) Implementation.- Parameters:
pString- the string to be parsed.pDelimiters- the delimiters.pDirection- iteration direction.pIncludeDelimiters- flag indicating whether to return delimiters as tokens.pIncludeEmpty- flag indicating whether to return empty tokens
-
-
Method Details
-
toCharArray
-
initMaxDelimiter
private static char initMaxDelimiter(char[] pDelimiters) Returns the highest char in the delimiter set.- Parameters:
pDelimiters- the delimiter set- Returns:
- the highest char
-
reset
public void reset()Resets this iterator. -
hasNext
public boolean hasNext()Returnstrueif the iteration has more elements. (In other words, returnstrueifnextwould return an element rather than throwing an exception.)- Returns:
trueif the iterator has more elements.
-
fetchNext
-
fetchReverse
-
fetchForward
-
scanForNext
private int scanForNext() -
scanForPrev
private int scanForPrev() -
next
Returns the next element in the iteration.- Returns:
- the next element in the iteration.
- Throws:
NoSuchElementException- iteration has no more elements.
-