< prev index next >

src/java.base/share/classes/sun/text/normalizer/UnicodeSetIterator.java

Print this page




  56  * }
  57  * </pre>
  58  *
  59  * <p>To iterate over code point ranges, use a loop like this:
  60  * <pre>
  61  * UnicodeSetIterator it(set);
  62  * while (set.nextRange()) {
  63  *   if (set.codepoint != UnicodeSetIterator::IS_STRING) {
  64  *     processCodepointRange(set.codepoint, set.codepointEnd);
  65  *   } else {
  66  *     processString(set.string);
  67  *   }
  68  * }
  69  * </pre>
  70  * @author M. Davis
  71  * @stable ICU 2.0
  72  */
  73 public class UnicodeSetIterator {
  74 
  75     /**
  76      * Value of <tt>codepoint</tt> if the iterator points to a string.
  77      * If <tt>codepoint == IS_STRING</tt>, then examine
  78      * <tt>string</tt> for the current iteration result.
  79      * @stable ICU 2.0
  80      */
  81     public static int IS_STRING = -1;
  82 
  83     /**
  84      * Current code point, or the special value <tt>IS_STRING</tt>, if
  85      * the iterator points to a string.
  86      * @stable ICU 2.0
  87      */
  88     public int codepoint;
  89 
  90     /**
  91      * When iterating over ranges using <tt>nextRange()</tt>,
  92      * <tt>codepointEnd</tt> contains the inclusive end of the
  93      * iteration range, if <tt>codepoint != IS_STRING</tt>.  If
  94      * iterating over code points using <tt>next()</tt>, or if
  95      * <tt>codepoint == IS_STRING</tt>, then the value of
  96      * <tt>codepointEnd</tt> is undefined.
  97      * @stable ICU 2.0
  98      */
  99     public int codepointEnd;
 100 
 101     /**
 102      * If <tt>codepoint == IS_STRING</tt>, then <tt>string</tt> points
 103      * to the current string.  If <tt>codepoint != IS_STRING</tt>, the
 104      * value of <tt>string</tt> is undefined.
 105      * @stable ICU 2.0
 106      */
 107     public String string;
 108 
 109     /**
 110      * Create an iterator over the given set.
 111      * @param set set to iterate over
 112      * @stable ICU 2.0
 113      */
 114     public UnicodeSetIterator(UnicodeSet set) {
 115         reset(set);
 116     }
 117 
 118     /**
 119      * Returns the next element in the set, either a code point range
 120      * or a string.  If there are no more elements in the set, return
 121      * false.  If <tt>codepoint == IS_STRING</tt>, the value is a
 122      * string in the <tt>string</tt> field.  Otherwise the value is a
 123      * range of one or more code points from <tt>codepoint</tt> to
 124      * <tt>codepointeEnd</tt> inclusive.
 125      *
 126      * <p>The order of iteration is all code points ranges in sorted
 127      * order, followed by all strings sorted order.  Ranges are
 128      * disjoint and non-contiguous.  <tt>string</tt> is undefined
 129      * unless <tt>codepoint == IS_STRING</tt>.  Do not mix calls to
 130      * <tt>next()</tt> and <tt>nextRange()</tt> without calling
 131      * <tt>reset()</tt> between them.  The results of doing so are
 132      * undefined.
 133      *
 134      * @return true if there was another element in the set and this
 135      * object contains the element.
 136      * @stable ICU 2.0
 137      */
 138     public boolean nextRange() {
 139         if (nextElement <= endElement) {
 140             codepointEnd = endElement;
 141             codepoint = nextElement;
 142             nextElement = endElement+1;
 143             return true;
 144         }
 145         if (range < endRange) {
 146             loadRange(++range);
 147             codepointEnd = endElement;
 148             codepoint = nextElement;
 149             nextElement = endElement+1;
 150             return true;
 151         }
 152 
 153         // stringIterator == null iff there are no string elements remaining
 154 
 155         if (stringIterator == null) return false;
 156         codepoint = IS_STRING; // signal that value is actually a string
 157         string = stringIterator.next();
 158         if (!stringIterator.hasNext()) stringIterator = null;
 159         return true;
 160     }
 161 
 162     /**
 163      * Sets this iterator to visit the elements of the given set and
 164      * resets it to the start of that set.  The iterator is valid only
 165      * so long as <tt>set</tt> is valid.
 166      * @param set the set to iterate over.
 167      * @stable ICU 2.0
 168      */
 169     public void reset(UnicodeSet uset) {
 170         set = uset;
 171         reset();
 172     }
 173 
 174     /**
 175      * Resets this iterator to the start of the set.
 176      * @stable ICU 2.0
 177      */
 178     public void reset() {
 179         endRange = set.getRangeCount() - 1;
 180         range = 0;
 181         endElement = -1;
 182         nextElement = 0;
 183         if (endRange >= 0) {
 184             loadRange(range);
 185         }
 186         stringIterator = null;




  56  * }
  57  * </pre>
  58  *
  59  * <p>To iterate over code point ranges, use a loop like this:
  60  * <pre>
  61  * UnicodeSetIterator it(set);
  62  * while (set.nextRange()) {
  63  *   if (set.codepoint != UnicodeSetIterator::IS_STRING) {
  64  *     processCodepointRange(set.codepoint, set.codepointEnd);
  65  *   } else {
  66  *     processString(set.string);
  67  *   }
  68  * }
  69  * </pre>
  70  * @author M. Davis
  71  * @stable ICU 2.0
  72  */
  73 public class UnicodeSetIterator {
  74 
  75     /**
  76      * Value of {@code codepoint} if the iterator points to a string.
  77      * If {@code codepoint == IS_STRING}, then examine
  78      * {@code string} for the current iteration result.
  79      * @stable ICU 2.0
  80      */
  81     public static int IS_STRING = -1;
  82 
  83     /**
  84      * Current code point, or the special value {@code IS_STRING}, if
  85      * the iterator points to a string.
  86      * @stable ICU 2.0
  87      */
  88     public int codepoint;
  89 
  90     /**
  91      * When iterating over ranges using {@code nextRange()},
  92      * {@code codepointEnd} contains the inclusive end of the
  93      * iteration range, if {@code codepoint != IS_STRING}.  If
  94      * iterating over code points using {@code next()}, or if
  95      * {@code codepoint == IS_STRING}, then the value of
  96      * {@code codepointEnd} is undefined.
  97      * @stable ICU 2.0
  98      */
  99     public int codepointEnd;
 100 
 101     /**
 102      * If {@code codepoint == IS_STRING}, then {@code string} points
 103      * to the current string.  If {@code codepoint != IS_STRING}, the
 104      * value of {@code string} is undefined.
 105      * @stable ICU 2.0
 106      */
 107     public String string;
 108 
 109     /**
 110      * Create an iterator over the given set.
 111      * @param set set to iterate over
 112      * @stable ICU 2.0
 113      */
 114     public UnicodeSetIterator(UnicodeSet set) {
 115         reset(set);
 116     }
 117 
 118     /**
 119      * Returns the next element in the set, either a code point range
 120      * or a string.  If there are no more elements in the set, return
 121      * false.  If {@code codepoint == IS_STRING}, the value is a
 122      * string in the {@code string} field.  Otherwise the value is a
 123      * range of one or more code points from {@code codepoint} to
 124      * {@code codepointeEnd} inclusive.
 125      *
 126      * <p>The order of iteration is all code points ranges in sorted
 127      * order, followed by all strings sorted order.  Ranges are
 128      * disjoint and non-contiguous.  {@code string} is undefined
 129      * unless {@code codepoint == IS_STRING}.  Do not mix calls to
 130      * {@code next()} and {@code nextRange()} without calling
 131      * {@code reset()} between them.  The results of doing so are
 132      * undefined.
 133      *
 134      * @return true if there was another element in the set and this
 135      * object contains the element.
 136      * @stable ICU 2.0
 137      */
 138     public boolean nextRange() {
 139         if (nextElement <= endElement) {
 140             codepointEnd = endElement;
 141             codepoint = nextElement;
 142             nextElement = endElement+1;
 143             return true;
 144         }
 145         if (range < endRange) {
 146             loadRange(++range);
 147             codepointEnd = endElement;
 148             codepoint = nextElement;
 149             nextElement = endElement+1;
 150             return true;
 151         }
 152 
 153         // stringIterator == null iff there are no string elements remaining
 154 
 155         if (stringIterator == null) return false;
 156         codepoint = IS_STRING; // signal that value is actually a string
 157         string = stringIterator.next();
 158         if (!stringIterator.hasNext()) stringIterator = null;
 159         return true;
 160     }
 161 
 162     /**
 163      * Sets this iterator to visit the elements of the given set and
 164      * resets it to the start of that set.  The iterator is valid only
 165      * so long as {@code set} is valid.
 166      * @param uset the set to iterate over.
 167      * @stable ICU 2.0
 168      */
 169     public void reset(UnicodeSet uset) {
 170         set = uset;
 171         reset();
 172     }
 173 
 174     /**
 175      * Resets this iterator to the start of the set.
 176      * @stable ICU 2.0
 177      */
 178     public void reset() {
 179         endRange = set.getRangeCount() - 1;
 180         range = 0;
 181         endElement = -1;
 182         nextElement = 0;
 183         if (endRange >= 0) {
 184             loadRange(range);
 185         }
 186         stringIterator = null;


< prev index next >