~ubuntu-branches/ubuntu/oneiric/libcommons-collections-java/oneiric

« back to all changes in this revision

Viewing changes to src/java/org/apache/commons/collections/ArrayEnumeration.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2004-08-07 00:02:50 UTC
  • Revision ID: james.westby@ubuntu.com-20040807000250-hcnqvrdpxg95nmzr
Tags: upstream-2.1.1
ImportĀ upstreamĀ versionĀ 2.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 1999-2004 The Apache Software Foundation
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
package org.apache.commons.collections;
 
17
 
 
18
import java.util.Enumeration;
 
19
import java.util.List;
 
20
import java.util.NoSuchElementException;
 
21
 
 
22
/**
 
23
 * Enumeration wrapper for array.
 
24
 * 
 
25
 * @since 1.0
 
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.
 
32
 */
 
33
public final class ArrayEnumeration
 
34
    implements Enumeration
 
35
{
 
36
    protected Object[]       m_elements;
 
37
    protected int            m_index;
 
38
 
 
39
    public ArrayEnumeration( final List elements )
 
40
    {
 
41
        m_elements = elements.toArray();
 
42
    }
 
43
 
 
44
    public ArrayEnumeration( final Object[] elements )
 
45
    {
 
46
        if(elements == null) {
 
47
            m_elements = new Object[0];
 
48
        } else {
 
49
            m_elements = elements;
 
50
        }
 
51
    }
 
52
 
 
53
    public boolean hasMoreElements()
 
54
    {
 
55
        return ( m_index < m_elements.length );
 
56
    }
 
57
 
 
58
    public Object nextElement()
 
59
    {
 
60
        if( !hasMoreElements() )
 
61
        {
 
62
            throw new NoSuchElementException("No more elements exist");
 
63
        }
 
64
 
 
65
        return m_elements[ m_index++ ];
 
66
    }
 
67
}
 
68