1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * %W% %E%
 *
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package sun.misc;

import java.util.Enumeration;
import java.util.NoSuchElementException;

/*
 * A useful utility class that will enumerate over an array of
 * enumerations.
 */
public class CompoundEnumeration<E> implements Enumeration<E> {
    private Enumeration[] enums;
    private int index = 0;

    public CompoundEnumeration(Enumeration[] enums) {
    this.enums = enums;
    }

    private boolean next() {
    while (index < enums.length) {
        if (enums[index] != null && enums[index].hasMoreElements()) {
        return true;
        }
        index++;
    }
    return false;
    }

    public boolean hasMoreElements() {
    return next();
    }

    public E nextElement() {
    if (!next()) {
        throw new NoSuchElementException();
    }
    return (E)enums[index].nextElement();
    }
}
			
			

Browsed Source: [clear]