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

se.l4.silo.results.FetchResultSpliterator Maven / Gradle / Ivy

The newest version!
package se.l4.silo.results;

import java.util.Iterator;
import java.util.Spliterator;
import java.util.Spliterators.AbstractSpliterator;
import java.util.function.Consumer;

import se.l4.silo.FetchResult;

/**
 * {@link Spliterator} for any {@link FetchResult}.
 *
 * @author Andreas Holstenson
 *
 * @param 
 */
public class FetchResultSpliterator
	extends AbstractSpliterator
{
	private final Iterator it;

	public FetchResultSpliterator(FetchResult fr)
	{
		super(fr.getSize() < 0 ? Integer.MAX_VALUE : fr.getSize(), Spliterator.ORDERED | Spliterator.IMMUTABLE);
		it = fr.iterator();
	}

	@Override
	public boolean tryAdvance(Consumer action)
	{
		if(! it.hasNext()) return false;

		T next = it.next();
		action.accept(next);

		return true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy