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: package org.apache.pluto.util;
18:
19: import java.util.Collection;
20: import java.util.Enumeration;
21: import java.util.Iterator;
22: import java.util.Map;
23: import java.util.NoSuchElementException;
24:
25: /**
26: * Uitlity class to wraps an <code>Enumeration</code> around a Collection, i.e.
27: * <code>Iterator</code> classes.
28: */
29:
30: public final class Enumerator implements Enumeration {
31:
32: // Iterator over which the Enumeration takes place
33: private Iterator iterator = null;
34:
35: /**
36: * Returns an Enumeration over the specified Collection.
37: * @param collection Collection with values that should be enumerated
38: */
39: public Enumerator(Collection collection) {
40: this (collection.iterator());
41: }
42:
43: /**
44: * Returns an Enumeration over the values of the specified Iterator.
45: * @param iterator Iterator to be wrapped
46: */
47: public Enumerator(Iterator iterator) {
48: super ();
49: this .iterator = iterator;
50: }
51:
52: /**
53: * Returns an Enumeration over the values of the specified Map.
54: * @param map Map with values that should be enumerated
55: */
56: public Enumerator(Map map) {
57: this (map.values().iterator());
58: }
59:
60: /**
61: * Tests if this enumeration contains more elements.
62: * @return <code>true</code> if this enumeration contains at least one more
63: * element to provide, <code>false</code> otherwise.
64: */
65: public boolean hasMoreElements() {
66: return (iterator.hasNext());
67: }
68:
69: /**
70: * Returns the next element of this enumeration.
71: * @return the next element of this enumeration
72: * @throws NoSuchElementException if no more elements exist
73: */
74: public Object nextElement() throws NoSuchElementException {
75: return (iterator.next());
76: }
77:
78: }
|