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