01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.util;
18:
19: import java.util.ArrayList;
20: import java.util.Enumeration;
21: import java.util.Iterator;
22: import java.util.List;
23:
24: /*
25: * A simple Enumeration implementation which is backed by a List and it's Iterator.
26: * Provides a few convienance constructors for creating the Enumeration.
27: *
28: * @author ewestfal
29: */
30: public class SimpleEnumeration<T> implements Enumeration<T> {
31:
32: private List<T> internalList = new ArrayList<T>();
33: private Iterator<T> iterator;
34:
35: public SimpleEnumeration(T object) {
36: if (object != null) {
37: internalList.add(object);
38: }
39: iterator = internalList.iterator();
40: }
41:
42: public SimpleEnumeration(Enumeration<T> enumeration, T object) {
43: while (enumeration.hasMoreElements()) {
44: internalList.add(enumeration.nextElement());
45: }
46: internalList.add(object);
47: iterator = internalList.iterator();
48: }
49:
50: public SimpleEnumeration(Enumeration<T> enumeration1,
51: Enumeration<T> enumeration2) {
52: while (enumeration1.hasMoreElements()) {
53: internalList.add(enumeration1.nextElement());
54: }
55: while (enumeration2.hasMoreElements()) {
56: internalList.add(enumeration2.nextElement());
57: }
58: iterator = internalList.iterator();
59: }
60:
61: public boolean hasMoreElements() {
62: return iterator.hasNext();
63: }
64:
65: public T nextElement() {
66: return iterator.next();
67: }
68:
69: }
|