From 8b006b49b4f79a1705b79ad9570a74324b2fc41b Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Mon, 24 Apr 2023 16:09:46 +0200 Subject: [PATCH] HHH-16508 Remove StreamDecorators --- .../query/spi/DoubleStreamDecorator.java | 316 ---------------- .../query/spi/IntStreamDecorator.java | 331 ----------------- .../query/spi/LongStreamDecorator.java | 324 ----------------- .../hibernate/query/spi/StreamDecorator.java | 338 ------------------ 4 files changed, 1309 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/query/spi/DoubleStreamDecorator.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/query/spi/IntStreamDecorator.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/query/spi/LongStreamDecorator.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/query/spi/StreamDecorator.java diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/DoubleStreamDecorator.java b/hibernate-core/src/main/java/org/hibernate/query/spi/DoubleStreamDecorator.java deleted file mode 100644 index 00a02d0699..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/DoubleStreamDecorator.java +++ /dev/null @@ -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 . - */ -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}. - *

- * 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 Stream mapToObj(DoubleFunction 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 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 collect( - Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer 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 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(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/IntStreamDecorator.java b/hibernate-core/src/main/java/org/hibernate/query/spi/IntStreamDecorator.java deleted file mode 100644 index 470128b2c9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/IntStreamDecorator.java +++ /dev/null @@ -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 . - */ -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}. - *

- * 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 Stream mapToObj(IntFunction 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 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 collect( - Supplier supplier, ObjIntConsumer accumulator, BiConsumer 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 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(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/LongStreamDecorator.java b/hibernate-core/src/main/java/org/hibernate/query/spi/LongStreamDecorator.java deleted file mode 100644 index befd5a16f2..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/LongStreamDecorator.java +++ /dev/null @@ -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 . - */ -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 Stream mapToObj(LongFunction 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 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 collect( - Supplier supplier, ObjLongConsumer accumulator, BiConsumer 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 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(); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/StreamDecorator.java b/hibernate-core/src/main/java/org/hibernate/query/spi/StreamDecorator.java deleted file mode 100644 index 9d862396b7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/StreamDecorator.java +++ /dev/null @@ -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 . - */ -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 implements Stream { - - private final Stream delegate; - private final Runnable closeHandler; - - public StreamDecorator( - Stream delegate, - Runnable closeHandler) { - this.closeHandler = closeHandler; - this.delegate = delegate.onClose( closeHandler ); - } - - @Override - public Stream filter(Predicate predicate) { - return new StreamDecorator( delegate.filter( predicate ), closeHandler ); - } - - @Override - public Stream map(Function mapper) { - return new StreamDecorator<>( delegate.map( mapper ), closeHandler ); - } - - @Override - public IntStream mapToInt(ToIntFunction mapper) { - return new IntStreamDecorator( - delegate.mapToInt( mapper ), - closeHandler - ); - } - - @Override - public LongStream mapToLong(ToLongFunction mapper) { - return new LongStreamDecorator( - delegate.mapToLong( mapper ), - closeHandler - ); - } - - @Override - public DoubleStream mapToDouble(ToDoubleFunction mapper) { - return new DoubleStreamDecorator( - delegate.mapToDouble( mapper ), - closeHandler - ); - } - - @Override - public Stream flatMap(Function> mapper) { - return new StreamDecorator<>( delegate.flatMap( mapper ), closeHandler ); - } - - @Override - public IntStream flatMapToInt(Function mapper) { - return new IntStreamDecorator( - delegate.flatMapToInt( mapper ), - closeHandler - ); - } - - @Override - public LongStream flatMapToLong(Function mapper) { - return new LongStreamDecorator( - delegate.flatMapToLong( mapper ), - closeHandler - ); - } - - @Override - public DoubleStream flatMapToDouble(Function mapper) { - return new DoubleStreamDecorator( - delegate.flatMapToDouble( mapper ), - closeHandler - ); - } - - @Override - public Stream distinct() { - return new StreamDecorator<>( delegate.distinct(), closeHandler ); - } - - @Override - public Stream sorted() { - return new StreamDecorator<>( delegate.sorted(), closeHandler ); - } - - @Override - public Stream sorted(Comparator comparator) { - return new StreamDecorator<>( delegate.sorted( comparator ), closeHandler ); - } - - @Override - public Stream peek(Consumer action) { - return new StreamDecorator<>( delegate.peek( action ), closeHandler ); - } - - @Override - public Stream limit(long maxSize) { - return new StreamDecorator<>( delegate.limit( maxSize ), closeHandler ); - } - - @Override - public Stream skip(long n) { - return new StreamDecorator<>( delegate.skip( n ), closeHandler ); - } - - @Override - public void forEach(Consumer action) { - delegate.forEach( action ); - close(); - } - - @Override - public void forEachOrdered(Consumer action) { - delegate.forEachOrdered( action ); - close(); - } - - @Override - public Object[] toArray() { - Object[] result = delegate.toArray(); - close(); - return result; - } - - @Override - public A[] toArray(IntFunction generator) { - A[] result = delegate.toArray( generator ); - close(); - return result; - } - - @Override - public R reduce(R identity, BinaryOperator accumulator) { - R result = delegate.reduce( identity, accumulator ); - close(); - return result; - } - - @Override - public Optional reduce(BinaryOperator accumulator) { - Optional result = delegate.reduce( accumulator ); - close(); - return result; - } - - @Override - public U reduce( - U identity, BiFunction accumulator, BinaryOperator combiner) { - U result = delegate.reduce( identity, accumulator, combiner ); - close(); - return result; - } - - @Override - public R1 collect( - Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { - R1 result = delegate.collect( supplier, accumulator, combiner ); - close(); - return result; - } - - @Override - public R1 collect(Collector collector) { - R1 result = delegate.collect( collector ); - close(); - return result; - } - - @Override - public Optional min(Comparator comparator) { - Optional result = delegate.min( comparator ); - close(); - return result; - } - - @Override - public Optional max(Comparator comparator) { - Optional result = delegate.max( comparator ); - close(); - return result; - } - - @Override - public long count() { - long result = delegate.count(); - close(); - return result; - } - - @Override - public boolean anyMatch(Predicate predicate) { - boolean result = delegate.anyMatch( predicate ); - close(); - return result; - } - - @Override - public boolean allMatch(Predicate predicate) { - boolean result = delegate.allMatch( predicate ); - close(); - return result; - } - - @Override - public boolean noneMatch(Predicate predicate) { - boolean result = delegate.noneMatch( predicate ); - close(); - return result; - } - - @Override - public Optional findFirst() { - Optional result = delegate.findFirst(); - close(); - return result; - } - - @Override - public Optional findAny() { - Optional result = delegate.findAny(); - close(); - return result; - } - - @Override - public Iterator iterator() { - return delegate.iterator(); - } - - @Override - public Spliterator spliterator() { - return delegate.spliterator(); - } - - @Override - public boolean isParallel() { - return delegate.isParallel(); - } - - @Override - public Stream sequential() { - return new StreamDecorator<>( delegate.sequential(), closeHandler ); - } - - @Override - public Stream parallel() { - return new StreamDecorator<>( delegate.parallel(), closeHandler ); - } - - @Override - public Stream unordered() { - return new StreamDecorator<>( delegate.unordered(), closeHandler ); - } - - @Override - public Stream onClose(Runnable closeHandler) { - this.delegate.onClose( closeHandler ); - return this; - } - - @Override - public void close() { - delegate.close(); - } - - //Methods added to JDK 9 - - public Stream takeWhile(Predicate predicate) { - try { - @SuppressWarnings("unchecked") - Stream result = (Stream) - 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 dropWhile(Predicate predicate) { - try { - @SuppressWarnings("unchecked") - Stream result = (Stream) - ReflectHelper.getMethod( Stream.class, "dropWhile", Predicate.class ) - .invoke( delegate, predicate ); - return new StreamDecorator<>( result, closeHandler ); - } - catch (IllegalAccessException | InvocationTargetException e) { - throw new HibernateException( e ); - } - } -}