KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > ICUResourceBundleIterator


1 /*
2 ******************************************************************************
3 * Copyright (C) 2004, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 ******************************************************************************
6 */

7
8 package com.ibm.icu.impl;
9
10 import java.util.NoSuchElementException JavaDoc;
11
12 import com.ibm.icu.util.UResourceTypeMismatchException;
13
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  * @draft ICU 3.0
38  */

39 public class ICUResourceBundleIterator{
40     private ICUResourceBundle 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      * @draft ICU 3.0
49      */

50     public ICUResourceBundleIterator(ICUResourceBundle bndl){
51         bundle = bndl;
52         size = bundle.getSize();
53     }
54
55     /**
56      * Returns the next element of this iterator if this iterator object has at least one more element to provide
57      * @return the UResourceBundle object
58      * @throws NoSuchElementException
59      * @draft ICU 3.0
60      */

61     public ICUResourceBundle next()throws NoSuchElementException JavaDoc{
62         if(index<size){
63             return bundle.get(index++);
64         }
65         throw new NoSuchElementException JavaDoc();
66     }
67     /**
68      * Returns the next String of this iterator if this iterator object has at least one more element to provide
69      * @return the UResourceBundle object
70      * @throws NoSuchElementException
71      * @throws UResourceTypeMismatchException
72      * @draft ICU 3.0
73      */

74     public String JavaDoc nextString()throws NoSuchElementException JavaDoc, UResourceTypeMismatchException{
75         if(index<size){
76             return bundle.getString(index++);
77         }
78         throw new NoSuchElementException JavaDoc();
79     }
80     
81     /**
82      * Resets the internal context of a resource so that iteration starts from the first element.
83      * @draft ICU 3.0
84      */

85     public void reset(){
86         //reset the internal context
87
index = 0;
88     }
89     
90     /**
91      * Checks whether the given resource has another element to iterate over.
92      * @return TRUE if there are more elements, FALSE if there is no more elements
93      * @draft ICU 3.0
94      */

95     public boolean hasNext(){
96         return index < size;
97     }
98 }
Popular Tags