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

fr.lirmm.graphik.util.stream.StreamAdapter Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
package fr.lirmm.graphik.util.stream;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
import java.util.stream.Collector;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class StreamAdapter implements Stream {
	AutoCloseable toClose = null;
	Stream stream;

	public StreamAdapter(CloseableIterator iterator) {
		super();
		this.toClose = iterator;
        Spliterator spitr = Spliterators.spliteratorUnknownSize( 
                new IteratorAdapter(iterator), Spliterator.NONNULL); 
        stream = StreamSupport.stream(spitr, false); 
	}
	
	public StreamAdapter(Iterator iterator) {
		super();
		if (iterator instanceof AutoCloseable) {
			this.toClose = (AutoCloseable)iterator;
		}
        Spliterator spitr = Spliterators.spliteratorUnknownSize( 
                iterator, Spliterator.NONNULL); 
        stream = StreamSupport.stream(spitr, false); 
	}

	public boolean allMatch(Predicate arg0) {
		return stream.allMatch(arg0);
	}

	public boolean anyMatch(Predicate arg0) {
		return stream.anyMatch(arg0);
	}

	public void close() {
		if (toClose != null) {
			try {
				toClose.close();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		stream.close();
	}

	public  R collect(Collector arg0) {
		return stream.collect(arg0);
	}

	public  R collect(Supplier arg0, BiConsumer arg1, BiConsumer arg2) {
		return stream.collect(arg0, arg1, arg2);
	}

	public long count() {
		return stream.count();
	}

	public Stream distinct() {
		return stream.distinct();
	}

	public Stream filter(Predicate arg0) {
		return stream.filter(arg0);
	}

	public Optional findAny() {
		return stream.findAny();
	}

	public Optional findFirst() {
		return stream.findFirst();
	}

	public  Stream flatMap(Function> arg0) {
		return stream.flatMap(arg0);
	}

	public DoubleStream flatMapToDouble(Function arg0) {
		return stream.flatMapToDouble(arg0);
	}

	public IntStream flatMapToInt(Function arg0) {
		return stream.flatMapToInt(arg0);
	}

	public LongStream flatMapToLong(Function arg0) {
		return stream.flatMapToLong(arg0);
	}

	public void forEach(Consumer arg0) {
		stream.forEach(arg0);
	}

	public void forEachOrdered(Consumer arg0) {
		stream.forEachOrdered(arg0);
	}

	public boolean isParallel() {
		return stream.isParallel();
	}

	public Iterator iterator() {
		return stream.iterator();
	}

	public Stream limit(long arg0) {
		return stream.limit(arg0);
	}

	public  Stream map(Function arg0) {
		return stream.map(arg0);
	}

	public DoubleStream mapToDouble(ToDoubleFunction arg0) {
		return stream.mapToDouble(arg0);
	}

	public IntStream mapToInt(ToIntFunction arg0) {
		return stream.mapToInt(arg0);
	}

	public LongStream mapToLong(ToLongFunction arg0) {
		return stream.mapToLong(arg0);
	}

	public Optional max(Comparator arg0) {
		return stream.max(arg0);
	}

	public Optional min(Comparator arg0) {
		return stream.min(arg0);
	}

	public boolean noneMatch(Predicate arg0) {
		return stream.noneMatch(arg0);
	}

	public Stream onClose(Runnable arg0) {
		return stream.onClose(arg0);
	}

	public Stream parallel() {
		return stream.parallel();
	}

	public Stream peek(Consumer arg0) {
		return stream.peek(arg0);
	}

	public Optional reduce(BinaryOperator arg0) {
		return stream.reduce(arg0);
	}

	public T reduce(T arg0, BinaryOperator arg1) {
		return stream.reduce(arg0, arg1);
	}

	public  U reduce(U arg0, BiFunction arg1, BinaryOperator arg2) {
		return stream.reduce(arg0, arg1, arg2);
	}

	public Stream sequential() {
		return stream.sequential();
	}

	public Stream skip(long arg0) {
		return stream.skip(arg0);
	}

	public Stream sorted() {
		return stream.sorted();
	}

	public Stream sorted(Comparator arg0) {
		return stream.sorted(arg0);
	}

	public Spliterator spliterator() {
		return stream.spliterator();
	}

	public Object[] toArray() {
		return stream.toArray();
	}

	public  A[] toArray(IntFunction arg0) {
		return stream.toArray(arg0);
	}

	public Stream unordered() {
		return stream.unordered();
	}
}