/* * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * bstefanescu */ package org.eclipse.ecr.web.jaxrs.servlet; import java.util.Enumeration; import java.util.NoSuchElementException; /** * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> * */ public class CompoundEnumeration<E> implements Enumeration<E> { private final Enumeration<E>[] enums; private int index = 0; @SuppressWarnings("unchecked") public CompoundEnumeration(Enumeration<?>[] enums) { this.enums = (Enumeration<E>[])enums; } private boolean next() { while (index < enums.length) { if (enums[index] != null && enums[index].hasMoreElements()) { return true; } index++; } return false; } @Override public boolean hasMoreElements() { return next(); } @Override public E nextElement() { if (!next()) { throw new NoSuchElementException(); } return enums[index].nextElement(); } }