package gve.calc.formula;

import java.util.Enumeration;

public class FallbackEnumeration implements Enumeration {
	private Enumeration first;	// set to null if we're done with it
	private Enumeration second;

	public FallbackEnumeration(Enumeration first,Enumeration second) {
		this.first = first;
		this.second = second;
	}

	public boolean hasMoreElements() {
		if (first != null) {
			if (first.hasMoreElements()) return true;
			first = null;	// switch over to second Enumeration
		}
		return second.hasMoreElements();
	}

	public Object nextElement() {
		if (first != null) {
			try {
				return first.nextElement();
			} catch (java.util.NoSuchElementException exc) {
				first = null;	// switch over to second Enumeration
			}
		}
		return second.nextElement();
	}
}