2 ******************************************************************************
\r
3 * Copyright (C) 2004-2009, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 ******************************************************************************
\r
8 package com.ibm.icu.util;
\r
10 import java.util.NoSuchElementException;
\r
13 * <p>Class for enabling iteration over UResourceBundle objects.
\r
14 * Example of use:<br>
\r
16 * ICUResourceBundleIterator iterator = resB.getIterator();
\r
17 * ICUResourceBundle temp;
\r
18 * while (iterator.hasNext()) {
\r
19 * temp = iterartor.next();
\r
20 * int type = temp.getType();
\r
22 * case UResourceBundle.STRING:
\r
23 * str = temp.getString();
\r
25 * case UResourceBundle.INT:
\r
26 * integer = temp.getInt();
\r
30 * // do something interesting with data collected
\r
36 public class UResourceBundleIterator{
\r
37 private UResourceBundle bundle;
\r
38 private int index = 0;
\r
39 private int size = 0;
\r
41 * Construct a resource bundle iterator for the
\r
42 * given resource bundle
\r
44 * @param bndl The resource bundle to iterate over
\r
47 public UResourceBundleIterator(UResourceBundle bndl){
\r
49 size = bundle.getSize();
\r
53 * Returns the next element of this iterator if this iterator object has at least one more element to provide
\r
54 * @return the UResourceBundle object
\r
55 * @throws NoSuchElementException If there does not exist such an element.
\r
58 public UResourceBundle next()throws NoSuchElementException{
\r
60 return bundle.get(index++);
\r
62 throw new NoSuchElementException();
\r
65 * Returns the next String of this iterator if this iterator object has at least one more element to provide
\r
66 * @return the UResourceBundle object
\r
67 * @throws NoSuchElementException If there does not exist such an element.
\r
68 * @throws UResourceTypeMismatchException If resource has a type mismatch.
\r
71 public String nextString()throws NoSuchElementException, UResourceTypeMismatchException{
\r
73 return bundle.getString(index++);
\r
75 throw new NoSuchElementException();
\r
79 * Resets the internal context of a resource so that iteration starts from the first element.
\r
82 public void reset(){
\r
83 //reset the internal context
\r
88 * Checks whether the given resource has another element to iterate over.
\r
89 * @return TRUE if there are more elements, FALSE if there is no more elements
\r
92 public boolean hasNext(){
\r
93 return index < size;
\r