• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2016 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 /*
5 ******************************************************************************
6 * Copyright (C) 2004-2009, International Business Machines Corporation and   *
7 * others. All Rights Reserved.                                               *
8 ******************************************************************************
9 */
10 
11 package ohos.global.icu.util;
12 
13 import java.util.NoSuchElementException;
14 
15 /**
16  * <p>Class for enabling iteration over UResourceBundle objects.
17  * Example of use:<br>
18  * <pre>
19  * ICUResourceBundleIterator iterator = resB.getIterator();
20  * ICUResourceBundle temp;
21  * while (iterator.hasNext()) {
22  *    temp = iterartor.next();
23  *    int type = temp.getType();
24  *    switch(type){
25  *      case UResourceBundle.STRING:
26  *          str = temp.getString();
27  *          break;
28  *      case UResourceBundle.INT:
29  *          integer = temp.getInt();
30  *          break;
31  *     .....
32  *    }
33  *   // do something interesting with data collected
34  * }
35  * </pre>
36  * @author ram
37  * @hide exposed on OHOS
38  */
39 public class UResourceBundleIterator{
40     private UResourceBundle bundle;
41     private int index = 0;
42     private int size = 0;
43     /**
44      * Construct a resource bundle iterator for the
45      * given resource bundle
46      *
47      * @param bndl The resource bundle to iterate over
48      */
UResourceBundleIterator(UResourceBundle bndl)49     public UResourceBundleIterator(UResourceBundle bndl){
50         bundle = bndl;
51         size = bundle.getSize();
52     }
53 
54     /**
55      * Returns the next element of this iterator if this iterator object has at least one more element to provide
56      * @return the UResourceBundle object
57      * @throws NoSuchElementException If there does not exist such an element.
58      */
next()59     public UResourceBundle next()throws NoSuchElementException{
60         if(index<size){
61             return bundle.get(index++);
62         }
63         throw new NoSuchElementException();
64     }
65     /**
66      * Returns the next String of this iterator if this iterator object has at least one more element to provide
67      * @return the UResourceBundle object
68      * @throws NoSuchElementException If there does not exist such an element.
69      * @throws UResourceTypeMismatchException If resource has a type mismatch.
70      */
nextString()71     public String nextString()throws NoSuchElementException, UResourceTypeMismatchException{
72         if(index<size){
73             return bundle.getString(index++);
74         }
75         throw new NoSuchElementException();
76     }
77 
78     /**
79      * Resets the internal context of a resource so that iteration starts from the first element.
80      */
reset()81     public void reset(){
82         //reset the internal context
83         index = 0;
84     }
85 
86     /**
87      * Checks whether the given resource has another element to iterate over.
88      * @return TRUE if there are more elements, FALSE if there is no more elements
89      */
hasNext()90     public boolean hasNext(){
91         return index < size;
92     }
93 }