2
* Copyright 1999-2004 The Apache Software Foundation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
package org.apache.commons.collections;
18
import java.util.Enumeration;
19
import java.util.List;
20
import java.util.NoSuchElementException;
23
* Enumeration wrapper for array.
26
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
27
* @deprecated This class has significant overlap with ArrayIterator,
28
* and Collections focuses mainly on Java2-style
29
* collections. If you need to enumerate an array,
30
* create an {@link ArrayIterator} and wrap it with an
31
* {@link IteratorEnumeration} instead.
33
public final class ArrayEnumeration
34
implements Enumeration
36
protected Object[] m_elements;
37
protected int m_index;
39
public ArrayEnumeration( final List elements )
41
m_elements = elements.toArray();
44
public ArrayEnumeration( final Object[] elements )
46
if(elements == null) {
47
m_elements = new Object[0];
49
m_elements = elements;
53
public boolean hasMoreElements()
55
return ( m_index < m_elements.length );
58
public Object nextElement()
60
if( !hasMoreElements() )
62
throw new NoSuchElementException("No more elements exist");
65
return m_elements[ m_index++ ];