]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/util/UResourceBundleIterator.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / util / UResourceBundleIterator.java
1 /*
2 ******************************************************************************
3 * Copyright (C) 2004-2009, International Business Machines Corporation and   *
4 * others. All Rights Reserved.                                               *
5 ******************************************************************************
6 */
7
8 package com.ibm.icu.util;
9
10 import java.util.NoSuchElementException;
11
12 /**
13  * <p>Class for enabling iteration over UResourceBundle objects.
14  * Example of use:<br>
15  * <pre>
16  * ICUResourceBundleIterator iterator = resB.getIterator();
17  * ICUResourceBundle temp;
18  * while (iterator.hasNext()) {
19  *    temp = iterartor.next();  
20  *    int type = temp.getType();
21  *    switch(type){
22  *      case UResourceBundle.STRING:
23  *          str = temp.getString();
24  *          break;
25  *      case UResourceBundle.INT:
26  *          integer = temp.getInt();
27  *          break;
28  *     .....
29  *    }
30  *   // do something interesting with data collected
31  * }
32  * </pre>
33  * @author ram
34  * @stable ICU 3.8
35  */
36 public class UResourceBundleIterator{
37     private UResourceBundle bundle;
38     private int index = 0;
39     private int size = 0;
40     /**
41      * Construct a resource bundle iterator for the
42      * given resource bundle
43      * 
44      * @param bndl The resource bundle to iterate over
45      * @stable ICU 3.8
46      */
47     public UResourceBundleIterator(UResourceBundle bndl){
48         bundle = bndl;   
49         size = bundle.getSize();
50     }
51
52     /**
53      * Returns the next element of this iterator if this iterator object has at least one more element to provide
54      * @return the UResourceBundle object
55      * @throws NoSuchElementException If there does not exist such an element.
56      * @stable ICU 3.8
57      */
58     public UResourceBundle next()throws NoSuchElementException{
59         if(index<size){
60             return bundle.get(index++);
61         }
62         throw new NoSuchElementException();
63     }
64     /**
65      * Returns the next String of this iterator if this iterator object has at least one more element to provide
66      * @return the UResourceBundle object
67      * @throws NoSuchElementException If there does not exist such an element.
68      * @throws UResourceTypeMismatchException If resource has a type mismatch.
69      * @stable ICU 3.8
70      */
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      * @stable ICU 3.8
81      */
82     public void reset(){
83         //reset the internal context   
84         index = 0;
85     }
86     
87     /**
88      * Checks whether the given resource has another element to iterate over.
89      * @return TRUE if there are more elements, FALSE if there is no more elements
90      * @stable ICU 3.8
91      */
92     public boolean hasNext(){
93         return index < size;   
94     }
95 }