CompositeEnumeration.java revision 2224:2a8815d86b93
1292932Sdim/* 2292932Sdim * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3292932Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4292932Sdim * 5292932Sdim * This code is free software; you can redistribute it and/or modify it 6292932Sdim * under the terms of the GNU General Public License version 2 only, as 7292932Sdim * published by the Free Software Foundation. Oracle designates this 8292932Sdim * particular file as subject to the "Classpath" exception as provided 9292932Sdim * by Oracle in the LICENSE file that accompanied this code. 10292932Sdim * 11292932Sdim * This code is distributed in the hope that it will be useful, but WITHOUT 12292932Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13292932Sdim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14309124Sdim * version 2 for more details (a copy is included in the LICENSE file that 15309124Sdim * accompanied this code). 16309124Sdim * 17309124Sdim * You should have received a copy of the GNU General Public License version 18309124Sdim * 2 along with this work; if not, write to the Free Software Foundation, 19292932Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20292932Sdim * 21292932Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22292932Sdim * or visit www.oracle.com if you need additional information or have any 23292932Sdim * questions. 24292932Sdim */ 25292932Sdim 26292932Sdim 27292932Sdim/* 28292932Sdim * The Original Code is HAT. The Initial Developer of the 29292932Sdim * Original Code is Bill Foote, with contributions from others 30292932Sdim * at JavaSoft/Sun. 31292932Sdim */ 32292932Sdim 33292932Sdimpackage jdk.test.lib.hprof.util; 34292932Sdim 35292932Sdimimport java.util.Enumeration; 36309124Sdimimport java.util.NoSuchElementException; 37309124Sdimimport jdk.test.lib.hprof.model.JavaHeapObject; 38309124Sdim 39309124Sdimpublic class CompositeEnumeration implements Enumeration<JavaHeapObject> { 40309124Sdim Enumeration<JavaHeapObject> e1; 41309124Sdim Enumeration<JavaHeapObject> e2; 42309124Sdim 43292932Sdim public CompositeEnumeration(Enumeration<JavaHeapObject> e1, Enumeration<JavaHeapObject> e2) { 44292932Sdim this.e1 = e1; 45292932Sdim this.e2 = e2; 46292932Sdim } 47292932Sdim 48292932Sdim public boolean hasMoreElements() { 49292932Sdim return e1.hasMoreElements() || e2.hasMoreElements(); 50292932Sdim } 51292932Sdim 52292932Sdim public JavaHeapObject nextElement() { 53292932Sdim if (e1.hasMoreElements()) { 54292932Sdim return e1.nextElement(); 55292932Sdim } 56292932Sdim 57292932Sdim if (e2.hasMoreElements()) { 58292932Sdim return e2.nextElement(); 59292932Sdim } 60292932Sdim 61292932Sdim throw new NoSuchElementException(); 62292932Sdim } 63292932Sdim} 64292932Sdim