2 ******************************************************************************
3 * Copyright (C) 2004-2009, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 ******************************************************************************
8 package com.ibm.icu.util;
10 import java.util.NoSuchElementException;
13 * <p>Class for enabling iteration over UResourceBundle objects.
16 * ICUResourceBundleIterator iterator = resB.getIterator();
17 * ICUResourceBundle temp;
18 * while (iterator.hasNext()) {
19 * temp = iterartor.next();
20 * int type = temp.getType();
22 * case UResourceBundle.STRING:
23 * str = temp.getString();
25 * case UResourceBundle.INT:
26 * integer = temp.getInt();
30 * // do something interesting with data collected
36 public class UResourceBundleIterator{
37 private UResourceBundle bundle;
38 private int index = 0;
41 * Construct a resource bundle iterator for the
42 * given resource bundle
44 * @param bndl The resource bundle to iterate over
47 public UResourceBundleIterator(UResourceBundle bndl){
49 size = bundle.getSize();
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.
58 public UResourceBundle next()throws NoSuchElementException{
60 return bundle.get(index++);
62 throw new NoSuchElementException();
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.
71 public String nextString()throws NoSuchElementException, UResourceTypeMismatchException{
73 return bundle.getString(index++);
75 throw new NoSuchElementException();
79 * Resets the internal context of a resource so that iteration starts from the first element.
83 //reset the internal context
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
92 public boolean hasNext(){