View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.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 org.kuali.rice.kew.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 Kuali Rice Team (rice.collab@kuali.org)
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, Enumeration<T> enumeration2) {
51  		while (enumeration1.hasMoreElements()) {
52  			internalList.add(enumeration1.nextElement());
53  		}
54  		while (enumeration2.hasMoreElements()) {
55  			internalList.add(enumeration2.nextElement());
56  		}
57  		iterator = internalList.iterator();
58  	}
59  	
60  	public boolean hasMoreElements() {
61  		return iterator.hasNext();
62  	}
63  
64  	public T nextElement() {
65  		return iterator.next();
66  	}
67  
68  }