From 1dfef51587d96864cbb0d7c6e41c331b35507696 Mon Sep 17 00:00:00 2001 From: Per Minborg Date: Wed, 30 Dec 2020 16:56:53 +0100 Subject: [PATCH] Add XTerminatingOperationFactory, Work on #44 --- .../DoubleTerminalOperationFactory.java | 68 +++++ .../terminal/IntTerminalOperationFactory.java | 67 +++++ .../LongTerminalOperationFactory.java | 67 +++++ .../internal/AutoClosingDoubleStreamTest.java | 2 +- .../internal/AutoClosingStreamTest.java | 2 +- ...nternalDoubleTerminalOperationFactory.java | 241 +++++++++++++++++ .../InternalIntTerminalOperationFactory.java | 242 ++++++++++++++++++ .../InternalLongTerminalOperationFactory.java | 240 +++++++++++++++++ ...tandardDoubleTerminalOperationFactory.java | 124 +++++++++ .../StandardIntTerminalOperationFactory.java | 122 +++++++++ .../StandardLongTerminalOperationFactory.java | 122 +++++++++ ...ne.terminal.DoubleTerminalOperationFactory | 1 + ...eline.terminal.IntTerminalOperationFactory | 1 + ...line.terminal.LongTerminalOperationFactory | 1 + 14 files changed, 1298 insertions(+), 2 deletions(-) create mode 100644 pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/DoubleTerminalOperationFactory.java create mode 100644 pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/IntTerminalOperationFactory.java create mode 100644 pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/LongTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalDoubleTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalIntTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalLongTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardDoubleTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardIntTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardLongTerminalOperationFactory.java create mode 100644 provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory create mode 100644 provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory create mode 100644 provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory diff --git a/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/DoubleTerminalOperationFactory.java b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/DoubleTerminalOperationFactory.java new file mode 100644 index 00000000..66d1b2f6 --- /dev/null +++ b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/DoubleTerminalOperationFactory.java @@ -0,0 +1,68 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.terminal; + +import java.util.*; +import java.util.function.*; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; + +public interface DoubleTerminalOperationFactory extends BaseStreamTerminalOperationFactory { + + TerminalOperation createForEach(DoubleConsumer action); + + TerminalOperation createForEachOrdered(DoubleConsumer action); + + TerminalOperation acquireToArray(); + + TerminalOperation createReduce(double identity, DoubleBinaryOperator op); + + TerminalOperation createReduce(DoubleBinaryOperator op); + + TerminalOperation createCollect(Supplier supplier, + ObjDoubleConsumer accumulator, + BiConsumer combiner); + + TerminalOperation acquireSum(); + + TerminalOperation acquireMin(); + + TerminalOperation acquireMax(); + + TerminalOperation acquireCount(); + + + TerminalOperation acquireAverage(); + + TerminalOperation acquireSummaryStatistics(); + + + TerminalOperation createAnyMatch(DoublePredicate predicate); + + TerminalOperation createAllMatch(DoublePredicate predicate); + + TerminalOperation createNoneMatch(DoublePredicate predicate); + + TerminalOperation acquireFindFirst(); + + TerminalOperation acquireFindAny(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireIterator(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireSpliterator(); + +} \ No newline at end of file diff --git a/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/IntTerminalOperationFactory.java b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/IntTerminalOperationFactory.java new file mode 100644 index 00000000..1da11dad --- /dev/null +++ b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/IntTerminalOperationFactory.java @@ -0,0 +1,67 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.terminal; + +import java.util.*; +import java.util.function.*; +import java.util.stream.BaseStream; +import java.util.stream.IntStream; + +public interface IntTerminalOperationFactory extends BaseStreamTerminalOperationFactory { + + TerminalOperation createForEach(IntConsumer action); + + TerminalOperation createForEachOrdered(IntConsumer action); + + TerminalOperation acquireToArray(); + + TerminalOperation createReduce(int identity, IntBinaryOperator op); + + TerminalOperation createReduce(IntBinaryOperator op); + + TerminalOperation createCollect(Supplier supplier, + ObjIntConsumer accumulator, + BiConsumer combiner); + + TerminalOperation acquireSum(); + + TerminalOperation acquireMin(); + + TerminalOperation acquireMax(); + + TerminalOperation acquireCount(); + + + TerminalOperation acquireAverage(); + + TerminalOperation acquireSummaryStatistics(); + + + TerminalOperation createAnyMatch(IntPredicate predicate); + + TerminalOperation createAllMatch(IntPredicate predicate); + + TerminalOperation createNoneMatch(IntPredicate predicate); + + TerminalOperation acquireFindFirst(); + + TerminalOperation acquireFindAny(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireIterator(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireSpliterator(); +} \ No newline at end of file diff --git a/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/LongTerminalOperationFactory.java b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/LongTerminalOperationFactory.java new file mode 100644 index 00000000..ac8f130e --- /dev/null +++ b/pipeline/src/main/java/com/speedment/jpastreamer/pipeline/terminal/LongTerminalOperationFactory.java @@ -0,0 +1,67 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.terminal; + +import java.util.*; +import java.util.function.*; +import java.util.stream.LongStream; + +public interface LongTerminalOperationFactory extends BaseStreamTerminalOperationFactory { + + TerminalOperation createForEach(LongConsumer action); + + TerminalOperation createForEachOrdered(LongConsumer action); + + TerminalOperation acquireToArray(); + + TerminalOperation createReduce(long identity, LongBinaryOperator op); + + TerminalOperation createReduce(LongBinaryOperator op); + + TerminalOperation createCollect(Supplier supplier, + ObjLongConsumer accumulator, + BiConsumer combiner); + + TerminalOperation acquireSum(); + + TerminalOperation acquireMin(); + + TerminalOperation acquireMax(); + + TerminalOperation acquireCount(); + + + TerminalOperation acquireAverage(); + + TerminalOperation acquireSummaryStatistics(); + + + TerminalOperation createAnyMatch(LongPredicate predicate); + + TerminalOperation createAllMatch(LongPredicate predicate); + + TerminalOperation createNoneMatch(LongPredicate predicate); + + TerminalOperation acquireFindFirst(); + + TerminalOperation acquireFindAny(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireIterator(); + + @SuppressWarnings("unchecked") + @Override + TerminalOperation acquireSpliterator(); + +} \ No newline at end of file diff --git a/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingDoubleStreamTest.java b/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingDoubleStreamTest.java index 11a2d8f8..fff0e8ad 100644 --- a/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingDoubleStreamTest.java +++ b/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingDoubleStreamTest.java @@ -140,7 +140,7 @@ void testReduce() { @Test void collect() { - testTerminal(s -> s.collect(AtomicLong::new, (al, d) -> al.addAndGet((long) d), (a, b) -> a.addAndGet((long) b.get())), (a, b) -> a.get() == b.get()); + testTerminal(s -> s.collect(AtomicLong::new, (al, d) -> al.addAndGet((long) d), (a, b) -> a.addAndGet(b.get())), (a, b) -> a.get() == b.get()); } @Test diff --git a/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingStreamTest.java b/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingStreamTest.java index 6b310c0e..562a6c91 100644 --- a/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingStreamTest.java +++ b/provider/autoclose-standard/src/test/java/com/speedment/jpastreamer/autoclose/standard/internal/AutoClosingStreamTest.java @@ -22,7 +22,7 @@ protected Stream initialStream() { @Override protected Stream autoClosingStream(Stream stream, boolean allowStreamIteratorAndSpliterator) { - return new AutoClosingStream(stream, allowStreamIteratorAndSpliterator); + return new AutoClosingStream<>(stream, allowStreamIteratorAndSpliterator); } @Override diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalDoubleTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalDoubleTerminalOperationFactory.java new file mode 100644 index 00000000..88481b33 --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalDoubleTerminalOperationFactory.java @@ -0,0 +1,241 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.internal.terminal; + +import com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationType; + +import java.util.*; +import java.util.function.*; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; + +import static java.util.Objects.requireNonNull; + +public class InternalDoubleTerminalOperationFactory implements DoubleTerminalOperationFactory { + + private static final TerminalOperation TO_ARRAY = new ApplyTerminalOperation<>( + TerminalOperationType.TO_ARRAY, + DoubleStream.class, + double[].class, + DoubleStream::toArray); + + private static final TerminalOperation SUM = new ApplyTerminalOperation<>( + TerminalOperationType.SUM_DOUBLE, + DoubleStream.class, + double.class, + DoubleStream::sum); + + private static final TerminalOperation MIN = new ApplyTerminalOperation<>( + TerminalOperationType.MIN, + DoubleStream.class, + OptionalDouble.class, + DoubleStream::min); + + private static final TerminalOperation MAX = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + DoubleStream.class, + OptionalDouble.class, + DoubleStream::max); + + private static final TerminalOperation AVERAGE = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + DoubleStream.class, + OptionalDouble.class, + DoubleStream::average); + + private static final TerminalOperation SUMMARY_STATISTICS = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + DoubleStream.class, + DoubleSummaryStatistics.class, + DoubleStream::summaryStatistics); + + private static final TerminalOperation FIND_FIRST = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_FIRST, + DoubleStream.class, + OptionalDouble.class, + DoubleStream::findFirst); + + private static final TerminalOperation FIND_ANY = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_ANY, + DoubleStream.class, + OptionalDouble.class, + DoubleStream::findAny); + + private static final TerminalOperation COUNT = new ApplyAsLongTerminalOperation<>( + TerminalOperationType.COUNT, + DoubleStream.class, + long.class, + DoubleStream::count); + + private static final TerminalOperation ITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.ITERATOR, + DoubleStream.class, + PrimitiveIterator.OfDouble.class, + DoubleStream::iterator); + + private static final TerminalOperation SPLITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.SPLITERATOR, + DoubleStream.class, + Spliterator.OfDouble.class, + DoubleStream::spliterator); + + @Override + public TerminalOperation createForEach(DoubleConsumer action) { + requireNonNull(action); + + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH, + DoubleStream.class, + void.class, + stream -> stream.forEach(action), + action); + } + + @Override + public TerminalOperation createForEachOrdered(DoubleConsumer action) { + requireNonNull(action); + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH_ORDERED, + DoubleStream.class, + void.class, + stream -> stream.forEachOrdered(action), + action); + } + + @Override + public TerminalOperation acquireToArray() { + return TO_ARRAY; + } + + @Override + public TerminalOperation createReduce(double identity, DoubleBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + DoubleStream.class, + double.class, + stream -> stream.reduce(identity, op), + identity, op); + } + + @Override + public TerminalOperation createReduce(DoubleBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + DoubleStream.class, + OptionalDouble.class, + stream -> stream.reduce(op), + op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, + ObjDoubleConsumer accumulator, + BiConsumer combiner) { + requireNonNull(supplier); + requireNonNull(accumulator); + requireNonNull(combiner); + return new ApplyTerminalOperation<>( + TerminalOperationType.COLLECT, + DoubleStream.class, + Object.class, + stream -> stream.collect(supplier, accumulator, combiner), + supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return SUM; + } + + @Override + public TerminalOperation acquireMin() { + return MIN; + } + + @Override + public TerminalOperation acquireMax() { + return MAX; + } + + @Override + public TerminalOperation acquireCount() { + return COUNT; + } + + @Override + public TerminalOperation acquireAverage() { + return AVERAGE; + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return SUMMARY_STATISTICS; + } + + @Override + public TerminalOperation createAnyMatch(DoublePredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ANY_MATCH, + DoubleStream.class, + boolean.class, + stream -> stream.anyMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createAllMatch(DoublePredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ALL_MATCH, + DoubleStream.class, + boolean.class, + stream -> stream.allMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createNoneMatch(DoublePredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.NONE_MATCH, + DoubleStream.class, + boolean.class, + stream -> stream.noneMatch(predicate), + predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return FIND_FIRST; + } + + @Override + public TerminalOperation acquireFindAny() { + return FIND_ANY; + } + + @Override + public TerminalOperation acquireIterator() { + return ITERATOR; + } + + @Override + public TerminalOperation acquireSpliterator() { + return SPLITERATOR; + } +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalIntTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalIntTerminalOperationFactory.java new file mode 100644 index 00000000..1dca691f --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalIntTerminalOperationFactory.java @@ -0,0 +1,242 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.internal.terminal; + +import com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationType; + +import java.util.*; +import java.util.function.*; +import java.util.stream.BaseStream; +import java.util.stream.Collector; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static java.util.Objects.requireNonNull; + +public class InternalIntTerminalOperationFactory implements IntTerminalOperationFactory { + + private static final TerminalOperation TO_ARRAY = new ApplyTerminalOperation<>( + TerminalOperationType.TO_ARRAY, + IntStream.class, + int[].class, + IntStream::toArray); + + private static final TerminalOperation SUM = new ApplyTerminalOperation<>( + TerminalOperationType.SUM_INT, + IntStream.class, + int.class, + IntStream::sum); + + private static final TerminalOperation MIN = new ApplyTerminalOperation<>( + TerminalOperationType.MIN, + IntStream.class, + OptionalInt.class, + IntStream::min); + + private static final TerminalOperation MAX = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + IntStream.class, + OptionalInt.class, + IntStream::max); + + private static final TerminalOperation AVERAGE = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + IntStream.class, + OptionalDouble.class, + IntStream::average); + + private static final TerminalOperation SUMMARY_STATISTICS = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + IntStream.class, + IntSummaryStatistics.class, + IntStream::summaryStatistics); + + private static final TerminalOperation FIND_FIRST = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_FIRST, + IntStream.class, + OptionalInt.class, + IntStream::findFirst); + + private static final TerminalOperation FIND_ANY = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_ANY, + IntStream.class, + OptionalInt.class, + IntStream::findAny); + + private static final TerminalOperation COUNT = new ApplyAsLongTerminalOperation<>( + TerminalOperationType.COUNT, + IntStream.class, + long.class, + IntStream::count); + + private static final TerminalOperation ITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.ITERATOR, + IntStream.class, + PrimitiveIterator.OfInt.class, + IntStream::iterator); + + private static final TerminalOperation SPLITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.SPLITERATOR, + IntStream.class, + Spliterator.OfInt.class, + IntStream::spliterator); + + @Override + public TerminalOperation createForEach(IntConsumer action) { + requireNonNull(action); + + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH, + IntStream.class, + void.class, + stream -> stream.forEach(action), + action); + } + + @Override + public TerminalOperation createForEachOrdered(IntConsumer action) { + requireNonNull(action); + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH_ORDERED, + IntStream.class, + void.class, + stream -> stream.forEachOrdered(action), + action); + } + + @Override + public TerminalOperation acquireToArray() { + return TO_ARRAY; + } + + @Override + public TerminalOperation createReduce(int identity, IntBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + IntStream.class, + int.class, + stream -> stream.reduce(identity, op), + identity, op); + } + + @Override + public TerminalOperation createReduce(IntBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + IntStream.class, + OptionalInt.class, + stream -> stream.reduce(op), + op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + requireNonNull(supplier); + requireNonNull(accumulator); + requireNonNull(combiner); + return new ApplyTerminalOperation<>( + TerminalOperationType.COLLECT, + IntStream.class, + Object.class, + stream -> stream.collect(supplier, accumulator, combiner), + supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return SUM; + } + + @Override + public TerminalOperation acquireMin() { + return MIN; + } + + @Override + public TerminalOperation acquireMax() { + return MAX; + } + + @Override + public TerminalOperation acquireCount() { + return COUNT; + } + + @Override + public TerminalOperation acquireAverage() { + return AVERAGE; + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return SUMMARY_STATISTICS; + } + + @Override + public TerminalOperation createAnyMatch(IntPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ANY_MATCH, + IntStream.class, + boolean.class, + stream -> stream.anyMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createAllMatch(IntPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ALL_MATCH, + IntStream.class, + boolean.class, + stream -> stream.allMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createNoneMatch(IntPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.NONE_MATCH, + IntStream.class, + boolean.class, + stream -> stream.noneMatch(predicate), + predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return FIND_FIRST; + } + + @Override + public TerminalOperation acquireFindAny() { + return FIND_ANY; + } + + @Override + public TerminalOperation acquireIterator() { + return ITERATOR; + } + + @Override + public TerminalOperation acquireSpliterator() { + return SPLITERATOR; + } +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalLongTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalLongTerminalOperationFactory.java new file mode 100644 index 00000000..230da80e --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/internal/terminal/InternalLongTerminalOperationFactory.java @@ -0,0 +1,240 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.internal.terminal; + +import com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperationType; + +import java.util.*; +import java.util.function.*; +import java.util.stream.IntStream; +import java.util.stream.LongStream; + +import static java.util.Objects.requireNonNull; + +public class InternalLongTerminalOperationFactory implements LongTerminalOperationFactory { + + private static final TerminalOperation TO_ARRAY = new ApplyTerminalOperation<>( + TerminalOperationType.TO_ARRAY, + LongStream.class, + long[].class, + LongStream::toArray); + + private static final TerminalOperation SUM = new ApplyTerminalOperation<>( + TerminalOperationType.SUM_LONG, + LongStream.class, + long.class, + LongStream::sum); + + private static final TerminalOperation MIN = new ApplyTerminalOperation<>( + TerminalOperationType.MIN, + LongStream.class, + OptionalLong.class, + LongStream::min); + + private static final TerminalOperation MAX = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + LongStream.class, + OptionalLong.class, + LongStream::max); + + private static final TerminalOperation AVERAGE = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + LongStream.class, + OptionalDouble.class, + LongStream::average); + + private static final TerminalOperation SUMMARY_STATISTICS = new ApplyTerminalOperation<>( + TerminalOperationType.MAX, + LongStream.class, + LongSummaryStatistics.class, + LongStream::summaryStatistics); + + private static final TerminalOperation FIND_FIRST = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_FIRST, + LongStream.class, + OptionalLong.class, + LongStream::findFirst); + + private static final TerminalOperation FIND_ANY = new ApplyTerminalOperation<>( + TerminalOperationType.FIND_ANY, + LongStream.class, + OptionalLong.class, + LongStream::findAny); + + private static final TerminalOperation COUNT = new ApplyAsLongTerminalOperation<>( + TerminalOperationType.COUNT, + LongStream.class, + long.class, + LongStream::count); + + private static final TerminalOperation ITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.ITERATOR, + LongStream.class, + PrimitiveIterator.OfLong.class, + LongStream::iterator); + + private static final TerminalOperation SPLITERATOR = new ApplyTerminalOperation<>( + TerminalOperationType.SPLITERATOR, + LongStream.class, + Spliterator.OfLong.class, + LongStream::spliterator); + + @Override + public TerminalOperation createForEach(LongConsumer action) { + requireNonNull(action); + + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH, + LongStream.class, + void.class, + stream -> stream.forEach(action), + action); + } + + @Override + public TerminalOperation createForEachOrdered(LongConsumer action) { + requireNonNull(action); + return new AcceptTerminalOperation<>( + TerminalOperationType.FOR_EACH_ORDERED, + LongStream.class, + void.class, + stream -> stream.forEachOrdered(action), + action); + } + + @Override + public TerminalOperation acquireToArray() { + return TO_ARRAY; + } + + @Override + public TerminalOperation createReduce(long identity, LongBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + LongStream.class, + long.class, + stream -> stream.reduce(identity, op), + identity, op); + } + + @Override + public TerminalOperation createReduce(LongBinaryOperator op) { + requireNonNull(op); + return new ApplyTerminalOperation<>( + TerminalOperationType.REDUCE, + LongStream.class, + OptionalLong.class, + stream -> stream.reduce(op), + op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + requireNonNull(supplier); + requireNonNull(accumulator); + requireNonNull(combiner); + return new ApplyTerminalOperation<>( + TerminalOperationType.COLLECT, + LongStream.class, + Object.class, + stream -> stream.collect(supplier, accumulator, combiner), + supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return SUM; + } + + @Override + public TerminalOperation acquireMin() { + return MIN; + } + + @Override + public TerminalOperation acquireMax() { + return MAX; + } + + @Override + public TerminalOperation acquireCount() { + return COUNT; + } + + @Override + public TerminalOperation acquireAverage() { + return AVERAGE; + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return SUMMARY_STATISTICS; + } + + @Override + public TerminalOperation createAnyMatch(LongPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ANY_MATCH, + LongStream.class, + boolean.class, + stream -> stream.anyMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createAllMatch(LongPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.ALL_MATCH, + LongStream.class, + boolean.class, + stream -> stream.allMatch(predicate), + predicate); + } + + @Override + public TerminalOperation createNoneMatch(LongPredicate predicate) { + requireNonNull(predicate); + return new TestTerminalOperation<>( + TerminalOperationType.NONE_MATCH, + LongStream.class, + boolean.class, + stream -> stream.noneMatch(predicate), + predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return FIND_FIRST; + } + + @Override + public TerminalOperation acquireFindAny() { + return FIND_ANY; + } + + @Override + public TerminalOperation acquireIterator() { + return ITERATOR; + } + + @Override + public TerminalOperation acquireSpliterator() { + return SPLITERATOR; + } +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardDoubleTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardDoubleTerminalOperationFactory.java new file mode 100644 index 00000000..75bb3fe0 --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardDoubleTerminalOperationFactory.java @@ -0,0 +1,124 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.terminal; + +import com.speedment.jpastreamer.pipeline.standard.internal.terminal.InternalDoubleTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.standard.internal.terminal.InternalIntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; + +import java.util.*; +import java.util.function.*; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; + +public class StandardDoubleTerminalOperationFactory implements DoubleTerminalOperationFactory { + + private final DoubleTerminalOperationFactory delegate = new InternalDoubleTerminalOperationFactory(); + + @Override + public TerminalOperation createForEach(DoubleConsumer action) { + return delegate.createForEach(action); + } + + @Override + public TerminalOperation createForEachOrdered(DoubleConsumer action) { + return delegate.createForEachOrdered(action); + } + + @Override + public TerminalOperation acquireToArray() { + return delegate.acquireToArray(); + } + + @Override + public TerminalOperation createReduce(double identity, DoubleBinaryOperator op) { + return delegate.createReduce(identity, op); + } + + @Override + public TerminalOperation createReduce(DoubleBinaryOperator op) { + return delegate.createReduce(op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + return delegate.createCollect(supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return delegate.acquireSum(); + } + + @Override + public TerminalOperation acquireMin() { + return delegate.acquireMin(); + } + + @Override + public TerminalOperation acquireMax() { + return delegate.acquireMax(); + } + + @Override + public TerminalOperation acquireCount() { + return delegate.acquireCount(); + } + + @Override + public TerminalOperation acquireAverage() { + return delegate.acquireAverage(); + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return delegate.acquireSummaryStatistics(); + } + + @Override + public TerminalOperation createAnyMatch(DoublePredicate predicate) { + return delegate.createAnyMatch(predicate); + } + + @Override + public TerminalOperation createAllMatch(DoublePredicate predicate) { + return delegate.createAllMatch(predicate); + } + + @Override + public TerminalOperation createNoneMatch(DoublePredicate predicate) { + return delegate.createNoneMatch(predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return delegate.acquireFindFirst(); + } + + @Override + public TerminalOperation acquireFindAny() { + return delegate.acquireFindAny(); + } + + @Override + public TerminalOperation acquireIterator() { + return delegate.acquireIterator(); + } + + @Override + public TerminalOperation acquireSpliterator() { + return delegate.acquireSpliterator(); + } +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardIntTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardIntTerminalOperationFactory.java new file mode 100644 index 00000000..6ca77608 --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardIntTerminalOperationFactory.java @@ -0,0 +1,122 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.terminal; + +import com.speedment.jpastreamer.pipeline.standard.internal.terminal.InternalIntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; + +import java.util.*; +import java.util.function.*; +import java.util.stream.IntStream; + +public class StandardIntTerminalOperationFactory implements IntTerminalOperationFactory { + + private final IntTerminalOperationFactory delegate = new InternalIntTerminalOperationFactory(); + + @Override + public TerminalOperation createForEach(IntConsumer action) { + return delegate.createForEach(action); + } + + @Override + public TerminalOperation createForEachOrdered(IntConsumer action) { + return delegate.createForEachOrdered(action); + } + + @Override + public TerminalOperation acquireToArray() { + return delegate.acquireToArray(); + } + + @Override + public TerminalOperation createReduce(int identity, IntBinaryOperator op) { + return delegate.createReduce(identity, op); + } + + @Override + public TerminalOperation createReduce(IntBinaryOperator op) { + return delegate.createReduce(op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + return delegate.createCollect(supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return delegate.acquireSum(); + } + + @Override + public TerminalOperation acquireMin() { + return delegate.acquireMin(); + } + + @Override + public TerminalOperation acquireMax() { + return delegate.acquireMax(); + } + + @Override + public TerminalOperation acquireCount() { + return delegate.acquireCount(); + } + + @Override + public TerminalOperation acquireAverage() { + return delegate.acquireAverage(); + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return delegate.acquireSummaryStatistics(); + } + + @Override + public TerminalOperation createAnyMatch(IntPredicate predicate) { + return delegate.createAnyMatch(predicate); + } + + @Override + public TerminalOperation createAllMatch(IntPredicate predicate) { + return delegate.createAllMatch(predicate); + } + + @Override + public TerminalOperation createNoneMatch(IntPredicate predicate) { + return delegate.createNoneMatch(predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return delegate.acquireFindFirst(); + } + + @Override + public TerminalOperation acquireFindAny() { + return delegate.acquireFindAny(); + } + + @Override + public TerminalOperation acquireIterator() { + return delegate.acquireIterator(); + } + + @Override + public TerminalOperation acquireSpliterator() { + return delegate.acquireSpliterator(); + } + +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardLongTerminalOperationFactory.java b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardLongTerminalOperationFactory.java new file mode 100644 index 00000000..91f3a756 --- /dev/null +++ b/provider/pipeline-standard/src/main/java/com/speedment/jpastreamer/pipeline/standard/terminal/StandardLongTerminalOperationFactory.java @@ -0,0 +1,122 @@ +/* + * JPAstreamer - Express JPA queries with Java Streams + * Copyright (c) 2020-2020, Speedment, Inc. All Rights Reserved. + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * See: https://github.com/speedment/jpa-streamer/blob/master/LICENSE + */ +package com.speedment.jpastreamer.pipeline.standard.terminal; + +import com.speedment.jpastreamer.pipeline.standard.internal.terminal.InternalLongTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory; +import com.speedment.jpastreamer.pipeline.terminal.TerminalOperation; + +import java.util.*; +import java.util.function.*; +import java.util.stream.LongStream; + +public class StandardLongTerminalOperationFactory implements LongTerminalOperationFactory { + + private final LongTerminalOperationFactory delegate = new InternalLongTerminalOperationFactory(); + + @Override + public TerminalOperation createForEach(LongConsumer action) { + return delegate.createForEach(action); + } + + @Override + public TerminalOperation createForEachOrdered(LongConsumer action) { + return delegate.createForEachOrdered(action); + } + + @Override + public TerminalOperation acquireToArray() { + return delegate.acquireToArray(); + } + + @Override + public TerminalOperation createReduce(long identity, LongBinaryOperator op) { + return delegate.createReduce(identity, op); + } + + @Override + public TerminalOperation createReduce(LongBinaryOperator op) { + return delegate.createReduce(op); + } + + @Override + public TerminalOperation createCollect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + return delegate.createCollect(supplier, accumulator, combiner); + } + + @Override + public TerminalOperation acquireSum() { + return delegate.acquireSum(); + } + + @Override + public TerminalOperation acquireMin() { + return delegate.acquireMin(); + } + + @Override + public TerminalOperation acquireMax() { + return delegate.acquireMax(); + } + + @Override + public TerminalOperation acquireCount() { + return delegate.acquireCount(); + } + + @Override + public TerminalOperation acquireAverage() { + return delegate.acquireAverage(); + } + + @Override + public TerminalOperation acquireSummaryStatistics() { + return delegate.acquireSummaryStatistics(); + } + + @Override + public TerminalOperation createAnyMatch(LongPredicate predicate) { + return delegate.createAnyMatch(predicate); + } + + @Override + public TerminalOperation createAllMatch(LongPredicate predicate) { + return delegate.createAllMatch(predicate); + } + + @Override + public TerminalOperation createNoneMatch(LongPredicate predicate) { + return delegate.createNoneMatch(predicate); + } + + @Override + public TerminalOperation acquireFindFirst() { + return delegate.acquireFindFirst(); + } + + @Override + public TerminalOperation acquireFindAny() { + return delegate.acquireFindAny(); + } + + @Override + public TerminalOperation acquireIterator() { + return delegate.acquireIterator(); + } + + @Override + public TerminalOperation acquireSpliterator() { + return delegate.acquireSpliterator(); + } + +} \ No newline at end of file diff --git a/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory new file mode 100644 index 00000000..f7030c8a --- /dev/null +++ b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.DoubleTerminalOperationFactory @@ -0,0 +1 @@ +com.speedment.jpastreamer.pipeline.standard.terminal.StandardDoubleTerminalOperationFactory diff --git a/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory new file mode 100644 index 00000000..1f63da94 --- /dev/null +++ b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.IntTerminalOperationFactory @@ -0,0 +1 @@ +com.speedment.jpastreamer.pipeline.standard.terminal.StandardIntTerminalOperationFactory diff --git a/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory new file mode 100644 index 00000000..fb0c1349 --- /dev/null +++ b/provider/pipeline-standard/src/main/resources/META-INF/services/com.speedment.jpastreamer.pipeline.terminal.LongTerminalOperationFactory @@ -0,0 +1 @@ +com.speedment.jpastreamer.pipeline.standard.terminal.StandardLongTerminalOperationFactory