HHH-16508 Remove StreamDecorators
This commit is contained in:
parent
911887328c
commit
a8b1dfd7be
|
@ -1,316 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.query.spi;
|
||||
|
||||
import java.util.DoubleSummaryStatistics;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.DoubleBinaryOperator;
|
||||
import java.util.function.DoubleConsumer;
|
||||
import java.util.function.DoubleFunction;
|
||||
import java.util.function.DoublePredicate;
|
||||
import java.util.function.DoubleToIntFunction;
|
||||
import java.util.function.DoubleToLongFunction;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
import java.util.function.ObjDoubleConsumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
|
||||
/**
|
||||
* The {@link DoubleStreamDecorator} wraps a Java {@link DoubleStream} and registers a {@code closeHandler}
|
||||
* which is passed further to any resulting {@link Stream}.
|
||||
* <p>
|
||||
* The goal of the {@link DoubleStreamDecorator} is to close the underlying {@link DoubleStream} upon
|
||||
* calling a terminal operation.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
* @since 5.4
|
||||
*/
|
||||
@Incubating
|
||||
public class DoubleStreamDecorator implements DoubleStream {
|
||||
|
||||
private final DoubleStream delegate;
|
||||
private final Runnable closeHandler;
|
||||
|
||||
public DoubleStreamDecorator(
|
||||
DoubleStream delegate,
|
||||
Runnable closeHandler) {
|
||||
this.closeHandler = closeHandler;
|
||||
this.delegate = delegate.onClose( closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream filter(DoublePredicate predicate) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.filter( predicate ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream map(DoubleUnaryOperator mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.map( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper) {
|
||||
return new StreamDecorator<>(
|
||||
delegate.mapToObj( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream mapToInt(DoubleToIntFunction mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.mapToInt( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream mapToLong(DoubleToLongFunction mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.mapToLong( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.flatMap( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream distinct() {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.distinct(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream sorted() {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.sorted(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream peek(DoubleConsumer action) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.peek( action ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream limit(long maxSize) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.limit( maxSize ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream skip(long n) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.skip( n ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(DoubleConsumer action) {
|
||||
delegate.forEach( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachOrdered(DoubleConsumer action) {
|
||||
delegate.forEachOrdered( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] toArray() {
|
||||
double[] result = delegate.toArray();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double reduce(double identity, DoubleBinaryOperator op) {
|
||||
double result = delegate.reduce( identity, op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble reduce(DoubleBinaryOperator op) {
|
||||
OptionalDouble result = delegate.reduce( op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R collect(
|
||||
Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R, R> combiner) {
|
||||
R result = delegate.collect( supplier, accumulator, combiner );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double sum() {
|
||||
double result = delegate.sum();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble min() {
|
||||
OptionalDouble result = delegate.min();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble max() {
|
||||
OptionalDouble result = delegate.max();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
long result = delegate.count();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble average() {
|
||||
OptionalDouble result = delegate.average();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleSummaryStatistics summaryStatistics() {
|
||||
DoubleSummaryStatistics result = delegate.summaryStatistics();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyMatch(DoublePredicate predicate) {
|
||||
boolean result = delegate.anyMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allMatch(DoublePredicate predicate) {
|
||||
boolean result = delegate.allMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noneMatch(DoublePredicate predicate) {
|
||||
boolean result = delegate.noneMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble findFirst() {
|
||||
OptionalDouble result = delegate.findFirst();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble findAny() {
|
||||
OptionalDouble result = delegate.findAny();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Double> boxed() {
|
||||
return new StreamDecorator<>(
|
||||
delegate.boxed(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream sequential() {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.sequential(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream parallel() {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.parallel(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream unordered() {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.unordered(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream onClose(Runnable closeHandler) {
|
||||
this.delegate.onClose( closeHandler );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimitiveIterator.OfDouble iterator() {
|
||||
return delegate.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator.OfDouble spliterator() {
|
||||
return delegate.spliterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return delegate.isParallel();
|
||||
}
|
||||
}
|
|
@ -1,331 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.query.spi;
|
||||
|
||||
import java.util.IntSummaryStatistics;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntBinaryOperator;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.IntPredicate;
|
||||
import java.util.function.IntToDoubleFunction;
|
||||
import java.util.function.IntToLongFunction;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
import java.util.function.ObjIntConsumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
|
||||
/**
|
||||
* The {@link IntStreamDecorator} wraps a Java {@link IntStream} and registers a {@code closeHandler}
|
||||
* which is passed further to any resulting {@link Stream}.
|
||||
* <p>
|
||||
* The goal of the {@link IntStreamDecorator} is to close the underlying {@link IntStream} upon
|
||||
* calling a terminal operation.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
* @since 5.4
|
||||
*/
|
||||
@Incubating
|
||||
public class IntStreamDecorator implements IntStream {
|
||||
|
||||
private final IntStream delegate;
|
||||
private final Runnable closeHandler;
|
||||
|
||||
public IntStreamDecorator(
|
||||
IntStream delegate,
|
||||
Runnable closeHandler) {
|
||||
this.closeHandler = closeHandler;
|
||||
this.delegate = delegate.onClose( closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream filter(IntPredicate predicate) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.filter( predicate ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream map(IntUnaryOperator mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.map( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Stream<U> mapToObj(IntFunction<? extends U> mapper) {
|
||||
return new StreamDecorator<>(
|
||||
delegate.mapToObj( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream mapToLong(IntToLongFunction mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.mapToLong( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream mapToDouble(IntToDoubleFunction mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.mapToDouble( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream flatMap(IntFunction<? extends IntStream> mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.flatMap( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream distinct() {
|
||||
return new IntStreamDecorator(
|
||||
delegate.distinct(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream sorted() {
|
||||
return new IntStreamDecorator(
|
||||
delegate.sorted(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream peek(IntConsumer action) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.peek( action ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream limit(long maxSize) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.limit( maxSize ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream skip(long n) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.skip( n ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(IntConsumer action) {
|
||||
delegate.forEach( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachOrdered(IntConsumer action) {
|
||||
delegate.forEachOrdered( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] toArray() {
|
||||
int[] result = delegate.toArray();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int reduce(int identity, IntBinaryOperator op) {
|
||||
int result = delegate.reduce( identity, op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt reduce(IntBinaryOperator op) {
|
||||
OptionalInt result = delegate.reduce( op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R collect(
|
||||
Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R, R> combiner) {
|
||||
R result = delegate.collect( supplier, accumulator, combiner );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sum() {
|
||||
int result = delegate.sum();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt min() {
|
||||
OptionalInt result = delegate.min();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt max() {
|
||||
OptionalInt result = delegate.max();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
long result = delegate.count();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble average() {
|
||||
OptionalDouble result = delegate.average();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntSummaryStatistics summaryStatistics() {
|
||||
IntSummaryStatistics result = delegate.summaryStatistics();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyMatch(IntPredicate predicate) {
|
||||
boolean result = delegate.anyMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allMatch(IntPredicate predicate) {
|
||||
boolean result = delegate.allMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noneMatch(IntPredicate predicate) {
|
||||
boolean result = delegate.noneMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt findFirst() {
|
||||
OptionalInt result = delegate.findFirst();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt findAny() {
|
||||
OptionalInt result = delegate.findAny();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream asLongStream() {
|
||||
LongStream result = delegate.asLongStream();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream asDoubleStream() {
|
||||
DoubleStream result = delegate.asDoubleStream();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Integer> boxed() {
|
||||
return new StreamDecorator<>(
|
||||
delegate.boxed(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream sequential() {
|
||||
return new IntStreamDecorator(
|
||||
delegate.sequential(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream parallel() {
|
||||
return new IntStreamDecorator(
|
||||
delegate.parallel(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream unordered() {
|
||||
return new IntStreamDecorator(
|
||||
delegate.unordered(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream onClose(Runnable closeHandler) {
|
||||
this.delegate.onClose( closeHandler );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimitiveIterator.OfInt iterator() {
|
||||
return delegate.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator.OfInt spliterator() {
|
||||
return delegate.spliterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return delegate.isParallel();
|
||||
}
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.query.spi;
|
||||
|
||||
import java.util.LongSummaryStatistics;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.PrimitiveIterator;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.LongBinaryOperator;
|
||||
import java.util.function.LongConsumer;
|
||||
import java.util.function.LongFunction;
|
||||
import java.util.function.LongPredicate;
|
||||
import java.util.function.LongToDoubleFunction;
|
||||
import java.util.function.LongToIntFunction;
|
||||
import java.util.function.LongUnaryOperator;
|
||||
import java.util.function.ObjLongConsumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
|
||||
/**
|
||||
* The {@link LongStreamDecorator} wraps a Java {@link LongStream} and registers a {@code closeHandler}
|
||||
* which is passed further to any resulting {@link Stream}.
|
||||
*
|
||||
* The goal of the {@link LongStreamDecorator} is to close the underlying {@link LongStream} upon
|
||||
* calling a terminal operation.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
* @since 5.4
|
||||
*/
|
||||
@Incubating
|
||||
public class LongStreamDecorator implements LongStream {
|
||||
|
||||
private final LongStream delegate;
|
||||
private final Runnable closeHandler;
|
||||
|
||||
public LongStreamDecorator(
|
||||
LongStream delegate,
|
||||
Runnable closeHandler) {
|
||||
this.closeHandler = closeHandler;
|
||||
this.delegate = delegate.onClose( closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream filter(LongPredicate predicate) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.filter( predicate ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream map(LongUnaryOperator mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.map( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Stream<U> mapToObj(LongFunction<? extends U> mapper) {
|
||||
return new StreamDecorator<>(
|
||||
delegate.mapToObj( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream mapToInt(LongToIntFunction mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.mapToInt( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream mapToDouble(LongToDoubleFunction mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.mapToDouble( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream flatMap(LongFunction<? extends LongStream> mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.flatMap( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream distinct() {
|
||||
return new LongStreamDecorator(
|
||||
delegate.distinct(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream sorted() {
|
||||
return new LongStreamDecorator(
|
||||
delegate.sorted(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream peek(LongConsumer action) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.peek( action ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream limit(long maxSize) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.limit( maxSize ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream skip(long n) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.skip( n ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(LongConsumer action) {
|
||||
delegate.forEach( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachOrdered(LongConsumer action) {
|
||||
delegate.forEachOrdered( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] toArray() {
|
||||
long[] result = delegate.toArray();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long reduce(long identity, LongBinaryOperator op) {
|
||||
long result = delegate.reduce( identity, op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong reduce(LongBinaryOperator op) {
|
||||
OptionalLong result = delegate.reduce( op );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R collect(
|
||||
Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R, R> combiner) {
|
||||
R result = delegate.collect( supplier, accumulator, combiner );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sum() {
|
||||
long result = delegate.sum();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong min() {
|
||||
OptionalLong result = delegate.min();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong max() {
|
||||
OptionalLong result = delegate.max();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
long result = delegate.count();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalDouble average() {
|
||||
OptionalDouble result = delegate.average();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongSummaryStatistics summaryStatistics() {
|
||||
LongSummaryStatistics result = delegate.summaryStatistics();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyMatch(LongPredicate predicate) {
|
||||
boolean result = delegate.anyMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allMatch(LongPredicate predicate) {
|
||||
boolean result = delegate.allMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noneMatch(LongPredicate predicate) {
|
||||
boolean result = delegate.noneMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong findFirst() {
|
||||
OptionalLong result = delegate.findFirst();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalLong findAny() {
|
||||
OptionalLong result = delegate.findAny();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream asDoubleStream() {
|
||||
DoubleStream result = delegate.asDoubleStream();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Long> boxed() {
|
||||
return new StreamDecorator<>(
|
||||
delegate.boxed(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream sequential() {
|
||||
return new LongStreamDecorator(
|
||||
delegate.sequential(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream parallel() {
|
||||
return new LongStreamDecorator(
|
||||
delegate.parallel(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream unordered() {
|
||||
return new LongStreamDecorator(
|
||||
delegate.unordered(),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream onClose(Runnable closeHandler) {
|
||||
this.delegate.onClose( closeHandler );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimitiveIterator.OfLong iterator() {
|
||||
return delegate.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator.OfLong spliterator() {
|
||||
return delegate.spliterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return delegate.isParallel();
|
||||
}
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.query.spi;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.Spliterator;
|
||||
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 org.hibernate.HibernateException;
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
||||
/**
|
||||
* The {@link StreamDecorator} wraps a Java {@link Stream} and registers a {@code closeHandler}
|
||||
* which is passed further to any resulting {@link Stream}.
|
||||
*
|
||||
* The goal of the {@link StreamDecorator} is to close the underlying {@link Stream} upon
|
||||
* calling a terminal operation.
|
||||
*
|
||||
* @author Vlad Mihalcea
|
||||
* @since 5.4
|
||||
*/
|
||||
@Incubating
|
||||
public class StreamDecorator<R> implements Stream<R> {
|
||||
|
||||
private final Stream<R> delegate;
|
||||
private final Runnable closeHandler;
|
||||
|
||||
public StreamDecorator(
|
||||
Stream<R> delegate,
|
||||
Runnable closeHandler) {
|
||||
this.closeHandler = closeHandler;
|
||||
this.delegate = delegate.onClose( closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> filter(Predicate<? super R> predicate) {
|
||||
return new StreamDecorator<R>( delegate.filter( predicate ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R1> Stream<R1> map(Function<? super R, ? extends R1> mapper) {
|
||||
return new StreamDecorator<>( delegate.map( mapper ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream mapToInt(ToIntFunction<? super R> mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.mapToInt( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream mapToLong(ToLongFunction<? super R> mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.mapToLong( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream mapToDouble(ToDoubleFunction<? super R> mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.mapToDouble( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R1> Stream<R1> flatMap(Function<? super R, ? extends Stream<? extends R1>> mapper) {
|
||||
return new StreamDecorator<>( delegate.flatMap( mapper ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntStream flatMapToInt(Function<? super R, ? extends IntStream> mapper) {
|
||||
return new IntStreamDecorator(
|
||||
delegate.flatMapToInt( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LongStream flatMapToLong(Function<? super R, ? extends LongStream> mapper) {
|
||||
return new LongStreamDecorator(
|
||||
delegate.flatMapToLong( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DoubleStream flatMapToDouble(Function<? super R, ? extends DoubleStream> mapper) {
|
||||
return new DoubleStreamDecorator(
|
||||
delegate.flatMapToDouble( mapper ),
|
||||
closeHandler
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> distinct() {
|
||||
return new StreamDecorator<>( delegate.distinct(), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> sorted() {
|
||||
return new StreamDecorator<>( delegate.sorted(), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> sorted(Comparator<? super R> comparator) {
|
||||
return new StreamDecorator<>( delegate.sorted( comparator ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> peek(Consumer<? super R> action) {
|
||||
return new StreamDecorator<>( delegate.peek( action ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> limit(long maxSize) {
|
||||
return new StreamDecorator<>( delegate.limit( maxSize ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> skip(long n) {
|
||||
return new StreamDecorator<>( delegate.skip( n ), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super R> action) {
|
||||
delegate.forEach( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachOrdered(Consumer<? super R> action) {
|
||||
delegate.forEachOrdered( action );
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] result = delegate.toArray();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A> A[] toArray(IntFunction<A[]> generator) {
|
||||
A[] result = delegate.toArray( generator );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R reduce(R identity, BinaryOperator<R> accumulator) {
|
||||
R result = delegate.reduce( identity, accumulator );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> reduce(BinaryOperator<R> accumulator) {
|
||||
Optional<R> result = delegate.reduce( accumulator );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> U reduce(
|
||||
U identity, BiFunction<U, ? super R, U> accumulator, BinaryOperator<U> combiner) {
|
||||
U result = delegate.reduce( identity, accumulator, combiner );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R1> R1 collect(
|
||||
Supplier<R1> supplier, BiConsumer<R1, ? super R> accumulator, BiConsumer<R1, R1> combiner) {
|
||||
R1 result = delegate.collect( supplier, accumulator, combiner );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R1, A> R1 collect(Collector<? super R, A, R1> collector) {
|
||||
R1 result = delegate.collect( collector );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> min(Comparator<? super R> comparator) {
|
||||
Optional<R> result = delegate.min( comparator );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> max(Comparator<? super R> comparator) {
|
||||
Optional<R> result = delegate.max( comparator );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
long result = delegate.count();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyMatch(Predicate<? super R> predicate) {
|
||||
boolean result = delegate.anyMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allMatch(Predicate<? super R> predicate) {
|
||||
boolean result = delegate.allMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean noneMatch(Predicate<? super R> predicate) {
|
||||
boolean result = delegate.noneMatch( predicate );
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> findFirst() {
|
||||
Optional<R> result = delegate.findFirst();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<R> findAny() {
|
||||
Optional<R> result = delegate.findAny();
|
||||
close();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<R> iterator() {
|
||||
return delegate.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<R> spliterator() {
|
||||
return delegate.spliterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParallel() {
|
||||
return delegate.isParallel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> sequential() {
|
||||
return new StreamDecorator<>( delegate.sequential(), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> parallel() {
|
||||
return new StreamDecorator<>( delegate.parallel(), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> unordered() {
|
||||
return new StreamDecorator<>( delegate.unordered(), closeHandler );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<R> onClose(Runnable closeHandler) {
|
||||
this.delegate.onClose( closeHandler );
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
//Methods added to JDK 9
|
||||
|
||||
public Stream<R> takeWhile(Predicate<? super R> predicate) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<R> result = (Stream<R>)
|
||||
ReflectHelper.getMethod( Stream.class, "takeWhile", Predicate.class )
|
||||
.invoke( delegate, predicate );
|
||||
return new StreamDecorator<>( result, closeHandler );
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new HibernateException( e );
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<R> dropWhile(Predicate<? super R> predicate) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<R> result = (Stream<R>)
|
||||
ReflectHelper.getMethod( Stream.class, "dropWhile", Predicate.class )
|
||||
.invoke( delegate, predicate );
|
||||
return new StreamDecorator<>( result, closeHandler );
|
||||
}
|
||||
catch (IllegalAccessException | InvocationTargetException e) {
|
||||
throw new HibernateException( e );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue