1 /*
   2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  *******************************************************************************
  28  * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved                     *
  29  *                                                                             *
  30  * The original version of this source code and documentation is copyrighted   *
  31  * and owned by IBM, These materials are provided under terms of a License     *
  32  * Agreement between IBM and Sun. This technology is protected by multiple     *
  33  * US and International patents. This notice and attribution to IBM may not    *
  34  * to removed.                                                                 *
  35  *******************************************************************************
  36  */
  37 
  38 package sun.text.normalizer;
  39 
  40 /**
  41  * <p>Interface for enabling iteration over sets of
  42  * {@code <int index, int value>},
  43  * where index is the sorted integer index in ascending order and value, its
  44  * associated integer value.
  45  * <p>The result for each iteration is the consecutive range of
  46  * {@code <int index, int value>} with the same value. Result is represented by
  47  * {@code <start, limit, value>} where
  48  * <ul>
  49  * <li> start is the starting integer of the result range
  50  * <li> limit is 1 after the maximum integer that follows start, such that
  51  *      all integers between start and (limit - 1), inclusive, have the same
  52  *      associated integer value.
  53  * <li> value is the integer value that all integers from start to (limit - 1)
  54  *      share in common.
  55  * </ul>
  56  * <p>
  57  * Hence value(start) = value(start + 1) = .... = value(start + n) = .... =
  58  * value(limit - 1). However value(start -1) != value(start) and
  59  * value(limit) != value(start).
  60  *
  61  * <p>Most implementations will be created by factory methods, such as the
  62  * character type iterator in UCharacter.getTypeIterator. See example below.
  63  *
  64  * Example of use:<br>
  65  * <pre>
  66  * RangeValueIterator iterator = UCharacter.getTypeIterator();
  67  * RangeValueIterator.Element result = new RangeValueIterator.Element();
  68  * while (iterator.next(result)) {
  69  *     System.out.println("Codepoint \\u" +
  70  *                        Integer.toHexString(result.start) +
  71  *                        " to codepoint \\u" +
  72  *                        Integer.toHexString(result.limit - 1) +
  73  *                        " has the character type " + result.value);
  74  * }
  75  * </pre>
  76  * @author synwee
  77  * @stable ICU 2.6
  78  */
  79 public interface RangeValueIterator
  80 {
  81     // public inner class ---------------------------------------------
  82 
  83     /**
  84     * Return result wrapper for com.ibm.icu.util.RangeValueIterator.
  85     * Stores the start and limit of the continous result range and the
  86     * common value all integers between [start, limit - 1] has.
  87     * @stable ICU 2.6
  88     */
  89     public class Element
  90     {
  91         // public data member ---------------------------------------------
  92 
  93         /**
  94         * Starting integer of the continuous result range that has the same
  95         * value
  96         * @stable ICU 2.6
  97         */
  98         public int start;
  99         /**
 100         * (End + 1) integer of continuous result range that has the same
 101         * value
 102         * @stable ICU 2.6
 103         */
 104         public int limit;
 105         /**
 106         * Gets the common value of the continous result range
 107         * @stable ICU 2.6
 108         */
 109         public int value;
 110 
 111         // public constructor --------------------------------------------
 112 
 113         /**
 114          * Empty default constructor to make javadoc happy
 115          * @stable ICU 2.4
 116          */
 117         public Element()
 118         {
 119         }
 120     }
 121 
 122     // public methods -------------------------------------------------
 123 
 124     /**
 125     * <p>Gets the next maximal result range with a common value and returns
 126     * true if we are not at the end of the iteration, false otherwise.</p>
 127     * <p>If the return boolean is a false, the contents of elements will not
 128     * be updated.</p>
 129     * @param element for storing the result range and value
 130     * @return true if we are not at the end of the iteration, false otherwise.
 131     * @see Element
 132     * @stable ICU 2.6
 133     */
 134     public boolean next(Element element);
 135 
 136     /**
 137     * Resets the iterator to the beginning of the iteration.
 138     * @stable ICU 2.6
 139     */
 140     public void reset();
 141 }