xref: /aosp_15_r20/external/icu/libicu/cts_headers/unicode/alphaindex.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 2011-2014 International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker *******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker */
11*0e209d39SAndroid Build Coastguard Worker 
12*0e209d39SAndroid Build Coastguard Worker #ifndef INDEXCHARS_H
13*0e209d39SAndroid Build Coastguard Worker #define INDEXCHARS_H
14*0e209d39SAndroid Build Coastguard Worker 
15*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/locid.h"
21*0e209d39SAndroid Build Coastguard Worker #include "unicode/unistr.h"
22*0e209d39SAndroid Build Coastguard Worker 
23*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_COLLATION
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker /**
26*0e209d39SAndroid Build Coastguard Worker  * \file
27*0e209d39SAndroid Build Coastguard Worker  * \brief C++ API: Index Characters
28*0e209d39SAndroid Build Coastguard Worker  */
29*0e209d39SAndroid Build Coastguard Worker 
30*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
31*0e209d39SAndroid Build Coastguard Worker 
32*0e209d39SAndroid Build Coastguard Worker /**
33*0e209d39SAndroid Build Coastguard Worker  * Constants for Alphabetic Index Label Types.
34*0e209d39SAndroid Build Coastguard Worker  * The form of these enum constants anticipates having a plain C API
35*0e209d39SAndroid Build Coastguard Worker  * for Alphabetic Indexes that will also use them.
36*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.8
37*0e209d39SAndroid Build Coastguard Worker  */
38*0e209d39SAndroid Build Coastguard Worker typedef enum UAlphabeticIndexLabelType {
39*0e209d39SAndroid Build Coastguard Worker     /**
40*0e209d39SAndroid Build Coastguard Worker      *  Normal Label, typically the starting letter of the names
41*0e209d39SAndroid Build Coastguard Worker      *  in the bucket with this label.
42*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
43*0e209d39SAndroid Build Coastguard Worker      */
44*0e209d39SAndroid Build Coastguard Worker     U_ALPHAINDEX_NORMAL    = 0,
45*0e209d39SAndroid Build Coastguard Worker 
46*0e209d39SAndroid Build Coastguard Worker     /**
47*0e209d39SAndroid Build Coastguard Worker      * Underflow Label.  The bucket with this label contains names
48*0e209d39SAndroid Build Coastguard Worker      * in scripts that sort before any of the bucket labels in this index.
49*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
50*0e209d39SAndroid Build Coastguard Worker      */
51*0e209d39SAndroid Build Coastguard Worker     U_ALPHAINDEX_UNDERFLOW = 1,
52*0e209d39SAndroid Build Coastguard Worker 
53*0e209d39SAndroid Build Coastguard Worker     /**
54*0e209d39SAndroid Build Coastguard Worker      * Inflow Label.  The bucket with this label contains names
55*0e209d39SAndroid Build Coastguard Worker      * in scripts that sort between two of the bucket labels in this index.
56*0e209d39SAndroid Build Coastguard Worker      * Inflow labels are created when an index contains normal labels for
57*0e209d39SAndroid Build Coastguard Worker      * multiple scripts, and skips other scripts that sort between some of the
58*0e209d39SAndroid Build Coastguard Worker      * included scripts.
59*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
60*0e209d39SAndroid Build Coastguard Worker      */
61*0e209d39SAndroid Build Coastguard Worker     U_ALPHAINDEX_INFLOW    = 2,
62*0e209d39SAndroid Build Coastguard Worker 
63*0e209d39SAndroid Build Coastguard Worker     /**
64*0e209d39SAndroid Build Coastguard Worker      * Overflow Label. The bucket with this label contains names in scripts
65*0e209d39SAndroid Build Coastguard Worker      * that sort after all of the bucket labels in this index.
66*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
67*0e209d39SAndroid Build Coastguard Worker      */
68*0e209d39SAndroid Build Coastguard Worker     U_ALPHAINDEX_OVERFLOW  = 3
69*0e209d39SAndroid Build Coastguard Worker } UAlphabeticIndexLabelType;
70*0e209d39SAndroid Build Coastguard Worker 
71*0e209d39SAndroid Build Coastguard Worker 
72*0e209d39SAndroid Build Coastguard Worker struct UHashtable;
73*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
74*0e209d39SAndroid Build Coastguard Worker 
75*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
76*0e209d39SAndroid Build Coastguard Worker 
77*0e209d39SAndroid Build Coastguard Worker // Forward Declarations
78*0e209d39SAndroid Build Coastguard Worker 
79*0e209d39SAndroid Build Coastguard Worker class BucketList;
80*0e209d39SAndroid Build Coastguard Worker class Collator;
81*0e209d39SAndroid Build Coastguard Worker class RuleBasedCollator;
82*0e209d39SAndroid Build Coastguard Worker class StringEnumeration;
83*0e209d39SAndroid Build Coastguard Worker class UnicodeSet;
84*0e209d39SAndroid Build Coastguard Worker class UVector;
85*0e209d39SAndroid Build Coastguard Worker 
86*0e209d39SAndroid Build Coastguard Worker /**
87*0e209d39SAndroid Build Coastguard Worker  * AlphabeticIndex supports the creation of a UI index appropriate for a given language.
88*0e209d39SAndroid Build Coastguard Worker  * It can support either direct use, or use with a client that doesn't support localized collation.
89*0e209d39SAndroid Build Coastguard Worker  * The following is an example of what an index might look like in a UI:
90*0e209d39SAndroid Build Coastguard Worker  *
91*0e209d39SAndroid Build Coastguard Worker  * <pre>
92*0e209d39SAndroid Build Coastguard Worker  *  <b>... A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  ...</b>
93*0e209d39SAndroid Build Coastguard Worker  *
94*0e209d39SAndroid Build Coastguard Worker  *  <b>A</b>
95*0e209d39SAndroid Build Coastguard Worker  *     Addison
96*0e209d39SAndroid Build Coastguard Worker  *     Albertson
97*0e209d39SAndroid Build Coastguard Worker  *     Azensky
98*0e209d39SAndroid Build Coastguard Worker  *  <b>B</b>
99*0e209d39SAndroid Build Coastguard Worker  *     Baker
100*0e209d39SAndroid Build Coastguard Worker  *  ...
101*0e209d39SAndroid Build Coastguard Worker  * </pre>
102*0e209d39SAndroid Build Coastguard Worker  *
103*0e209d39SAndroid Build Coastguard Worker  * The class can generate a list of labels for use as a UI "index", that is, a list of
104*0e209d39SAndroid Build Coastguard Worker  * clickable characters (or character sequences) that allow the user to see a segment
105*0e209d39SAndroid Build Coastguard Worker  * (bucket) of a larger "target" list. That is, each label corresponds to a bucket in
106*0e209d39SAndroid Build Coastguard Worker  * the target list, where everything in the bucket is greater than or equal to the character
107*0e209d39SAndroid Build Coastguard Worker  * (according to the locale's collation). Strings can be added to the index;
108*0e209d39SAndroid Build Coastguard Worker  * they will be in sorted order in the right bucket.
109*0e209d39SAndroid Build Coastguard Worker  * <p>
110*0e209d39SAndroid Build Coastguard Worker  * The class also supports having buckets for strings before the first (underflow),
111*0e209d39SAndroid Build Coastguard Worker  * after the last (overflow), and between scripts (inflow). For example, if the index
112*0e209d39SAndroid Build Coastguard Worker  * is constructed with labels for Russian and English, Greek characters would fall
113*0e209d39SAndroid Build Coastguard Worker  * into an inflow bucket between the other two scripts.
114*0e209d39SAndroid Build Coastguard Worker  * <p>
115*0e209d39SAndroid Build Coastguard Worker  * The AlphabeticIndex class is not intended for public subclassing.
116*0e209d39SAndroid Build Coastguard Worker  *
117*0e209d39SAndroid Build Coastguard Worker  * <p><em>Note:</em> If you expect to have a lot of ASCII or Latin characters
118*0e209d39SAndroid Build Coastguard Worker  * as well as characters from the user's language,
119*0e209d39SAndroid Build Coastguard Worker  * then it is a good idea to call addLabels(Locale::getEnglish(), status).</p>
120*0e209d39SAndroid Build Coastguard Worker  *
121*0e209d39SAndroid Build Coastguard Worker  * <h2>Direct Use</h2>
122*0e209d39SAndroid Build Coastguard Worker  * <p>The following shows an example of building an index directly.
123*0e209d39SAndroid Build Coastguard Worker  *  The "show..." methods below are just to illustrate usage.
124*0e209d39SAndroid Build Coastguard Worker  *
125*0e209d39SAndroid Build Coastguard Worker  * <pre>
126*0e209d39SAndroid Build Coastguard Worker  * // Create a simple index.  "Item" is assumed to be an application
127*0e209d39SAndroid Build Coastguard Worker  * // defined type that the application's UI and other processing knows about,
128*0e209d39SAndroid Build Coastguard Worker  * //  and that has a name.
129*0e209d39SAndroid Build Coastguard Worker  *
130*0e209d39SAndroid Build Coastguard Worker  * UErrorCode status = U_ZERO_ERROR;
131*0e209d39SAndroid Build Coastguard Worker  * AlphabeticIndex index = new AlphabeticIndex(desiredLocale, status);
132*0e209d39SAndroid Build Coastguard Worker  * index->addLabels(additionalLocale, status);
133*0e209d39SAndroid Build Coastguard Worker  * for (Item *item in some source of Items ) {
134*0e209d39SAndroid Build Coastguard Worker  *     index->addRecord(item->name(), item, status);
135*0e209d39SAndroid Build Coastguard Worker  * }
136*0e209d39SAndroid Build Coastguard Worker  * ...
137*0e209d39SAndroid Build Coastguard Worker  * // Show index at top. We could skip or gray out empty buckets
138*0e209d39SAndroid Build Coastguard Worker  *
139*0e209d39SAndroid Build Coastguard Worker  * while (index->nextBucket(status)) {
140*0e209d39SAndroid Build Coastguard Worker  *     if (showAll || index->getBucketRecordCount() != 0) {
141*0e209d39SAndroid Build Coastguard Worker  *         showLabelAtTop(UI, index->getBucketLabel());
142*0e209d39SAndroid Build Coastguard Worker  *     }
143*0e209d39SAndroid Build Coastguard Worker  * }
144*0e209d39SAndroid Build Coastguard Worker  *  ...
145*0e209d39SAndroid Build Coastguard Worker  * // Show the buckets with their contents, skipping empty buckets
146*0e209d39SAndroid Build Coastguard Worker  *
147*0e209d39SAndroid Build Coastguard Worker  * index->resetBucketIterator(status);
148*0e209d39SAndroid Build Coastguard Worker  * while (index->nextBucket(status)) {
149*0e209d39SAndroid Build Coastguard Worker  *    if (index->getBucketRecordCount() != 0) {
150*0e209d39SAndroid Build Coastguard Worker  *        showLabelInList(UI, index->getBucketLabel());
151*0e209d39SAndroid Build Coastguard Worker  *        while (index->nextRecord(status)) {
152*0e209d39SAndroid Build Coastguard Worker  *            showIndexedItem(UI, static_cast<Item *>(index->getRecordData()))
153*0e209d39SAndroid Build Coastguard Worker  * </pre>
154*0e209d39SAndroid Build Coastguard Worker  *
155*0e209d39SAndroid Build Coastguard Worker  * The caller can build different UIs using this class.
156*0e209d39SAndroid Build Coastguard Worker  * For example, an index character could be omitted or grayed-out
157*0e209d39SAndroid Build Coastguard Worker  * if its bucket is empty. Small buckets could also be combined based on size, such as:
158*0e209d39SAndroid Build Coastguard Worker  *
159*0e209d39SAndroid Build Coastguard Worker  * <pre>
160*0e209d39SAndroid Build Coastguard Worker  * <b>... A-F G-N O-Z ...</b>
161*0e209d39SAndroid Build Coastguard Worker  * </pre>
162*0e209d39SAndroid Build Coastguard Worker  *
163*0e209d39SAndroid Build Coastguard Worker  * <h2>Client Support</h2>
164*0e209d39SAndroid Build Coastguard Worker  * <p>Callers can also use the AlphabeticIndex::ImmutableIndex, or the AlphabeticIndex itself,
165*0e209d39SAndroid Build Coastguard Worker  * to support sorting on a client that doesn't support AlphabeticIndex functionality.
166*0e209d39SAndroid Build Coastguard Worker  *
167*0e209d39SAndroid Build Coastguard Worker  * <p>The ImmutableIndex is both immutable and thread-safe.
168*0e209d39SAndroid Build Coastguard Worker  * The corresponding AlphabeticIndex methods are not thread-safe because
169*0e209d39SAndroid Build Coastguard Worker  * they "lazily" build the index buckets.
170*0e209d39SAndroid Build Coastguard Worker  * <ul>
171*0e209d39SAndroid Build Coastguard Worker  * <li>ImmutableIndex.getBucket(index) provides random access to all
172*0e209d39SAndroid Build Coastguard Worker  *     buckets and their labels and label types.
173*0e209d39SAndroid Build Coastguard Worker  * <li>The AlphabeticIndex bucket iterator or ImmutableIndex.getBucket(0..getBucketCount-1)
174*0e209d39SAndroid Build Coastguard Worker  *     can be used to get a list of the labels,
175*0e209d39SAndroid Build Coastguard Worker  *     such as "...", "A", "B",..., and send that list to the client.
176*0e209d39SAndroid Build Coastguard Worker  * <li>When the client has a new name, it sends that name to the server.
177*0e209d39SAndroid Build Coastguard Worker  * The server needs to call the following methods,
178*0e209d39SAndroid Build Coastguard Worker  * and communicate the bucketIndex and collationKey back to the client.
179*0e209d39SAndroid Build Coastguard Worker  *
180*0e209d39SAndroid Build Coastguard Worker  * <pre>
181*0e209d39SAndroid Build Coastguard Worker  * int32_t bucketIndex = index.getBucketIndex(name, status);
182*0e209d39SAndroid Build Coastguard Worker  * const UnicodeString &label = immutableIndex.getBucket(bucketIndex)->getLabel();  // optional
183*0e209d39SAndroid Build Coastguard Worker  * int32_t skLength = collator.getSortKey(name, sk, skCapacity);
184*0e209d39SAndroid Build Coastguard Worker  * </pre>
185*0e209d39SAndroid Build Coastguard Worker  *
186*0e209d39SAndroid Build Coastguard Worker  * <li>The client would put the name (and associated information) into its bucket for bucketIndex. The sort key sk is a
187*0e209d39SAndroid Build Coastguard Worker  * sequence of bytes that can be compared with a binary compare, and produce the right localized result.</li>
188*0e209d39SAndroid Build Coastguard Worker  * </ul>
189*0e209d39SAndroid Build Coastguard Worker  *
190*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.8
191*0e209d39SAndroid Build Coastguard Worker  */
192*0e209d39SAndroid Build Coastguard Worker class U_I18N_API AlphabeticIndex: public UObject {
193*0e209d39SAndroid Build Coastguard Worker public:
194*0e209d39SAndroid Build Coastguard Worker      /**
195*0e209d39SAndroid Build Coastguard Worker       * An index "bucket" with a label string and type.
196*0e209d39SAndroid Build Coastguard Worker       * It is referenced by getBucketIndex(),
197*0e209d39SAndroid Build Coastguard Worker       * and returned by ImmutableIndex.getBucket().
198*0e209d39SAndroid Build Coastguard Worker       *
199*0e209d39SAndroid Build Coastguard Worker       * The Bucket class is not intended for public subclassing.
200*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 51
201*0e209d39SAndroid Build Coastguard Worker       */
202*0e209d39SAndroid Build Coastguard Worker      class U_I18N_API Bucket : public UObject {
203*0e209d39SAndroid Build Coastguard Worker      public:
204*0e209d39SAndroid Build Coastguard Worker         /**
205*0e209d39SAndroid Build Coastguard Worker          * Destructor.
206*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
207*0e209d39SAndroid Build Coastguard Worker          */
208*0e209d39SAndroid Build Coastguard Worker         virtual ~Bucket();
209*0e209d39SAndroid Build Coastguard Worker 
210*0e209d39SAndroid Build Coastguard Worker         /**
211*0e209d39SAndroid Build Coastguard Worker          * Returns the label string.
212*0e209d39SAndroid Build Coastguard Worker          *
213*0e209d39SAndroid Build Coastguard Worker          * @return the label string for the bucket
214*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
215*0e209d39SAndroid Build Coastguard Worker          */
getLabel()216*0e209d39SAndroid Build Coastguard Worker         const UnicodeString &getLabel() const { return label_; }
217*0e209d39SAndroid Build Coastguard Worker         /**
218*0e209d39SAndroid Build Coastguard Worker          * Returns whether this bucket is a normal, underflow, overflow, or inflow bucket.
219*0e209d39SAndroid Build Coastguard Worker          *
220*0e209d39SAndroid Build Coastguard Worker          * @return the bucket label type
221*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
222*0e209d39SAndroid Build Coastguard Worker          */
getLabelType()223*0e209d39SAndroid Build Coastguard Worker         UAlphabeticIndexLabelType getLabelType() const { return labelType_; }
224*0e209d39SAndroid Build Coastguard Worker 
225*0e209d39SAndroid Build Coastguard Worker      private:
226*0e209d39SAndroid Build Coastguard Worker         friend class AlphabeticIndex;
227*0e209d39SAndroid Build Coastguard Worker         friend class BucketList;
228*0e209d39SAndroid Build Coastguard Worker 
229*0e209d39SAndroid Build Coastguard Worker         UnicodeString label_;
230*0e209d39SAndroid Build Coastguard Worker         UnicodeString lowerBoundary_;
231*0e209d39SAndroid Build Coastguard Worker         UAlphabeticIndexLabelType labelType_;
232*0e209d39SAndroid Build Coastguard Worker         Bucket *displayBucket_;
233*0e209d39SAndroid Build Coastguard Worker         int32_t displayIndex_;
234*0e209d39SAndroid Build Coastguard Worker         UVector *records_;  // Records are owned by the inputList_ vector.
235*0e209d39SAndroid Build Coastguard Worker 
236*0e209d39SAndroid Build Coastguard Worker         Bucket(const UnicodeString &label,   // Parameter strings are copied.
237*0e209d39SAndroid Build Coastguard Worker                const UnicodeString &lowerBoundary,
238*0e209d39SAndroid Build Coastguard Worker                UAlphabeticIndexLabelType type);
239*0e209d39SAndroid Build Coastguard Worker      };
240*0e209d39SAndroid Build Coastguard Worker 
241*0e209d39SAndroid Build Coastguard Worker     /**
242*0e209d39SAndroid Build Coastguard Worker      * Immutable, thread-safe version of AlphabeticIndex.
243*0e209d39SAndroid Build Coastguard Worker      * This class provides thread-safe methods for bucketing,
244*0e209d39SAndroid Build Coastguard Worker      * and random access to buckets and their properties,
245*0e209d39SAndroid Build Coastguard Worker      * but does not offer adding records to the index.
246*0e209d39SAndroid Build Coastguard Worker      *
247*0e209d39SAndroid Build Coastguard Worker      * The ImmutableIndex class is not intended for public subclassing.
248*0e209d39SAndroid Build Coastguard Worker      *
249*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
250*0e209d39SAndroid Build Coastguard Worker      */
251*0e209d39SAndroid Build Coastguard Worker     class U_I18N_API ImmutableIndex : public UObject {
252*0e209d39SAndroid Build Coastguard Worker     public:
253*0e209d39SAndroid Build Coastguard Worker         /**
254*0e209d39SAndroid Build Coastguard Worker          * Destructor.
255*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
256*0e209d39SAndroid Build Coastguard Worker          */
257*0e209d39SAndroid Build Coastguard Worker         virtual ~ImmutableIndex();
258*0e209d39SAndroid Build Coastguard Worker 
259*0e209d39SAndroid Build Coastguard Worker         /**
260*0e209d39SAndroid Build Coastguard Worker          * Returns the number of index buckets and labels, including underflow/inflow/overflow.
261*0e209d39SAndroid Build Coastguard Worker          *
262*0e209d39SAndroid Build Coastguard Worker          * @return the number of index buckets
263*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
264*0e209d39SAndroid Build Coastguard Worker          */
265*0e209d39SAndroid Build Coastguard Worker         int32_t getBucketCount() const;
266*0e209d39SAndroid Build Coastguard Worker 
267*0e209d39SAndroid Build Coastguard Worker         /**
268*0e209d39SAndroid Build Coastguard Worker          * Finds the index bucket for the given name and returns the number of that bucket.
269*0e209d39SAndroid Build Coastguard Worker          * Use getBucket() to get the bucket's properties.
270*0e209d39SAndroid Build Coastguard Worker          *
271*0e209d39SAndroid Build Coastguard Worker          * @param name the string to be sorted into an index bucket
272*0e209d39SAndroid Build Coastguard Worker          * @param errorCode Error code, will be set with the reason if the
273*0e209d39SAndroid Build Coastguard Worker          *                  operation fails.
274*0e209d39SAndroid Build Coastguard Worker          * @return the bucket number for the name
275*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
276*0e209d39SAndroid Build Coastguard Worker          */
277*0e209d39SAndroid Build Coastguard Worker         int32_t getBucketIndex(const UnicodeString &name, UErrorCode &errorCode) const;
278*0e209d39SAndroid Build Coastguard Worker 
279*0e209d39SAndroid Build Coastguard Worker         /**
280*0e209d39SAndroid Build Coastguard Worker          * Returns the index-th bucket. Returns nullptr if the index is out of range.
281*0e209d39SAndroid Build Coastguard Worker          *
282*0e209d39SAndroid Build Coastguard Worker          * @param index bucket number
283*0e209d39SAndroid Build Coastguard Worker          * @return the index-th bucket
284*0e209d39SAndroid Build Coastguard Worker          * @stable ICU 51
285*0e209d39SAndroid Build Coastguard Worker          */
286*0e209d39SAndroid Build Coastguard Worker         const Bucket *getBucket(int32_t index) const;
287*0e209d39SAndroid Build Coastguard Worker 
288*0e209d39SAndroid Build Coastguard Worker     private:
289*0e209d39SAndroid Build Coastguard Worker         friend class AlphabeticIndex;
290*0e209d39SAndroid Build Coastguard Worker 
ImmutableIndex(BucketList * bucketList,Collator * collatorPrimaryOnly)291*0e209d39SAndroid Build Coastguard Worker         ImmutableIndex(BucketList *bucketList, Collator *collatorPrimaryOnly)
292*0e209d39SAndroid Build Coastguard Worker                 : buckets_(bucketList), collatorPrimaryOnly_(collatorPrimaryOnly) {}
293*0e209d39SAndroid Build Coastguard Worker 
294*0e209d39SAndroid Build Coastguard Worker         BucketList *buckets_;
295*0e209d39SAndroid Build Coastguard Worker         Collator *collatorPrimaryOnly_;
296*0e209d39SAndroid Build Coastguard Worker     };
297*0e209d39SAndroid Build Coastguard Worker 
298*0e209d39SAndroid Build Coastguard Worker     /**
299*0e209d39SAndroid Build Coastguard Worker      * Construct an AlphabeticIndex object for the specified locale.  If the locale's
300*0e209d39SAndroid Build Coastguard Worker      * data does not include index characters, a set of them will be
301*0e209d39SAndroid Build Coastguard Worker      * synthesized based on the locale's exemplar characters.  The locale
302*0e209d39SAndroid Build Coastguard Worker      * determines the sorting order for both the index characters and the
303*0e209d39SAndroid Build Coastguard Worker      * user item names appearing under each Index character.
304*0e209d39SAndroid Build Coastguard Worker      *
305*0e209d39SAndroid Build Coastguard Worker      * @param locale the desired locale.
306*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the construction
307*0e209d39SAndroid Build Coastguard Worker      *               of the AlphabeticIndex object fails.
308*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
309*0e209d39SAndroid Build Coastguard Worker      */
310*0e209d39SAndroid Build Coastguard Worker      AlphabeticIndex(const Locale &locale, UErrorCode &status);
311*0e209d39SAndroid Build Coastguard Worker 
312*0e209d39SAndroid Build Coastguard Worker    /**
313*0e209d39SAndroid Build Coastguard Worker      * Construct an AlphabeticIndex that uses a specific collator.
314*0e209d39SAndroid Build Coastguard Worker      *
315*0e209d39SAndroid Build Coastguard Worker      * The index will be created with no labels; the addLabels() function must be called
316*0e209d39SAndroid Build Coastguard Worker      * after creation to add the desired labels to the index.
317*0e209d39SAndroid Build Coastguard Worker      *
318*0e209d39SAndroid Build Coastguard Worker      * The index adopts the collator, and is responsible for deleting it.
319*0e209d39SAndroid Build Coastguard Worker      * The caller should make no further use of the collator after creating the index.
320*0e209d39SAndroid Build Coastguard Worker      *
321*0e209d39SAndroid Build Coastguard Worker      * @param collator The collator to use to order the contents of this index.
322*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the
323*0e209d39SAndroid Build Coastguard Worker      *               operation fails.
324*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
325*0e209d39SAndroid Build Coastguard Worker      */
326*0e209d39SAndroid Build Coastguard Worker     AlphabeticIndex(RuleBasedCollator *collator, UErrorCode &status);
327*0e209d39SAndroid Build Coastguard Worker 
328*0e209d39SAndroid Build Coastguard Worker     /**
329*0e209d39SAndroid Build Coastguard Worker      * Add Labels to this Index.  The labels are additions to those
330*0e209d39SAndroid Build Coastguard Worker      * that are already in the index; they do not replace the existing
331*0e209d39SAndroid Build Coastguard Worker      * ones.
332*0e209d39SAndroid Build Coastguard Worker      * @param additions The additional characters to add to the index, such as A-Z.
333*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the
334*0e209d39SAndroid Build Coastguard Worker      *               operation fails.
335*0e209d39SAndroid Build Coastguard Worker      * @return this, for chaining
336*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
337*0e209d39SAndroid Build Coastguard Worker      */
338*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &addLabels(const UnicodeSet &additions, UErrorCode &status);
339*0e209d39SAndroid Build Coastguard Worker 
340*0e209d39SAndroid Build Coastguard Worker     /**
341*0e209d39SAndroid Build Coastguard Worker      * Add the index characters from a Locale to the index.  The labels
342*0e209d39SAndroid Build Coastguard Worker      * are added to those that are already in the index; they do not replace the
343*0e209d39SAndroid Build Coastguard Worker      * existing index characters.  The collation order for this index is not
344*0e209d39SAndroid Build Coastguard Worker      * changed; it remains that of the locale that was originally specified
345*0e209d39SAndroid Build Coastguard Worker      * when creating this Index.
346*0e209d39SAndroid Build Coastguard Worker      *
347*0e209d39SAndroid Build Coastguard Worker      * @param locale The locale whose index characters are to be added.
348*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the
349*0e209d39SAndroid Build Coastguard Worker      *               operation fails.
350*0e209d39SAndroid Build Coastguard Worker      * @return this, for chaining
351*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
352*0e209d39SAndroid Build Coastguard Worker      */
353*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &addLabels(const Locale &locale, UErrorCode &status);
354*0e209d39SAndroid Build Coastguard Worker 
355*0e209d39SAndroid Build Coastguard Worker      /**
356*0e209d39SAndroid Build Coastguard Worker       * Destructor
357*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 4.8
358*0e209d39SAndroid Build Coastguard Worker       */
359*0e209d39SAndroid Build Coastguard Worker     virtual ~AlphabeticIndex();
360*0e209d39SAndroid Build Coastguard Worker 
361*0e209d39SAndroid Build Coastguard Worker     /**
362*0e209d39SAndroid Build Coastguard Worker      * Builds an immutable, thread-safe version of this instance, without data records.
363*0e209d39SAndroid Build Coastguard Worker      *
364*0e209d39SAndroid Build Coastguard Worker      * @return an immutable index instance
365*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 51
366*0e209d39SAndroid Build Coastguard Worker      */
367*0e209d39SAndroid Build Coastguard Worker     ImmutableIndex *buildImmutableIndex(UErrorCode &errorCode);
368*0e209d39SAndroid Build Coastguard Worker 
369*0e209d39SAndroid Build Coastguard Worker     /**
370*0e209d39SAndroid Build Coastguard Worker      * Get the Collator that establishes the ordering of the items in this index.
371*0e209d39SAndroid Build Coastguard Worker      * Ownership of the collator remains with the AlphabeticIndex instance.
372*0e209d39SAndroid Build Coastguard Worker      *
373*0e209d39SAndroid Build Coastguard Worker      * The returned collator is a reference to the internal collator used by this
374*0e209d39SAndroid Build Coastguard Worker      * index.  It may be safely used to compare the names of items or to get
375*0e209d39SAndroid Build Coastguard Worker      * sort keys for names.  However if any settings need to be changed,
376*0e209d39SAndroid Build Coastguard Worker      * or other non-const methods called, a cloned copy must be made first.
377*0e209d39SAndroid Build Coastguard Worker      *
378*0e209d39SAndroid Build Coastguard Worker      * @return The collator
379*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
380*0e209d39SAndroid Build Coastguard Worker      */
381*0e209d39SAndroid Build Coastguard Worker     virtual const RuleBasedCollator &getCollator() const;
382*0e209d39SAndroid Build Coastguard Worker 
383*0e209d39SAndroid Build Coastguard Worker 
384*0e209d39SAndroid Build Coastguard Worker    /**
385*0e209d39SAndroid Build Coastguard Worker      * Get the default label used for abbreviated buckets *between* other index characters.
386*0e209d39SAndroid Build Coastguard Worker      * For example, consider the labels when Latin (X Y Z) and Greek (Α Β Γ) are used:
387*0e209d39SAndroid Build Coastguard Worker      *
388*0e209d39SAndroid Build Coastguard Worker      *     X Y Z ... Α Β Γ.
389*0e209d39SAndroid Build Coastguard Worker      *
390*0e209d39SAndroid Build Coastguard Worker      * @return inflow label
391*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
392*0e209d39SAndroid Build Coastguard Worker      */
393*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString &getInflowLabel() const;
394*0e209d39SAndroid Build Coastguard Worker 
395*0e209d39SAndroid Build Coastguard Worker    /**
396*0e209d39SAndroid Build Coastguard Worker      * Set the default label used for abbreviated buckets <i>between</i> other index characters.
397*0e209d39SAndroid Build Coastguard Worker      * An inflow label will be automatically inserted if two otherwise-adjacent label characters
398*0e209d39SAndroid Build Coastguard Worker      * are from different scripts, e.g. Latin and Cyrillic, and a third script, e.g. Greek,
399*0e209d39SAndroid Build Coastguard Worker      * sorts between the two.  The default inflow character is an ellipsis (...)
400*0e209d39SAndroid Build Coastguard Worker      *
401*0e209d39SAndroid Build Coastguard Worker      * @param inflowLabel the new Inflow label.
402*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the operation fails.
403*0e209d39SAndroid Build Coastguard Worker      * @return this
404*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
405*0e209d39SAndroid Build Coastguard Worker      */
406*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &setInflowLabel(const UnicodeString &inflowLabel, UErrorCode &status);
407*0e209d39SAndroid Build Coastguard Worker 
408*0e209d39SAndroid Build Coastguard Worker 
409*0e209d39SAndroid Build Coastguard Worker    /**
410*0e209d39SAndroid Build Coastguard Worker      * Get the special label used for items that sort after the last normal label,
411*0e209d39SAndroid Build Coastguard Worker      * and that would not otherwise have an appropriate label.
412*0e209d39SAndroid Build Coastguard Worker      *
413*0e209d39SAndroid Build Coastguard Worker      * @return the overflow label
414*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
415*0e209d39SAndroid Build Coastguard Worker      */
416*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString &getOverflowLabel() const;
417*0e209d39SAndroid Build Coastguard Worker 
418*0e209d39SAndroid Build Coastguard Worker 
419*0e209d39SAndroid Build Coastguard Worker    /**
420*0e209d39SAndroid Build Coastguard Worker      * Set the label used for items that sort after the last normal label,
421*0e209d39SAndroid Build Coastguard Worker      * and that would not otherwise have an appropriate label.
422*0e209d39SAndroid Build Coastguard Worker      *
423*0e209d39SAndroid Build Coastguard Worker      * @param overflowLabel the new overflow label.
424*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the operation fails.
425*0e209d39SAndroid Build Coastguard Worker      * @return this
426*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
427*0e209d39SAndroid Build Coastguard Worker      */
428*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &setOverflowLabel(const UnicodeString &overflowLabel, UErrorCode &status);
429*0e209d39SAndroid Build Coastguard Worker 
430*0e209d39SAndroid Build Coastguard Worker    /**
431*0e209d39SAndroid Build Coastguard Worker      * Get the special label used for items that sort before the first normal label,
432*0e209d39SAndroid Build Coastguard Worker      * and that would not otherwise have an appropriate label.
433*0e209d39SAndroid Build Coastguard Worker      *
434*0e209d39SAndroid Build Coastguard Worker      * @return underflow label
435*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
436*0e209d39SAndroid Build Coastguard Worker      */
437*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString &getUnderflowLabel() const;
438*0e209d39SAndroid Build Coastguard Worker 
439*0e209d39SAndroid Build Coastguard Worker    /**
440*0e209d39SAndroid Build Coastguard Worker      * Set the label used for items that sort before the first normal label,
441*0e209d39SAndroid Build Coastguard Worker      * and that would not otherwise have an appropriate label.
442*0e209d39SAndroid Build Coastguard Worker      *
443*0e209d39SAndroid Build Coastguard Worker      * @param underflowLabel the new underflow label.
444*0e209d39SAndroid Build Coastguard Worker      * @param status Error code, will be set with the reason if the operation fails.
445*0e209d39SAndroid Build Coastguard Worker      * @return this
446*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
447*0e209d39SAndroid Build Coastguard Worker      */
448*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &setUnderflowLabel(const UnicodeString &underflowLabel, UErrorCode &status);
449*0e209d39SAndroid Build Coastguard Worker 
450*0e209d39SAndroid Build Coastguard Worker 
451*0e209d39SAndroid Build Coastguard Worker     /**
452*0e209d39SAndroid Build Coastguard Worker      * Get the limit on the number of labels permitted in the index.
453*0e209d39SAndroid Build Coastguard Worker      * The number does not include over, under and inflow labels.
454*0e209d39SAndroid Build Coastguard Worker      *
455*0e209d39SAndroid Build Coastguard Worker      * @return maxLabelCount maximum number of labels.
456*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
457*0e209d39SAndroid Build Coastguard Worker      */
458*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getMaxLabelCount() const;
459*0e209d39SAndroid Build Coastguard Worker 
460*0e209d39SAndroid Build Coastguard Worker     /**
461*0e209d39SAndroid Build Coastguard Worker      * Set a limit on the number of labels permitted in the index.
462*0e209d39SAndroid Build Coastguard Worker      * The number does not include over, under and inflow labels.
463*0e209d39SAndroid Build Coastguard Worker      * Currently, if the number is exceeded, then every
464*0e209d39SAndroid Build Coastguard Worker      * nth item is removed to bring the count down.
465*0e209d39SAndroid Build Coastguard Worker      * A more sophisticated mechanism may be available in the future.
466*0e209d39SAndroid Build Coastguard Worker      *
467*0e209d39SAndroid Build Coastguard Worker      * @param maxLabelCount the maximum number of labels.
468*0e209d39SAndroid Build Coastguard Worker      * @param status error code
469*0e209d39SAndroid Build Coastguard Worker      * @return This, for chaining
470*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
471*0e209d39SAndroid Build Coastguard Worker      */
472*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &setMaxLabelCount(int32_t maxLabelCount, UErrorCode &status);
473*0e209d39SAndroid Build Coastguard Worker 
474*0e209d39SAndroid Build Coastguard Worker 
475*0e209d39SAndroid Build Coastguard Worker     /**
476*0e209d39SAndroid Build Coastguard Worker      * Add a record to the index.  Each record will be associated with an index Bucket
477*0e209d39SAndroid Build Coastguard Worker      *  based on the record's name.  The list of records for each bucket will be sorted
478*0e209d39SAndroid Build Coastguard Worker      *  based on the collation ordering of the names in the index's locale.
479*0e209d39SAndroid Build Coastguard Worker      *  Records with duplicate names are permitted; they will be kept in the order
480*0e209d39SAndroid Build Coastguard Worker      *  that they were added.
481*0e209d39SAndroid Build Coastguard Worker      *
482*0e209d39SAndroid Build Coastguard Worker      * @param name The display name for the Record.  The Record will be placed in
483*0e209d39SAndroid Build Coastguard Worker      *             a bucket based on this name.
484*0e209d39SAndroid Build Coastguard Worker      * @param data An optional pointer to user data associated with this
485*0e209d39SAndroid Build Coastguard Worker      *             item.  When iterating the contents of a bucket, both the
486*0e209d39SAndroid Build Coastguard Worker      *             data pointer the name will be available for each Record.
487*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
488*0e209d39SAndroid Build Coastguard Worker      * @return        This, for chaining.
489*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
490*0e209d39SAndroid Build Coastguard Worker      */
491*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &addRecord(const UnicodeString &name, const void *data, UErrorCode &status);
492*0e209d39SAndroid Build Coastguard Worker 
493*0e209d39SAndroid Build Coastguard Worker     /**
494*0e209d39SAndroid Build Coastguard Worker      * Remove all Records from the Index.  The set of Buckets, which define the headings under
495*0e209d39SAndroid Build Coastguard Worker      * which records are classified, is not altered.
496*0e209d39SAndroid Build Coastguard Worker      *
497*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
498*0e209d39SAndroid Build Coastguard Worker      * @return        This, for chaining.
499*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
500*0e209d39SAndroid Build Coastguard Worker      */
501*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &clearRecords(UErrorCode &status);
502*0e209d39SAndroid Build Coastguard Worker 
503*0e209d39SAndroid Build Coastguard Worker 
504*0e209d39SAndroid Build Coastguard Worker     /**  Get the number of labels in this index.
505*0e209d39SAndroid Build Coastguard Worker      *      Note: may trigger lazy index construction.
506*0e209d39SAndroid Build Coastguard Worker      *
507*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
508*0e209d39SAndroid Build Coastguard Worker      * @return        The number of labels in this index, including any under, over or
509*0e209d39SAndroid Build Coastguard Worker      *                in-flow labels.
510*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
511*0e209d39SAndroid Build Coastguard Worker      */
512*0e209d39SAndroid Build Coastguard Worker     virtual int32_t  getBucketCount(UErrorCode &status);
513*0e209d39SAndroid Build Coastguard Worker 
514*0e209d39SAndroid Build Coastguard Worker 
515*0e209d39SAndroid Build Coastguard Worker     /**  Get the total number of Records in this index, that is, the number
516*0e209d39SAndroid Build Coastguard Worker      *   of <name, data> pairs added.
517*0e209d39SAndroid Build Coastguard Worker      *
518*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
519*0e209d39SAndroid Build Coastguard Worker      * @return        The number of records in this index, that is, the total number
520*0e209d39SAndroid Build Coastguard Worker      *                of (name, data) items added with addRecord().
521*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
522*0e209d39SAndroid Build Coastguard Worker      */
523*0e209d39SAndroid Build Coastguard Worker     virtual int32_t  getRecordCount(UErrorCode &status);
524*0e209d39SAndroid Build Coastguard Worker 
525*0e209d39SAndroid Build Coastguard Worker 
526*0e209d39SAndroid Build Coastguard Worker 
527*0e209d39SAndroid Build Coastguard Worker     /**
528*0e209d39SAndroid Build Coastguard Worker      *   Given the name of a record, return the zero-based index of the Bucket
529*0e209d39SAndroid Build Coastguard Worker      *   in which the item should appear.  The name need not be in the index.
530*0e209d39SAndroid Build Coastguard Worker      *   A Record will not be added to the index by this function.
531*0e209d39SAndroid Build Coastguard Worker      *   Bucket numbers are zero-based, in Bucket iteration order.
532*0e209d39SAndroid Build Coastguard Worker      *
533*0e209d39SAndroid Build Coastguard Worker      * @param itemName  The name whose bucket position in the index is to be determined.
534*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
535*0e209d39SAndroid Build Coastguard Worker      * @return The bucket number for this name.
536*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
537*0e209d39SAndroid Build Coastguard Worker      *
538*0e209d39SAndroid Build Coastguard Worker      */
539*0e209d39SAndroid Build Coastguard Worker     virtual int32_t  getBucketIndex(const UnicodeString &itemName, UErrorCode &status);
540*0e209d39SAndroid Build Coastguard Worker 
541*0e209d39SAndroid Build Coastguard Worker 
542*0e209d39SAndroid Build Coastguard Worker     /**
543*0e209d39SAndroid Build Coastguard Worker      *   Get the zero based index of the current Bucket from an iteration
544*0e209d39SAndroid Build Coastguard Worker      *   over the Buckets of this index.  Return -1 if no iteration is in process.
545*0e209d39SAndroid Build Coastguard Worker      *   @return  the index of the current Bucket
546*0e209d39SAndroid Build Coastguard Worker      *   @stable ICU 4.8
547*0e209d39SAndroid Build Coastguard Worker      */
548*0e209d39SAndroid Build Coastguard Worker     virtual int32_t  getBucketIndex() const;
549*0e209d39SAndroid Build Coastguard Worker 
550*0e209d39SAndroid Build Coastguard Worker 
551*0e209d39SAndroid Build Coastguard Worker     /**
552*0e209d39SAndroid Build Coastguard Worker      *   Advance the iteration over the Buckets of this index.  Return false if
553*0e209d39SAndroid Build Coastguard Worker      *   there are no more Buckets.
554*0e209d39SAndroid Build Coastguard Worker      *
555*0e209d39SAndroid Build Coastguard Worker      *   @param status  Error code, will be set with the reason if the operation fails.
556*0e209d39SAndroid Build Coastguard Worker      *   U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
557*0e209d39SAndroid Build Coastguard Worker      *   an enumeration of its contents are in process.
558*0e209d39SAndroid Build Coastguard Worker      *
559*0e209d39SAndroid Build Coastguard Worker      *   @return true if success, false if at end of iteration
560*0e209d39SAndroid Build Coastguard Worker      *   @stable ICU 4.8
561*0e209d39SAndroid Build Coastguard Worker      */
562*0e209d39SAndroid Build Coastguard Worker     virtual UBool nextBucket(UErrorCode &status);
563*0e209d39SAndroid Build Coastguard Worker 
564*0e209d39SAndroid Build Coastguard Worker     /**
565*0e209d39SAndroid Build Coastguard Worker      *   Return the name of the Label of the current bucket from an iteration over the buckets.
566*0e209d39SAndroid Build Coastguard Worker      *   If the iteration is before the first Bucket (nextBucket() has not been called),
567*0e209d39SAndroid Build Coastguard Worker      *   or after the last, return an empty string.
568*0e209d39SAndroid Build Coastguard Worker      *
569*0e209d39SAndroid Build Coastguard Worker      *   @return the bucket label.
570*0e209d39SAndroid Build Coastguard Worker      *   @stable ICU 4.8
571*0e209d39SAndroid Build Coastguard Worker      */
572*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString &getBucketLabel() const;
573*0e209d39SAndroid Build Coastguard Worker 
574*0e209d39SAndroid Build Coastguard Worker     /**
575*0e209d39SAndroid Build Coastguard Worker      *  Return the type of the label for the current Bucket (selected by the
576*0e209d39SAndroid Build Coastguard Worker      *  iteration over Buckets.)
577*0e209d39SAndroid Build Coastguard Worker      *
578*0e209d39SAndroid Build Coastguard Worker      * @return the label type.
579*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
580*0e209d39SAndroid Build Coastguard Worker      */
581*0e209d39SAndroid Build Coastguard Worker     virtual UAlphabeticIndexLabelType getBucketLabelType() const;
582*0e209d39SAndroid Build Coastguard Worker 
583*0e209d39SAndroid Build Coastguard Worker     /**
584*0e209d39SAndroid Build Coastguard Worker       * Get the number of <name, data> Records in the current Bucket.
585*0e209d39SAndroid Build Coastguard Worker       * If the current bucket iteration position is before the first label or after the
586*0e209d39SAndroid Build Coastguard Worker       * last, return 0.
587*0e209d39SAndroid Build Coastguard Worker       *
588*0e209d39SAndroid Build Coastguard Worker       *  @return the number of Records.
589*0e209d39SAndroid Build Coastguard Worker       *  @stable ICU 4.8
590*0e209d39SAndroid Build Coastguard Worker       */
591*0e209d39SAndroid Build Coastguard Worker     virtual int32_t getBucketRecordCount() const;
592*0e209d39SAndroid Build Coastguard Worker 
593*0e209d39SAndroid Build Coastguard Worker 
594*0e209d39SAndroid Build Coastguard Worker     /**
595*0e209d39SAndroid Build Coastguard Worker      *  Reset the Bucket iteration for this index.  The next call to nextBucket()
596*0e209d39SAndroid Build Coastguard Worker      *  will restart the iteration at the first label.
597*0e209d39SAndroid Build Coastguard Worker      *
598*0e209d39SAndroid Build Coastguard Worker      * @param status  Error code, will be set with the reason if the operation fails.
599*0e209d39SAndroid Build Coastguard Worker      * @return        this, for chaining.
600*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 4.8
601*0e209d39SAndroid Build Coastguard Worker      */
602*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &resetBucketIterator(UErrorCode &status);
603*0e209d39SAndroid Build Coastguard Worker 
604*0e209d39SAndroid Build Coastguard Worker     /**
605*0e209d39SAndroid Build Coastguard Worker      * Advance to the next record in the current Bucket.
606*0e209d39SAndroid Build Coastguard Worker      * When nextBucket() is called, Record iteration is reset to just before the
607*0e209d39SAndroid Build Coastguard Worker      * first Record in the new Bucket.
608*0e209d39SAndroid Build Coastguard Worker      *
609*0e209d39SAndroid Build Coastguard Worker      *   @param status  Error code, will be set with the reason if the operation fails.
610*0e209d39SAndroid Build Coastguard Worker      *   U_ENUM_OUT_OF_SYNC_ERROR will be reported if the index is modified while
611*0e209d39SAndroid Build Coastguard Worker      *   an enumeration of its contents are in process.
612*0e209d39SAndroid Build Coastguard Worker      *   @return true if successful, false when the iteration advances past the last item.
613*0e209d39SAndroid Build Coastguard Worker      *   @stable ICU 4.8
614*0e209d39SAndroid Build Coastguard Worker      */
615*0e209d39SAndroid Build Coastguard Worker     virtual UBool nextRecord(UErrorCode &status);
616*0e209d39SAndroid Build Coastguard Worker 
617*0e209d39SAndroid Build Coastguard Worker     /**
618*0e209d39SAndroid Build Coastguard Worker      * Get the name of the current Record.
619*0e209d39SAndroid Build Coastguard Worker      * Return an empty string if the Record iteration position is before first
620*0e209d39SAndroid Build Coastguard Worker      * or after the last.
621*0e209d39SAndroid Build Coastguard Worker      *
622*0e209d39SAndroid Build Coastguard Worker      *  @return The name of the current index item.
623*0e209d39SAndroid Build Coastguard Worker      *  @stable ICU 4.8
624*0e209d39SAndroid Build Coastguard Worker      */
625*0e209d39SAndroid Build Coastguard Worker     virtual const UnicodeString &getRecordName() const;
626*0e209d39SAndroid Build Coastguard Worker 
627*0e209d39SAndroid Build Coastguard Worker 
628*0e209d39SAndroid Build Coastguard Worker     /**
629*0e209d39SAndroid Build Coastguard Worker      * Return the data pointer of the Record currently being iterated over.
630*0e209d39SAndroid Build Coastguard Worker      * Return nullptr if the current iteration position before the first item in this Bucket,
631*0e209d39SAndroid Build Coastguard Worker      * or after the last.
632*0e209d39SAndroid Build Coastguard Worker      *
633*0e209d39SAndroid Build Coastguard Worker      *  @return The current Record's data pointer.
634*0e209d39SAndroid Build Coastguard Worker      *  @stable ICU 4.8
635*0e209d39SAndroid Build Coastguard Worker      */
636*0e209d39SAndroid Build Coastguard Worker     virtual const void *getRecordData() const;
637*0e209d39SAndroid Build Coastguard Worker 
638*0e209d39SAndroid Build Coastguard Worker 
639*0e209d39SAndroid Build Coastguard Worker     /**
640*0e209d39SAndroid Build Coastguard Worker      * Reset the Record iterator position to before the first Record in the current Bucket.
641*0e209d39SAndroid Build Coastguard Worker      *
642*0e209d39SAndroid Build Coastguard Worker      *  @return This, for chaining.
643*0e209d39SAndroid Build Coastguard Worker      *  @stable ICU 4.8
644*0e209d39SAndroid Build Coastguard Worker      */
645*0e209d39SAndroid Build Coastguard Worker     virtual AlphabeticIndex &resetRecordIterator();
646*0e209d39SAndroid Build Coastguard Worker 
647*0e209d39SAndroid Build Coastguard Worker private:
648*0e209d39SAndroid Build Coastguard Worker      /**
649*0e209d39SAndroid Build Coastguard Worker       * No Copy constructor.
650*0e209d39SAndroid Build Coastguard Worker       * @internal (private)
651*0e209d39SAndroid Build Coastguard Worker       */
652*0e209d39SAndroid Build Coastguard Worker      AlphabeticIndex(const AlphabeticIndex &other) = delete;
653*0e209d39SAndroid Build Coastguard Worker 
654*0e209d39SAndroid Build Coastguard Worker      /**
655*0e209d39SAndroid Build Coastguard Worker       *   No assignment.
656*0e209d39SAndroid Build Coastguard Worker       */
657*0e209d39SAndroid Build Coastguard Worker      AlphabeticIndex &operator =(const AlphabeticIndex & /*other*/) { return *this;}
658*0e209d39SAndroid Build Coastguard Worker 
659*0e209d39SAndroid Build Coastguard Worker     /**
660*0e209d39SAndroid Build Coastguard Worker      * No Equality operators.
661*0e209d39SAndroid Build Coastguard Worker      * @internal (private)
662*0e209d39SAndroid Build Coastguard Worker      */
663*0e209d39SAndroid Build Coastguard Worker      virtual bool operator==(const AlphabeticIndex& other) const;
664*0e209d39SAndroid Build Coastguard Worker 
665*0e209d39SAndroid Build Coastguard Worker     /**
666*0e209d39SAndroid Build Coastguard Worker      * Inequality operator.
667*0e209d39SAndroid Build Coastguard Worker      * @internal (private)
668*0e209d39SAndroid Build Coastguard Worker      */
669*0e209d39SAndroid Build Coastguard Worker      virtual bool operator!=(const AlphabeticIndex& other) const;
670*0e209d39SAndroid Build Coastguard Worker 
671*0e209d39SAndroid Build Coastguard Worker      // Common initialization, for use from all constructors.
672*0e209d39SAndroid Build Coastguard Worker      void init(const Locale *locale, UErrorCode &status);
673*0e209d39SAndroid Build Coastguard Worker 
674*0e209d39SAndroid Build Coastguard Worker     /**
675*0e209d39SAndroid Build Coastguard Worker      * This method is called to get the index exemplars. Normally these come from the locale directly,
676*0e209d39SAndroid Build Coastguard Worker      * but if they aren't available, we have to synthesize them.
677*0e209d39SAndroid Build Coastguard Worker      */
678*0e209d39SAndroid Build Coastguard Worker     void addIndexExemplars(const Locale &locale, UErrorCode &status);
679*0e209d39SAndroid Build Coastguard Worker     /**
680*0e209d39SAndroid Build Coastguard Worker      * Add Chinese index characters from the tailoring.
681*0e209d39SAndroid Build Coastguard Worker      */
682*0e209d39SAndroid Build Coastguard Worker     UBool addChineseIndexCharacters(UErrorCode &errorCode);
683*0e209d39SAndroid Build Coastguard Worker 
684*0e209d39SAndroid Build Coastguard Worker     UVector *firstStringsInScript(UErrorCode &status);
685*0e209d39SAndroid Build Coastguard Worker 
686*0e209d39SAndroid Build Coastguard Worker     static UnicodeString separated(const UnicodeString &item);
687*0e209d39SAndroid Build Coastguard Worker 
688*0e209d39SAndroid Build Coastguard Worker     /**
689*0e209d39SAndroid Build Coastguard Worker      * Determine the best labels to use.
690*0e209d39SAndroid Build Coastguard Worker      * This is based on the exemplars, but we also process to make sure that they are unique,
691*0e209d39SAndroid Build Coastguard Worker      * and sort differently, and that the overall list is small enough.
692*0e209d39SAndroid Build Coastguard Worker      */
693*0e209d39SAndroid Build Coastguard Worker     void initLabels(UVector &indexCharacters, UErrorCode &errorCode) const;
694*0e209d39SAndroid Build Coastguard Worker     BucketList *createBucketList(UErrorCode &errorCode) const;
695*0e209d39SAndroid Build Coastguard Worker     void initBuckets(UErrorCode &errorCode);
696*0e209d39SAndroid Build Coastguard Worker     void clearBuckets();
697*0e209d39SAndroid Build Coastguard Worker     void internalResetBucketIterator();
698*0e209d39SAndroid Build Coastguard Worker 
699*0e209d39SAndroid Build Coastguard Worker public:
700*0e209d39SAndroid Build Coastguard Worker 
701*0e209d39SAndroid Build Coastguard Worker     //  The Record is declared public only to allow access from
702*0e209d39SAndroid Build Coastguard Worker     //  implementation code written in plain C.
703*0e209d39SAndroid Build Coastguard Worker     //  It is not intended for public use.
704*0e209d39SAndroid Build Coastguard Worker 
705*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
706*0e209d39SAndroid Build Coastguard Worker     /**
707*0e209d39SAndroid Build Coastguard Worker      * A (name, data) pair, to be sorted by name into one of the index buckets.
708*0e209d39SAndroid Build Coastguard Worker      * The user data is not used by the index implementation.
709*0e209d39SAndroid Build Coastguard Worker      * \cond
710*0e209d39SAndroid Build Coastguard Worker      * @internal
711*0e209d39SAndroid Build Coastguard Worker      */
712*0e209d39SAndroid Build Coastguard Worker     struct Record: public UMemory {
713*0e209d39SAndroid Build Coastguard Worker         const UnicodeString  name_;
714*0e209d39SAndroid Build Coastguard Worker         const void           *data_;
715*0e209d39SAndroid Build Coastguard Worker         Record(const UnicodeString &name, const void *data);
716*0e209d39SAndroid Build Coastguard Worker         ~Record();
717*0e209d39SAndroid Build Coastguard Worker     };
718*0e209d39SAndroid Build Coastguard Worker     /** \endcond */
719*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_INTERNAL_API */
720*0e209d39SAndroid Build Coastguard Worker 
721*0e209d39SAndroid Build Coastguard Worker private:
722*0e209d39SAndroid Build Coastguard Worker 
723*0e209d39SAndroid Build Coastguard Worker     /**
724*0e209d39SAndroid Build Coastguard Worker      * Holds all user records before they are distributed into buckets.
725*0e209d39SAndroid Build Coastguard Worker      * Type of contents is (Record *)
726*0e209d39SAndroid Build Coastguard Worker      * @internal (private)
727*0e209d39SAndroid Build Coastguard Worker      */
728*0e209d39SAndroid Build Coastguard Worker     UVector  *inputList_;
729*0e209d39SAndroid Build Coastguard Worker 
730*0e209d39SAndroid Build Coastguard Worker     int32_t  labelsIterIndex_;        // Index of next item to return.
731*0e209d39SAndroid Build Coastguard Worker     int32_t  itemsIterIndex_;
732*0e209d39SAndroid Build Coastguard Worker     Bucket   *currentBucket_;         // While an iteration of the index in underway,
733*0e209d39SAndroid Build Coastguard Worker                                       //   point to the bucket for the current label.
734*0e209d39SAndroid Build Coastguard Worker                                       // nullptr when no iteration underway.
735*0e209d39SAndroid Build Coastguard Worker 
736*0e209d39SAndroid Build Coastguard Worker     int32_t    maxLabelCount_;        // Limit on # of labels permitted in the index.
737*0e209d39SAndroid Build Coastguard Worker 
738*0e209d39SAndroid Build Coastguard Worker     UnicodeSet *initialLabels_;       // Initial (unprocessed) set of Labels.  Union
739*0e209d39SAndroid Build Coastguard Worker                                       //   of those explicitly set by the user plus
740*0e209d39SAndroid Build Coastguard Worker                                       //   those from locales.  Raw values, before
741*0e209d39SAndroid Build Coastguard Worker                                       //   crunching into bucket labels.
742*0e209d39SAndroid Build Coastguard Worker 
743*0e209d39SAndroid Build Coastguard Worker     UVector *firstCharsInScripts_;    // The first character from each script,
744*0e209d39SAndroid Build Coastguard Worker                                       //   in collation order.
745*0e209d39SAndroid Build Coastguard Worker 
746*0e209d39SAndroid Build Coastguard Worker     RuleBasedCollator *collator_;
747*0e209d39SAndroid Build Coastguard Worker     RuleBasedCollator *collatorPrimaryOnly_;
748*0e209d39SAndroid Build Coastguard Worker 
749*0e209d39SAndroid Build Coastguard Worker     // Lazy evaluated: null means that we have not built yet.
750*0e209d39SAndroid Build Coastguard Worker     BucketList *buckets_;
751*0e209d39SAndroid Build Coastguard Worker 
752*0e209d39SAndroid Build Coastguard Worker     UnicodeString  inflowLabel_;
753*0e209d39SAndroid Build Coastguard Worker     UnicodeString  overflowLabel_;
754*0e209d39SAndroid Build Coastguard Worker     UnicodeString  underflowLabel_;
755*0e209d39SAndroid Build Coastguard Worker     UnicodeString  overflowComparisonString_;
756*0e209d39SAndroid Build Coastguard Worker 
757*0e209d39SAndroid Build Coastguard Worker     UnicodeString emptyString_;
758*0e209d39SAndroid Build Coastguard Worker };
759*0e209d39SAndroid Build Coastguard Worker 
760*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
761*0e209d39SAndroid Build Coastguard Worker 
762*0e209d39SAndroid Build Coastguard Worker #endif  // !UCONFIG_NO_COLLATION
763*0e209d39SAndroid Build Coastguard Worker 
764*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
765*0e209d39SAndroid Build Coastguard Worker 
766*0e209d39SAndroid Build Coastguard Worker #endif
767