All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.schlichtherle.truezip.util.JointEnumeration Maven / Gradle / Ivy

/*
 * Copyright (C) 2005-2015 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package de.schlichtherle.truezip.util;

import java.util.Enumeration;
import java.util.NoSuchElementException;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Concatenates two enumerations.
 *
 * @author  Christian Schlichtherle
 */
@NotThreadSafe
public final class JointEnumeration implements Enumeration {
    private Enumeration e1;
    private final Enumeration e2;

    public JointEnumeration(
            final Enumeration e1,
            final Enumeration e2) {
        this.e1 = e1;
        this.e2 = e2;
    }

    @Override
	public boolean hasMoreElements() {
        return e1.hasMoreElements()
           || (e1 != e2 && (e1 = e2).hasMoreElements());
    }

    @Override
	public E nextElement() {
        try {
            return e1.nextElement();
        } catch (NoSuchElementException ex) {
            if (e1 == e2)
                throw ex;
            return (e1 = e2).nextElement();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy