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

com.softicar.platform.common.container.iterable.concat.ConcatIterator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.iterable.concat;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * An {@link Iterator} to concatenates multiple iterables.
 *
 * @author Oliver Richers
 * @see ConcatIterable
 */
public class ConcatIterator implements Iterator {

	private final Iterator> iterablesIterator;
	private Iterator currentIterator;

	public ConcatIterator(Iterable> iterables) {

		this.iterablesIterator = iterables.iterator();
		this.currentIterator = null;
	}

	@Override
	public boolean hasNext() {

		if (currentIterator != null && currentIterator.hasNext()) {
			return true;
		}

		if (iterablesIterator.hasNext()) {
			this.currentIterator = iterablesIterator.next().iterator();
			return hasNext();
		}

		return false;
	}

	@Override
	public T next() {

		if (hasNext()) {
			return currentIterator.next();
		} else {
			throw new NoSuchElementException();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy