01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.util.iterator;
20:
21: import java.util.Iterator;
22: import java.util.Map;
23: import java.util.NoSuchElementException;
24:
25: import org.apache.beehive.netui.util.Bundle;
26:
27: /**
28: * This class implements the {@link Iterator} interface for accessing the set of
29: * values stored in a {@link Map}.
30: */
31: public class MapIterator implements Iterator {
32:
33: /**
34: * An iterator for the map's values.
35: */
36: private Iterator _mapIterator = null;
37:
38: /**
39: * Create the {@link Iterator} for the given {@link Map}
40: * @param map
41: */
42: public MapIterator(Map map) {
43: if (map == null)
44: return;
45:
46: _mapIterator = map.values().iterator();
47: }
48:
49: /**
50: * Advance to the next value in the {@link Map}.
51: *
52: * @return <code>true</code> if there is a next item; <code>false</code> otherwise
53: */
54: public boolean hasNext() {
55: if (_mapIterator == null)
56: return false;
57: else
58: return _mapIterator.hasNext();
59: }
60:
61: /**
62: * Advance to the next item in the {@link Map}
63: *
64: * @return the next item
65: * @throws NoSuchElementException if the map has no more elements
66: */
67: public Object next() {
68: if (_mapIterator == null)
69: throw new NoSuchElementException(
70: Bundle
71: .getErrorString("IteratorFactory_Iterator_noSuchElement"));
72: else
73: return _mapIterator.next();
74: }
75:
76: /**
77: * Remove the current item in the iterator.
78: */
79: public void remove() {
80: if (_mapIterator == null)
81: throw new UnsupportedOperationException(
82: Bundle
83: .getErrorString(
84: "IteratorFactory_Iterator_removeUnsupported",
85: new Object[] { this.getClass()
86: .getName() }));
87: else
88: _mapIterator.remove();
89: }
90: }
|