2 ******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 ******************************************************************************
\r
8 package com.ibm.icu.util;
\r
11 * <p>Interface for enabling iteration over sets of <int, Object>, where
\r
12 * int is the sorted integer index in ascending order, and Object its
\r
13 * associated value.</p>
\r
14 * <p>The ValueIterator allows iterations over integer indexes in the range
\r
15 * of Integer.MIN_VALUE to Integer.MAX_VALUE inclusive. Implementations of
\r
16 * ValueIterator should specify their own maximum subrange within the above
\r
17 * range that is meaningful to its applications.</p>
\r
18 * <p>Most implementations will be created by factory methods, such as the
\r
19 * character name iterator in UCharacter.getNameIterator. See example below.
\r
21 * Example of use:<br>
\r
23 * ValueIterator iterator = UCharacter.getNameIterator();
\r
24 * ValueIterator.Element result = new ValueIterator.Element();
\r
25 * iterator.setRange(UCharacter.MIN_VALUE, UCharacter.MAX_VALUE);
\r
26 * while (iterator.next(result)) {
\r
27 * System.out.println("Codepoint \\u" +
\r
28 * Integer.toHexString(result.integer) +
\r
29 * " has the character name " + (String)result.value);
\r
35 public interface ValueIterator
\r
37 // public inner class ---------------------------------------------
\r
40 * <p>The return result container of each iteration. Stores the next
\r
41 * integer index and its associated value Object.</p>
\r
44 public static final class Element
\r
46 // public data members ----------------------------------------
\r
49 * Integer index of the current iteration
\r
54 * Gets the Object value associated with the integer index.
\r
57 public Object value;
\r
59 // public constructor ------------------------------------------
\r
62 * Empty default constructor to make javadoc happy
\r
70 // public methods -------------------------------------------------
\r
73 * <p>Returns the next result for this iteration and returns
\r
74 * true if we are not at the end of the iteration, false otherwise.</p>
\r
75 * <p>If this returns a false, the contents of elements will not
\r
77 * @param element for storing the result index and value
\r
78 * @return true if we are not at the end of the iteration, false otherwise.
\r
82 public boolean next(Element element);
\r
85 * <p>Resets the iterator to start iterating from the integer index
\r
86 * Integer.MIN_VALUE or X if a setRange(X, Y) has been called previously.
\r
90 public void reset();
\r
93 * <p>Restricts the range of integers to iterate and resets the iteration
\r
94 * to begin at the index argument start.</p>
\r
95 * <p>If setRange(start, end) is not performed before next(element) is
\r
96 * called, the iteration will start from the integer index
\r
97 * Integer.MIN_VALUE and end at Integer.MAX_VALUE.</p>
\r
99 * If this range is set outside the meaningful range specified by the
\r
100 * implementation, next(element) will always return false.
\r
102 * @param start first integer in the range to iterate
\r
103 * @param limit one more than the last integer in the range
\r
104 * @exception IllegalArgumentException thrown when attempting to set an
\r
105 * illegal range. E.g limit <= start
\r
108 public void setRange(int start, int limit);
\r