CompositeEnumeration.java revision 2224:2a8815d86b93
1207753Smm/*
2207753Smm * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3207753Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4207753Smm *
5207753Smm * This code is free software; you can redistribute it and/or modify it
6207753Smm * under the terms of the GNU General Public License version 2 only, as
7207753Smm * published by the Free Software Foundation.  Oracle designates this
8207753Smm * particular file as subject to the "Classpath" exception as provided
9207753Smm * by Oracle in the LICENSE file that accompanied this code.
10207753Smm *
11207753Smm * This code is distributed in the hope that it will be useful, but WITHOUT
12207753Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13207753Smm * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14207753Smm * version 2 for more details (a copy is included in the LICENSE file that
15207753Smm * accompanied this code).
16207753Smm *
17207753Smm * You should have received a copy of the GNU General Public License version
18207753Smm * 2 along with this work; if not, write to the Free Software Foundation,
19207753Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20207753Smm *
21207753Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22207753Smm * or visit www.oracle.com if you need additional information or have any
23207753Smm * questions.
24207753Smm */
25207753Smm
26207753Smm
27207753Smm/*
28207753Smm * The Original Code is HAT. The Initial Developer of the
29207753Smm * Original Code is Bill Foote, with contributions from others
30207753Smm * at JavaSoft/Sun.
31207753Smm */
32207753Smm
33207753Smmpackage jdk.test.lib.hprof.util;
34207753Smm
35207753Smmimport java.util.Enumeration;
36207753Smmimport java.util.NoSuchElementException;
37207753Smmimport jdk.test.lib.hprof.model.JavaHeapObject;
38207753Smm
39207753Smmpublic class CompositeEnumeration implements Enumeration<JavaHeapObject> {
40207753Smm    Enumeration<JavaHeapObject> e1;
41207753Smm    Enumeration<JavaHeapObject> e2;
42360523Sdelphij
43207753Smm    public CompositeEnumeration(Enumeration<JavaHeapObject> e1, Enumeration<JavaHeapObject> e2) {
44207753Smm        this.e1 = e1;
45207753Smm        this.e2 = e2;
46207753Smm    }
47207753Smm
48207753Smm    public boolean hasMoreElements() {
49207753Smm        return e1.hasMoreElements() || e2.hasMoreElements();
50207753Smm    }
51207753Smm
52207753Smm    public JavaHeapObject nextElement() {
53207753Smm        if (e1.hasMoreElements()) {
54207753Smm            return e1.nextElement();
55207753Smm        }
56207753Smm
57207753Smm        if (e2.hasMoreElements()) {
58207753Smm            return e2.nextElement();
59207753Smm        }
60207753Smm
61207753Smm        throw new NoSuchElementException();
62207753Smm    }
63207753Smm}
64207753Smm