public final class UnicodeSetIterator extends Object
This class is not intended for public subclassing.
To iterate over code points and multicharacter strings, use a loop like this:
for (UnicodeSetIterator it = new UnicodeSetIterator(set); it.next();) { processString(it.getString()); }
To iterate over code point ranges, use a loop like this:
for (UnicodeSetIterator it = new UnicodeSetIterator(set); it.nextRange();) { if (it.codepoint != UnicodeSetIterator.IS_STRING) { processCodepointRange(it.codepoint, it.codepointEnd); } else { processString(it.getString()); } }
To iterate over only the strings, start with new UnicodeSetIterator(set).skipToStrings()
.
Warning: For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.
UnicodeSet.ranges()
,
UnicodeSet.strings()
,
UnicodeSet.iterator()
Modifier and Type | Field and Description |
---|---|
int |
codepoint
Current code point, or the special value IS_STRING, if
the iterator points to a string.
|
int |
codepointEnd
When iterating over ranges using nextRange(),
codepointEnd contains the inclusive end of the
iteration range, if codepoint !
|
static int |
IS_STRING
Value of codepoint if the iterator points to a string.
|
String |
string
If codepoint == IS_STRING, then string points
to the current string.
|
Constructor and Description |
---|
UnicodeSetIterator()
Create an iterator over nothing.
|
UnicodeSetIterator(UnicodeSet set)
Create an iterator over the given set.
|
Modifier and Type | Method and Description |
---|---|
String |
getString()
Gets the current string from the iterator.
|
boolean |
next()
Returns the next element in the set, either a single code point
or a string.
|
boolean |
nextRange()
Returns the next element in the set, either a code point range
or a string.
|
void |
reset()
Resets this iterator to the start of the set.
|
void |
reset(UnicodeSet uset)
Sets this iterator to visit the elements of the given set and
resets it to the start of that set.
|
UnicodeSetIterator |
skipToStrings()
Skips over the remaining code points/ranges, if any.
|
public static final int IS_STRING
public int codepoint
public int codepointEnd
public String string
public UnicodeSetIterator(UnicodeSet set)
set
- set to iterate overpublic UnicodeSetIterator()
public UnicodeSetIterator skipToStrings()
UnicodeSet.strings()
public boolean next()
The order of iteration is all code points in sorted order, followed by all strings sorted order. codepointEnd is undefined after calling this method. string is undefined unless codepoint == IS_STRING. Do not mix calls to next() and nextRange() without calling reset() between them. The results of doing so are undefined.
Warning: For speed, UnicodeSet iteration does not check for concurrent modification. Do not alter the UnicodeSet while iterating.
public boolean nextRange()
The order of iteration is all code points ranges in sorted order, followed by all strings sorted order. Ranges are disjoint and non-contiguous. string is undefined unless codepoint == IS_STRING. Do not mix calls to next() and nextRange() without calling reset() between them. The results of doing so are undefined.
public void reset(UnicodeSet uset)
uset
- the set to iterate over.public void reset()
public String getString()
Copyright © 2016 Unicode, Inc. and others.