├── .gitignore ├── GPL_ClasspathException ├── README.md ├── art ├── streamsupport-sf.png └── streamsupport-sf.svg ├── docs ├── apidocs │ ├── allclasses-frame.html │ ├── allclasses-noframe.html │ ├── constant-values.html │ ├── deprecated-list.html │ ├── help-doc.html │ ├── index-all.html │ ├── index.html │ ├── java9 │ │ ├── lang │ │ │ ├── Doubles.html │ │ │ ├── FunctionalInterface.html │ │ │ ├── Integers.html │ │ │ ├── Iterables.html │ │ │ ├── Longs.html │ │ │ ├── class-use │ │ │ │ ├── Doubles.html │ │ │ │ ├── FunctionalInterface.html │ │ │ │ ├── Integers.html │ │ │ │ ├── Iterables.html │ │ │ │ └── Longs.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ └── util │ │ │ ├── Comparators.html │ │ │ ├── DoubleSummaryStatistics.html │ │ │ ├── IntSummaryStatistics.html │ │ │ ├── Iterators.html │ │ │ ├── J8Arrays.html │ │ │ ├── Lists.html │ │ │ ├── LongSummaryStatistics.html │ │ │ ├── Maps.Entry.html │ │ │ ├── Maps.html │ │ │ ├── Objects.html │ │ │ ├── Optional.html │ │ │ ├── OptionalDouble.html │ │ │ ├── OptionalInt.html │ │ │ ├── OptionalLong.html │ │ │ ├── PrimitiveIterator.OfDouble.html │ │ │ ├── PrimitiveIterator.OfInt.html │ │ │ ├── PrimitiveIterator.OfLong.html │ │ │ ├── PrimitiveIterator.html │ │ │ ├── Sets.html │ │ │ ├── Spliterator.OfDouble.html │ │ │ ├── Spliterator.OfInt.html │ │ │ ├── Spliterator.OfLong.html │ │ │ ├── Spliterator.OfPrimitive.html │ │ │ ├── Spliterator.html │ │ │ ├── Spliterators.AbstractDoubleSpliterator.html │ │ │ ├── Spliterators.AbstractIntSpliterator.html │ │ │ ├── Spliterators.AbstractLongSpliterator.html │ │ │ ├── Spliterators.AbstractSpliterator.html │ │ │ ├── Spliterators.html │ │ │ ├── SplittableRandom.html │ │ │ ├── StringJoiner.html │ │ │ ├── class-use │ │ │ ├── Comparators.html │ │ │ ├── DoubleSummaryStatistics.html │ │ │ ├── IntSummaryStatistics.html │ │ │ ├── Iterators.html │ │ │ ├── J8Arrays.html │ │ │ ├── Lists.html │ │ │ ├── LongSummaryStatistics.html │ │ │ ├── Maps.Entry.html │ │ │ ├── Maps.html │ │ │ ├── Objects.html │ │ │ ├── Optional.html │ │ │ ├── OptionalDouble.html │ │ │ ├── OptionalInt.html │ │ │ ├── OptionalLong.html │ │ │ ├── PrimitiveIterator.OfDouble.html │ │ │ ├── PrimitiveIterator.OfInt.html │ │ │ ├── PrimitiveIterator.OfLong.html │ │ │ ├── PrimitiveIterator.html │ │ │ ├── Sets.html │ │ │ ├── Spliterator.OfDouble.html │ │ │ ├── Spliterator.OfInt.html │ │ │ ├── Spliterator.OfLong.html │ │ │ ├── Spliterator.OfPrimitive.html │ │ │ ├── Spliterator.html │ │ │ ├── Spliterators.AbstractDoubleSpliterator.html │ │ │ ├── Spliterators.AbstractIntSpliterator.html │ │ │ ├── Spliterators.AbstractLongSpliterator.html │ │ │ ├── Spliterators.AbstractSpliterator.html │ │ │ ├── Spliterators.html │ │ │ ├── SplittableRandom.html │ │ │ └── StringJoiner.html │ │ │ ├── concurrent │ │ │ ├── ConcurrentMaps.html │ │ │ ├── CountedCompleter.html │ │ │ ├── ForkJoinPool.ForkJoinWorkerThreadFactory.html │ │ │ ├── ForkJoinPool.ManagedBlocker.html │ │ │ ├── ForkJoinPool.html │ │ │ ├── ForkJoinTask.html │ │ │ ├── ForkJoinWorkerThread.html │ │ │ ├── RecursiveAction.html │ │ │ ├── RecursiveTask.html │ │ │ ├── ThreadLocalRandom.html │ │ │ ├── class-use │ │ │ │ ├── ConcurrentMaps.html │ │ │ │ ├── CountedCompleter.html │ │ │ │ ├── ForkJoinPool.ForkJoinWorkerThreadFactory.html │ │ │ │ ├── ForkJoinPool.ManagedBlocker.html │ │ │ │ ├── ForkJoinPool.html │ │ │ │ ├── ForkJoinTask.html │ │ │ │ ├── ForkJoinWorkerThread.html │ │ │ │ ├── RecursiveAction.html │ │ │ │ ├── RecursiveTask.html │ │ │ │ └── ThreadLocalRandom.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ │ ├── function │ │ │ ├── BiConsumer.html │ │ │ ├── BiFunction.html │ │ │ ├── BiPredicate.html │ │ │ ├── BinaryOperator.html │ │ │ ├── BooleanSupplier.html │ │ │ ├── Consumer.html │ │ │ ├── DoubleBinaryOperator.html │ │ │ ├── DoubleConsumer.html │ │ │ ├── DoubleFunction.html │ │ │ ├── DoublePredicate.html │ │ │ ├── DoubleSupplier.html │ │ │ ├── DoubleToIntFunction.html │ │ │ ├── DoubleToLongFunction.html │ │ │ ├── DoubleUnaryOperator.html │ │ │ ├── Function.html │ │ │ ├── IntBinaryOperator.html │ │ │ ├── IntConsumer.html │ │ │ ├── IntFunction.html │ │ │ ├── IntPredicate.html │ │ │ ├── IntSupplier.html │ │ │ ├── IntToDoubleFunction.html │ │ │ ├── IntToLongFunction.html │ │ │ ├── IntUnaryOperator.html │ │ │ ├── LongBinaryOperator.html │ │ │ ├── LongConsumer.html │ │ │ ├── LongFunction.html │ │ │ ├── LongPredicate.html │ │ │ ├── LongSupplier.html │ │ │ ├── LongToDoubleFunction.html │ │ │ ├── LongToIntFunction.html │ │ │ ├── LongUnaryOperator.html │ │ │ ├── ObjDoubleConsumer.html │ │ │ ├── ObjIntConsumer.html │ │ │ ├── ObjLongConsumer.html │ │ │ ├── Predicate.html │ │ │ ├── Supplier.html │ │ │ ├── ToDoubleBiFunction.html │ │ │ ├── ToDoubleFunction.html │ │ │ ├── ToIntBiFunction.html │ │ │ ├── ToIntFunction.html │ │ │ ├── ToLongBiFunction.html │ │ │ ├── ToLongFunction.html │ │ │ ├── UnaryOperator.html │ │ │ ├── class-use │ │ │ │ ├── BiConsumer.html │ │ │ │ ├── BiFunction.html │ │ │ │ ├── BiPredicate.html │ │ │ │ ├── BinaryOperator.html │ │ │ │ ├── BooleanSupplier.html │ │ │ │ ├── Consumer.html │ │ │ │ ├── DoubleBinaryOperator.html │ │ │ │ ├── DoubleConsumer.html │ │ │ │ ├── DoubleFunction.html │ │ │ │ ├── DoublePredicate.html │ │ │ │ ├── DoubleSupplier.html │ │ │ │ ├── DoubleToIntFunction.html │ │ │ │ ├── DoubleToLongFunction.html │ │ │ │ ├── DoubleUnaryOperator.html │ │ │ │ ├── Function.html │ │ │ │ ├── IntBinaryOperator.html │ │ │ │ ├── IntConsumer.html │ │ │ │ ├── IntFunction.html │ │ │ │ ├── IntPredicate.html │ │ │ │ ├── IntSupplier.html │ │ │ │ ├── IntToDoubleFunction.html │ │ │ │ ├── IntToLongFunction.html │ │ │ │ ├── IntUnaryOperator.html │ │ │ │ ├── LongBinaryOperator.html │ │ │ │ ├── LongConsumer.html │ │ │ │ ├── LongFunction.html │ │ │ │ ├── LongPredicate.html │ │ │ │ ├── LongSupplier.html │ │ │ │ ├── LongToDoubleFunction.html │ │ │ │ ├── LongToIntFunction.html │ │ │ │ ├── LongUnaryOperator.html │ │ │ │ ├── ObjDoubleConsumer.html │ │ │ │ ├── ObjIntConsumer.html │ │ │ │ ├── ObjLongConsumer.html │ │ │ │ ├── Predicate.html │ │ │ │ ├── Supplier.html │ │ │ │ ├── ToDoubleBiFunction.html │ │ │ │ ├── ToDoubleFunction.html │ │ │ │ ├── ToIntBiFunction.html │ │ │ │ ├── ToIntFunction.html │ │ │ │ ├── ToLongBiFunction.html │ │ │ │ ├── ToLongFunction.html │ │ │ │ └── UnaryOperator.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ ├── package-use.html │ │ │ └── stream │ │ │ ├── BaseStream.html │ │ │ ├── Collector.Characteristics.html │ │ │ ├── Collector.html │ │ │ ├── Collectors.html │ │ │ ├── DoubleStream.Builder.html │ │ │ ├── DoubleStream.DoubleMapMultiConsumer.html │ │ │ ├── DoubleStream.html │ │ │ ├── IntStream.Builder.html │ │ │ ├── IntStream.IntMapMultiConsumer.html │ │ │ ├── IntStream.html │ │ │ ├── LongStream.Builder.html │ │ │ ├── LongStream.LongMapMultiConsumer.html │ │ │ ├── LongStream.html │ │ │ ├── Stream.Builder.html │ │ │ ├── Stream.html │ │ │ ├── StreamSupport.html │ │ │ ├── class-use │ │ │ ├── BaseStream.html │ │ │ ├── Collector.Characteristics.html │ │ │ ├── Collector.html │ │ │ ├── Collectors.html │ │ │ ├── DoubleStream.Builder.html │ │ │ ├── DoubleStream.DoubleMapMultiConsumer.html │ │ │ ├── DoubleStream.html │ │ │ ├── IntStream.Builder.html │ │ │ ├── IntStream.IntMapMultiConsumer.html │ │ │ ├── IntStream.html │ │ │ ├── LongStream.Builder.html │ │ │ ├── LongStream.LongMapMultiConsumer.html │ │ │ ├── LongStream.html │ │ │ ├── Stream.Builder.html │ │ │ ├── Stream.html │ │ │ └── StreamSupport.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ ├── overview-frame.html │ ├── overview-summary.html │ ├── overview-tree.html │ ├── package-list │ ├── script.js │ ├── serialized-form.html │ └── stylesheet.css ├── images │ ├── bg_hr.png │ ├── blacktocat.png │ ├── icon_download.png │ └── sprite_download.png ├── index.html ├── scripts │ └── prettify │ │ ├── prettify.css │ │ ├── prettify.js │ │ └── run_prettify.js └── stylesheets │ ├── pygment_trac.css │ └── stylesheet.css ├── pom.xml ├── proguard-rules.pro └── src ├── alternative └── java9 │ └── util │ └── ImmutableCollections.java └── main └── java ├── java └── util │ └── Random.java └── java9 ├── lang ├── Doubles.java ├── FunctionalInterface.java ├── Integers.java ├── Iterables.java ├── Longs.java └── package-info.java └── util ├── ArrayDequeSpliterator.java ├── ArrayListSpliterator.java ├── ArrayPrefixHelpers.java ├── ArraysArrayListSpliterator.java ├── ArraysParallelSortHelpers.java ├── COWArrayListSpliterator.java ├── COWArraySetSpliterator.java ├── Comparators.java ├── DelegatingSpliterator.java ├── DoubleSummaryStatistics.java ├── DualPivotQuicksort.java ├── HMSpliterators.java ├── ImmutableCollections.java ├── IntSummaryStatistics.java ├── Iterators.java ├── J8Arrays.java ├── KeyValueHolder.java ├── LBDSpliterator.java ├── LBQSpliterator.java ├── LinkedListSpliterator.java ├── Lists.java ├── LongSummaryStatistics.java ├── Maps.java ├── Objects.java ├── Optional.java ├── OptionalDouble.java ├── OptionalInt.java ├── OptionalLong.java ├── PBQueueSpliterator.java ├── PQueueSpliterator.java ├── PrimitiveIterator.java ├── RASpliterator.java ├── RefConsumer.java ├── Sets.java ├── Spliterator.java ├── Spliterators.java ├── SplittableRandom.java ├── StringJoiner.java ├── TimSort.java ├── UnsafeAccess.java ├── VectorSpliterator.java ├── concurrent ├── ConcurrentMaps.java ├── CountedCompleter.java ├── ForkJoinPool.java ├── ForkJoinTask.java ├── ForkJoinWorkerThread.java ├── Mock.java ├── RecursiveAction.java ├── RecursiveTask.java ├── TLRandom.java ├── ThreadLocalRandom.java ├── UnsafeAccess.java └── package-info.java ├── function ├── BiConsumer.java ├── BiFunction.java ├── BiPredicate.java ├── BinaryOperator.java ├── BooleanSupplier.java ├── Consumer.java ├── DoubleBinaryOperator.java ├── DoubleConsumer.java ├── DoubleFunction.java ├── DoublePredicate.java ├── DoubleSupplier.java ├── DoubleToIntFunction.java ├── DoubleToLongFunction.java ├── DoubleUnaryOperator.java ├── Function.java ├── IntBinaryOperator.java ├── IntConsumer.java ├── IntFunction.java ├── IntPredicate.java ├── IntSupplier.java ├── IntToDoubleFunction.java ├── IntToLongFunction.java ├── IntUnaryOperator.java ├── LongBinaryOperator.java ├── LongConsumer.java ├── LongFunction.java ├── LongPredicate.java ├── LongSupplier.java ├── LongToDoubleFunction.java ├── LongToIntFunction.java ├── LongUnaryOperator.java ├── ObjDoubleConsumer.java ├── ObjIntConsumer.java ├── ObjLongConsumer.java ├── Predicate.java ├── Supplier.java ├── ToDoubleBiFunction.java ├── ToDoubleFunction.java ├── ToIntBiFunction.java ├── ToIntFunction.java ├── ToLongBiFunction.java ├── ToLongFunction.java ├── UnaryOperator.java └── package-info.java ├── package-info.java └── stream ├── AbstractPipeline.java ├── AbstractShortCircuitTask.java ├── AbstractSpinedBuffer.java ├── AbstractTask.java ├── BaseStream.java ├── Collector.java ├── Collectors.java ├── DistinctOps.java ├── DoublePipeline.java ├── DoubleStream.java ├── FindOps.java ├── ForEachOps.java ├── IntPipeline.java ├── IntStream.java ├── LongPipeline.java ├── LongStream.java ├── MatchOps.java ├── Node.java ├── Nodes.java ├── PipelineHelper.java ├── ReduceOps.java ├── ReferencePipeline.java ├── Sink.java ├── SliceOps.java ├── SortedOps.java ├── SpinedBuffer.java ├── Stream.java ├── StreamOpFlag.java ├── StreamShape.java ├── StreamSpliterators.java ├── StreamSupport.java ├── Streams.java ├── TerminalOp.java ├── TerminalSink.java ├── WhileOps.java └── package-info.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /upload/ 3 | /.classpath 4 | /.project 5 | /.settings/org.eclipse.core.resources.prefs 6 | /.settings/org.eclipse.jdt.core.prefs 7 | /.settings/org.eclipse.m2e.core.prefs -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Maven Central](https://img.shields.io/maven-central/v/net.sourceforge.streamsupport/android-retrostreams.svg)](http://mvnrepository.com/artifact/net.sourceforge.streamsupport/android-retrostreams) 2 | [![javadoc.io](https://javadoc.io/badge2/net.sourceforge.streamsupport/android-retrostreams/javadoc.svg)](https://javadoc.io/doc/net.sourceforge.streamsupport/android-retrostreams) 3 | 4 | # android-retrostreams 5 | 6 | ![](art/streamsupport-sf.png) 7 | 8 | android-retrostreams is a fork of the [streamsupport library](https://github.com/stefan-zobel/streamsupport) 9 | targeted at Android developers who want to take advantage of Android Studio 3.x D8 / desugar toolchain's 10 | capability to use interface default & static methods across Jar file boundaries. 11 | 12 | Utilizing this feature of desugar, the streamsupport API can be even more aligned with the original 13 | Java 8 / 9 API exposed in the java.util.function and java.util.stream packages. That allows for Android 14 | app's code to be much more in accordance with the standard Java 8 / 9 usage than it is now possible with the 15 | original streamsupport API (which is bound by the restrictions of supporting Java 6). 16 | 17 | With respect to static / default interface methods the android-retrostreams public API should now be 18 | identical to the Java 9 API wherever this is possible (i.e. for all interfaces that have first been 19 | introduced in Java 8). 20 | 21 | Supplemental helper classes, public static methods and so on that served as a replacement for the 22 | default / static interfaces methods in the original streamsupport API are now mostly gone. 23 | E.g., no `j8.u.s.RefStreams` class anymore - all these methods are now in the `j9.u.s.Stream` interface. 24 | 25 | The retrostreams API lives in the packages `java9.util.*` and `java9.lang` respectively. So, it's not possible 26 | to simply import the `java.util.stream` package in your code - you'd rather have to use `java9.util.stream` instead. 27 | While that is fine as long as you have full control over your source code there is the other common scenario of using 28 | a binary 3rd party dependency that has been compiled against the standard Java 8 `java.util.stream` API. In the latter 29 | case bytecode rewriting via [ProGuard](https://github.com/Guardsquare/proguard) might be an option. ProGuard supports 30 | most Java 8 language features and the latest release can also replace the standard Java 8 stream API by the 31 | [streamsupport](https://github.com/stefan-zobel/streamsupport) backport (cf. the Proguard [documentation](https://www.guardsquare.com/en/products/proguard/manual/gradleplugin), especially the section titled "Java 8 stream API support"), 32 | i.e., in this case, switching to the older [streamsupport](https://github.com/stefan-zobel/streamsupport) backport instead 33 | of using android-retrostreams might be the more promising approach. 34 | 35 | The [online Javadoc](https://retrostreams.github.io/android-retrostreams/apidocs/index.html) gives a 36 | picture of the API changes. 37 | 38 | The current stable release of retrostreams is `android-retrostreams-1.7.4`. 39 | 40 | Please give feedback [here](https://github.com/retrostreams/android-retrostreams/issues) if you experience 41 | any problems. 42 | 43 | 44 | ### build.gradle: 45 | 46 | ```gradle 47 | dependencies { 48 | implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.4' 49 | } 50 | ``` 51 | 52 | 53 | ### All-in-One JAR: 54 | Contains android-retrostreams core + retroatomic + retroflow + retrofuture 55 | 56 | ```gradle 57 | dependencies { 58 | implementation 'net.sourceforge.streamsupport:android-retrostreams_all:1.7.4' 59 | } 60 | ``` 61 | 62 | 63 | ### Example usage 64 | 65 | ```java 66 | import java.util.List; 67 | import java9.util.stream.Stream; 68 | import java9.util.stream.StreamSupport; 69 | import static java9.util.stream.Collectors.toList; 70 | 71 | List list = Stream.of(1, 2, 3, 4).collect(toList()); 72 | 73 | List incremented = StreamSupport.stream(list) 74 | .map(i -> i + 1) 75 | .collect(toList()); 76 | ``` 77 | 78 | ### Sibling projects 79 | 80 | You might also have a use for one of `retrostreams'` sibling projects: 81 | 82 | * [android-retrofuture](https://github.com/retrostreams/android-retrofuture) 83 | * [android-retroflow](https://github.com/retrostreams/android-retroflow) 84 | * [android-retroatomic](https://github.com/retrostreams/android-retroatomic) 85 | 86 | 87 | ## LICENSE 88 | 89 | GNU General Public License, version 2, [with the Classpath Exception](https://github.com/retrostreams/android-retrostreams/blob/master/GPL_ClasspathException) (and [CC0 1.0](https://creativecommons.org/publicdomain/zero/1.0/) for JSR-166 derived code) 90 | -------------------------------------------------------------------------------- /art/streamsupport-sf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/art/streamsupport-sf.png -------------------------------------------------------------------------------- /docs/apidocs/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Deprecated API

75 |

Contents

76 |
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/apidocs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | net.sourceforge.streamsupport:android-retrostreams 1.7.4 API 8 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | <noscript> 69 | <div>JavaScript is disabled on your browser.</div> 70 | </noscript> 71 | <h2>Frame Alert</h2> 72 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/apidocs/java9/lang/class-use/Longs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class java9.lang.Longs (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
java9.lang.Longs

75 |
76 |
No usage of java9.lang.Longs
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/apidocs/java9/lang/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | java9.lang (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 |

java9.lang

14 |
15 |

Classes

16 | 22 |

Annotation Types

23 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/apidocs/java9/lang/package-use.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Package java9.lang (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Package
java9.lang

75 |
76 |
No usage of java9.lang
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/apidocs/java9/util/class-use/Maps.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class java9.util.Maps (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
java9.util.Maps

75 |
76 |
No usage of java9.util.Maps
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/apidocs/java9/util/class-use/Sets.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Uses of Class java9.util.Sets (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 23 | 26 | 27 |
28 | 29 | 30 | 31 | 32 | 33 | 34 | 44 |
45 | 72 | 73 |
74 |

Uses of Class
java9.util.Sets

75 |
76 |
No usage of java9.util.Sets
77 | 78 |
79 | 80 | 81 | 82 | 83 | 84 | 85 | 95 |
96 | 123 | 124 |

Copyright © 2021. All rights reserved.

125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/apidocs/java9/util/concurrent/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | java9.util.concurrent (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 |

java9.util.concurrent

14 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/apidocs/java9/util/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | java9.util (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 |

java9.util

14 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/apidocs/java9/util/stream/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | java9.util.stream (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 |

java9.util.stream

14 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /docs/apidocs/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview List (net.sourceforge.streamsupport:android-retrostreams 1.7.4 API) 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |

Packages

16 | 23 |
24 |

 

25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/apidocs/package-list: -------------------------------------------------------------------------------- 1 | java9.lang 2 | java9.util 3 | java9.util.concurrent 4 | java9.util.function 5 | java9.util.stream 6 | -------------------------------------------------------------------------------- /docs/apidocs/script.js: -------------------------------------------------------------------------------- 1 | function show(type) 2 | { 3 | count = 0; 4 | for (var key in methods) { 5 | var row = document.getElementById(key); 6 | if ((methods[key] & type) != 0) { 7 | row.style.display = ''; 8 | row.className = (count++ % 2) ? rowColor : altColor; 9 | } 10 | else 11 | row.style.display = 'none'; 12 | } 13 | updateTabs(type); 14 | } 15 | 16 | function updateTabs(type) 17 | { 18 | for (var value in tabs) { 19 | var sNode = document.getElementById(tabs[value][0]); 20 | var spanNode = sNode.firstChild; 21 | if (value == type) { 22 | sNode.className = activeTableTab; 23 | spanNode.innerHTML = tabs[value][1]; 24 | } 25 | else { 26 | sNode.className = tableTab; 27 | spanNode.innerHTML = "" + tabs[value][1] + ""; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /docs/images/bg_hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/docs/images/bg_hr.png -------------------------------------------------------------------------------- /docs/images/blacktocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/docs/images/blacktocat.png -------------------------------------------------------------------------------- /docs/images/icon_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/docs/images/icon_download.png -------------------------------------------------------------------------------- /docs/images/sprite_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/docs/images/sprite_download.png -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | android-retrostreams : Backport of Java 9 java.util.stream API for Android Studio 3.x D8 / desugar toolchain 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | View on GitHub 21 | 22 |

android-retrostreams

23 |

Backport of Java 9 java.util.stream API
for Android Studio 3.x D8 / desugar toolchain

Forked from streamsupport

24 | 25 |
26 |
27 | 28 | 29 |
30 |
31 | 32 | 33 |

Javadoc online

34 | 35 |

See the online Javadoc for more details about the API

36 | 37 |

Downloads

38 | 39 | 44 | 45 | 46 | 47 |

Dependencies

48 |

No dependencies

49 | 50 | 51 |

License

52 |

android-retrostreams is free to use and licensed under the GPL2, CE
(GNU General Public License, version 2, with the Classpath Exception)

53 | 54 | 55 |

Credits

56 | 57 |

android-retrostreams builds on the code of the streamsupport project

58 | 59 | 63 | 64 | 65 |
66 | 67 |
68 | 69 | 70 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} -------------------------------------------------------------------------------- /docs/stylesheets/pygment_trac.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #f0f3f3; } 3 | .highlight .c { color: #0099FF; font-style: italic } /* Comment */ 4 | .highlight .err { color: #AA0000; background-color: #FFAAAA } /* Error */ 5 | .highlight .k { color: #006699; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #555555 } /* Operator */ 7 | .highlight .cm { color: #0099FF; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #009999 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #0099FF; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #0099FF; font-weight: bold; font-style: italic } /* Comment.Special */ 11 | .highlight .gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #003300; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */ 16 | .highlight .go { color: #AAAAAA } /* Generic.Output */ 17 | .highlight .gp { color: #000099; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #003300; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #99CC66 } /* Generic.Traceback */ 21 | .highlight .kc { color: #006699; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #006699; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #006699; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #006699 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #006699; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #007788; font-weight: bold } /* Keyword.Type */ 27 | .highlight .m { color: #FF6600 } /* Literal.Number */ 28 | .highlight .s { color: #CC3300 } /* Literal.String */ 29 | .highlight .na { color: #330099 } /* Name.Attribute */ 30 | .highlight .nb { color: #336666 } /* Name.Builtin */ 31 | .highlight .nc { color: #00AA88; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #336600 } /* Name.Constant */ 33 | .highlight .nd { color: #9999FF } /* Name.Decorator */ 34 | .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #CC0000; font-weight: bold } /* Name.Exception */ 36 | .highlight .nf { color: #CC00FF } /* Name.Function */ 37 | .highlight .nl { color: #9999FF } /* Name.Label */ 38 | .highlight .nn { color: #00CCFF; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #330099; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #003333 } /* Name.Variable */ 41 | .highlight .ow { color: #000000; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mf { color: #FF6600 } /* Literal.Number.Float */ 44 | .highlight .mh { color: #FF6600 } /* Literal.Number.Hex */ 45 | .highlight .mi { color: #FF6600 } /* Literal.Number.Integer */ 46 | .highlight .mo { color: #FF6600 } /* Literal.Number.Oct */ 47 | .highlight .sb { color: #CC3300 } /* Literal.String.Backtick */ 48 | .highlight .sc { color: #CC3300 } /* Literal.String.Char */ 49 | .highlight .sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ 50 | .highlight .s2 { color: #CC3300 } /* Literal.String.Double */ 51 | .highlight .se { color: #CC3300; font-weight: bold } /* Literal.String.Escape */ 52 | .highlight .sh { color: #CC3300 } /* Literal.String.Heredoc */ 53 | .highlight .si { color: #AA0000 } /* Literal.String.Interpol */ 54 | .highlight .sx { color: #CC3300 } /* Literal.String.Other */ 55 | .highlight .sr { color: #33AAAA } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #CC3300 } /* Literal.String.Single */ 57 | .highlight .ss { color: #FFCC33 } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #336666 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #003333 } /* Name.Variable.Class */ 60 | .highlight .vg { color: #003333 } /* Name.Variable.Global */ 61 | .highlight .vi { color: #003333 } /* Name.Variable.Instance */ 62 | .highlight .il { color: #FF6600 } /* Literal.Number.Integer.Long */ 63 | 64 | .type-csharp .highlight .k { color: #0000FF } 65 | .type-csharp .highlight .kt { color: #0000FF } 66 | .type-csharp .highlight .nf { color: #000000; font-weight: normal } 67 | .type-csharp .highlight .nc { color: #2B91AF } 68 | .type-csharp .highlight .nn { color: #000000 } 69 | .type-csharp .highlight .s { color: #A31515 } 70 | .type-csharp .highlight .sc { color: #A31515 } 71 | -------------------------------------------------------------------------------- /proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add any project specific keep options here: 2 | 3 | #-dontobfuscate 4 | #-dontshrink 5 | 6 | -keep class java9.** { *; } 7 | -keep interface java9.** { *; } 8 | -keep enum java9.** { *; } 9 | 10 | -dontwarn java9.** 11 | -dontwarn org.openjdk.** 12 | 13 | -dontnote java.util.Arrays* 14 | -dontnote java.util.HashMap* 15 | -dontnote java.util.concurrent.LinkedBlockingQueue* 16 | -dontnote java.util.concurrent.LinkedBlockingDeque* 17 | 18 | -------------------------------------------------------------------------------- /src/main/java/java9/lang/Doubles.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/src/main/java/java9/lang/Doubles.java -------------------------------------------------------------------------------- /src/main/java/java9/lang/FunctionalInterface.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/retrostreams/android-retrostreams/d781df5e30fabb395f472ca41cced6e36e895528/src/main/java/java9/lang/FunctionalInterface.java -------------------------------------------------------------------------------- /src/main/java/java9/lang/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | /** 27 | * Provides classes for some of the new static methods that were added in Java 8. 28 | * 29 | *

Value-based Classes

30 | *

31 | * Some classes, such as {@code java9.util.Optional}, are value-based. Instances 32 | * of a value-based class: 33 | * 34 | *

51 | * 52 | * A program may produce unpredictable results if it attempts to distinguish two 53 | * references to equal values of a value-based class, whether directly via 54 | * reference equality or indirectly via an appeal to synchronization, identity 55 | * hashing, serialization, or any other identity-sensitive mechanism. Use of such 56 | * identity-sensitive operations on instances of value-based classes may have 57 | * unpredictable effects and should be avoided. 58 | *

59 | * 60 | * @since 1.8 61 | */ 62 | package java9.lang; 63 | 64 | -------------------------------------------------------------------------------- /src/main/java/java9/util/ArraysArrayListSpliterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util; 26 | 27 | import java.util.List; 28 | 29 | import java9.util.Spliterator; 30 | import java9.util.Spliterators; 31 | 32 | final class ArraysArrayListSpliterator { 33 | 34 | private ArraysArrayListSpliterator() { 35 | } 36 | 37 | static Spliterator spliterator(List list) { 38 | return Spliterators.spliterator(getArray(list), Spliterator.ORDERED); 39 | } 40 | 41 | private static Object[] getArray(List list) { 42 | return (Object[]) U.getObject(list, ARRAY_OFF); 43 | } 44 | 45 | // Unsafe mechanics 46 | private static final sun.misc.Unsafe U = UnsafeAccess.unsafe; 47 | private static final long ARRAY_OFF; 48 | static { 49 | try { 50 | Class aal = Class.forName("java.util.Arrays$ArrayList"); 51 | ARRAY_OFF = U.objectFieldOffset(aal.getDeclaredField("a")); 52 | } catch (Exception e) { 53 | throw new Error(e); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/java9/util/COWArrayListSpliterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util; 26 | 27 | import java.util.concurrent.CopyOnWriteArrayList; 28 | 29 | // Spliterator for java.util.concurrent.CopyOnWriteArrayList 30 | final class COWArrayListSpliterator { 31 | // CVS rev. 1.155 32 | private COWArrayListSpliterator() { 33 | } 34 | 35 | static Spliterator spliterator(CopyOnWriteArrayList list) { 36 | return Spliterators.spliterator(getArray(list), Spliterator.IMMUTABLE 37 | | Spliterator.ORDERED); 38 | } 39 | 40 | static Object[] getArray(CopyOnWriteArrayList list) { 41 | return (Object[]) U.getObject(list, ARRAY_OFF); 42 | } 43 | 44 | // Unsafe mechanics 45 | private static final sun.misc.Unsafe U = UnsafeAccess.unsafe; 46 | private static final long ARRAY_OFF; 47 | static { 48 | ARRAY_OFF = fieldOffset(Spliterators.IS_ANDROID ? "elements" : "array", 49 | true); 50 | } 51 | 52 | static long fieldOffset(String arrayFieldName, boolean recursive) { 53 | try { 54 | return U.objectFieldOffset(CopyOnWriteArrayList.class 55 | .getDeclaredField(arrayFieldName)); 56 | } catch (Exception e) { 57 | if (recursive 58 | && e instanceof NoSuchFieldException 59 | && (Spliterators.IS_ANDROID && !Spliterators.IS_HARMONY_ANDROID)) { 60 | // https://android.googlesource.com/platform/libcore/+/29957558cf0db700bfaae360a80c42dc3871d0e5 61 | return fieldOffset("array", false); 62 | } 63 | throw new Error(e); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/java9/util/COWArraySetSpliterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util; 26 | 27 | import java.util.concurrent.CopyOnWriteArrayList; 28 | import java.util.concurrent.CopyOnWriteArraySet; 29 | 30 | // Spliterator for java.util.concurrent.CopyOnWriteArraySet 31 | final class COWArraySetSpliterator { 32 | // CVS rev. 1.74 33 | private COWArraySetSpliterator() { 34 | } 35 | 36 | static Spliterator spliterator(CopyOnWriteArraySet set) { 37 | Object[] array = COWArrayListSpliterator 38 | .getArray(getCowArrayList(set)); 39 | return Spliterators.spliterator(array, Spliterator.IMMUTABLE 40 | | Spliterator.DISTINCT); 41 | } 42 | 43 | private static CopyOnWriteArrayList getCowArrayList( 44 | CopyOnWriteArraySet set) { 45 | return (CopyOnWriteArrayList) U.getObject(set, COW_ARRAY_OFF); 46 | } 47 | 48 | // Unsafe mechanics 49 | private static final sun.misc.Unsafe U = UnsafeAccess.unsafe; 50 | private static final long COW_ARRAY_OFF; 51 | static { 52 | try { 53 | COW_ARRAY_OFF = U.objectFieldOffset(CopyOnWriteArraySet.class 54 | .getDeclaredField("al")); 55 | } catch (Exception e) { 56 | throw new Error(e); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/java9/util/DelegatingSpliterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Stefan Zobel and released to the 3 | * public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | package java9.util; 7 | 8 | import java.util.Comparator; 9 | 10 | import java9.util.function.Consumer; 11 | 12 | /** 13 | * A j8.u.Spliterator implementation that delegates to a j.u.Spliterator. 14 | * 15 | * @param 16 | * the type of the input to the operation 17 | */ 18 | final class DelegatingSpliterator implements Spliterator { 19 | 20 | private final java.util.Spliterator spliter; 21 | 22 | DelegatingSpliterator(java.util.Spliterator spliterator) { 23 | Objects.requireNonNull(spliterator); 24 | this.spliter = spliterator; 25 | } 26 | 27 | @Override 28 | public boolean tryAdvance(Consumer action) { 29 | return spliter.tryAdvance(new ConsumerDelegate<>(action)); 30 | } 31 | 32 | @Override 33 | public Spliterator trySplit() { 34 | java.util.Spliterator spliterator = spliter.trySplit(); 35 | if (spliterator == null) { 36 | return null; 37 | } 38 | return new DelegatingSpliterator<>(spliterator); 39 | } 40 | 41 | @Override 42 | public long estimateSize() { 43 | return spliter.estimateSize(); 44 | } 45 | 46 | @Override 47 | public int characteristics() { 48 | return spliter.characteristics(); 49 | } 50 | 51 | @Override 52 | public void forEachRemaining(Consumer action) { 53 | spliter.forEachRemaining(new ConsumerDelegate<>(action)); 54 | } 55 | 56 | @Override 57 | public long getExactSizeIfKnown() { 58 | return spliter.getExactSizeIfKnown(); 59 | } 60 | 61 | @Override 62 | public boolean hasCharacteristics(int characteristics) { 63 | return spliter.hasCharacteristics(characteristics); 64 | } 65 | 66 | @Override 67 | public Comparator getComparator() { 68 | return spliter.getComparator(); 69 | } 70 | 71 | /** 72 | * A j.u.f.Consumer implementation that delegates to a j8.u.f.Consumer. 73 | * 74 | * @param 75 | * the type of the input to the operation 76 | */ 77 | private static final class ConsumerDelegate implements 78 | java.util.function.Consumer { 79 | 80 | private final Consumer delegate; 81 | 82 | ConsumerDelegate(Consumer delegate) { 83 | Objects.requireNonNull(delegate); 84 | this.delegate = delegate; 85 | } 86 | 87 | @Override 88 | public void accept(T t) { 89 | delegate.accept(t); 90 | } 91 | 92 | @Override 93 | public java.util.function.Consumer andThen( 94 | java.util.function.Consumer after) { 95 | 96 | Objects.requireNonNull(after); 97 | 98 | return new ConsumerDelegate(delegate.andThen( 99 | new java9.util.function.Consumer() { 100 | @Override 101 | public void accept(T t) { 102 | after.accept(t); 103 | } 104 | })); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/java9/util/KeyValueHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util; 26 | 27 | import java.util.Map; 28 | 29 | /** 30 | * An immutable container for a key and a value, suitable for use 31 | * in creating and populating {@code Map} instances. 32 | * 33 | *

This is a value-based 34 | * class; use of identity-sensitive operations (including reference equality 35 | * ({@code ==}), identity hash code, or synchronization) on instances of 36 | * {@code KeyValueHolder} may have unpredictable results and should be avoided. 37 | * 38 | *

API Note:
39 | * This class is not public. Instances can be created using the 40 | * {@link Maps#entry Map.entry(k, v)} factory method, which is public. 41 | * 42 | *

This class differs from AbstractMap.SimpleImmutableEntry in the following ways: 43 | * it is not serializable, it is final, and its key and value must be non-null. 44 | * 45 | * @param the key type 46 | * @param the value type 47 | * 48 | * @see Maps#ofEntries Maps.ofEntries() 49 | * @since 9 50 | */ 51 | final class KeyValueHolder implements Map.Entry { 52 | final K key; 53 | final V value; 54 | 55 | KeyValueHolder(K k, V v) { 56 | key = Objects.requireNonNull(k); 57 | value = Objects.requireNonNull(v); 58 | } 59 | 60 | /** 61 | * Gets the key from this holder. 62 | * 63 | * @return the key 64 | */ 65 | @Override 66 | public K getKey() { 67 | return key; 68 | } 69 | 70 | /** 71 | * Gets the value from this holder. 72 | * 73 | * @return the value 74 | */ 75 | @Override 76 | public V getValue() { 77 | return value; 78 | } 79 | 80 | /** 81 | * Throws {@link UnsupportedOperationException}. 82 | * 83 | * @param value ignored 84 | * @return never returns normally 85 | */ 86 | @Override 87 | public V setValue(V value) { 88 | throw new UnsupportedOperationException("not supported"); 89 | } 90 | 91 | /** 92 | * Compares the specified object with this entry for equality. 93 | * Returns {@code true} if the given object is also a map entry and 94 | * the two entries' keys and values are equal. Note that key and 95 | * value are non-null, so equals() can be called safely on them. 96 | */ 97 | @Override 98 | public boolean equals(Object o) { 99 | if (!(o instanceof Map.Entry)) 100 | return false; 101 | Map.Entry e = (Map.Entry) o; 102 | return key.equals(e.getKey()) && value.equals(e.getValue()); 103 | } 104 | 105 | /** 106 | * Returns the hash code value for this map entry. The hash code 107 | * is {@code key.hashCode() ^ value.hashCode()}. Note that key and 108 | * value are non-null, so hashCode() can be called safely on them. 109 | */ 110 | @Override 111 | public int hashCode() { 112 | return key.hashCode() ^ value.hashCode(); 113 | } 114 | 115 | /** 116 | * Returns a String representation of this map entry. This 117 | * implementation returns the string representation of this 118 | * entry's key followed by the equals character ("{@code =}") 119 | * followed by the string representation of this entry's value. 120 | * 121 | * @return a String representation of this map entry 122 | */ 123 | @Override 124 | public String toString() { 125 | return key + "=" + value; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/java9/util/PBQueueSpliterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Doug Lea with assistance from members of JCP JSR-166 3 | * Expert Group and released to the public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | /* 7 | * Any changes or additions made by the maintainers of the 8 | * streamsupport (https://github.com/stefan-zobel/streamsupport) 9 | * or retrostreams (https://github.com/retrostreams) libraries are 10 | * also released to the public domain, as explained at 11 | * https://creativecommons.org/publicdomain/zero/1.0/ 12 | */ 13 | package java9.util; 14 | 15 | import java.util.concurrent.PriorityBlockingQueue; 16 | 17 | import java9.util.Spliterator; 18 | import java9.util.function.Consumer; 19 | 20 | /* 21 | * Spliterator for java.util.concurrent.PriorityBlockingQueue. 22 | * Immutable snapshot spliterator that binds to elements "late". 23 | */ 24 | final class PBQueueSpliterator implements Spliterator { 25 | // CVS rev. 1.142 26 | private final PriorityBlockingQueue queue; 27 | private Object[] array; // null until late-bound-initialized 28 | private int index; 29 | private int fence; 30 | 31 | private PBQueueSpliterator(PriorityBlockingQueue queue, 32 | Object[] array, int index, int fence) { 33 | this.queue = queue; 34 | this.array = array; 35 | this.index = index; 36 | this.fence = fence; 37 | } 38 | 39 | static Spliterator spliterator(PriorityBlockingQueue queue) { 40 | return new PBQueueSpliterator(queue, null, 0, -1); 41 | } 42 | 43 | private int getFence() { 44 | if (array == null) 45 | fence = (array = queue.toArray()).length; 46 | return fence; 47 | } 48 | 49 | @Override 50 | public PBQueueSpliterator trySplit() { 51 | int hi = getFence(), lo = index, mid = (lo + hi) >>> 1; 52 | return (lo >= mid) ? null : 53 | new PBQueueSpliterator(queue, array, lo, index = mid); 54 | } 55 | 56 | @Override 57 | @SuppressWarnings("unchecked") 58 | public void forEachRemaining(Consumer action) { 59 | Objects.requireNonNull(action); 60 | int hi = getFence(), lo = index; 61 | Object[] es = array; 62 | index = hi; // ensure exhaustion 63 | for (int i = lo; i < hi; i++) 64 | action.accept((E) es[i]); 65 | } 66 | 67 | @Override 68 | @SuppressWarnings("unchecked") 69 | public boolean tryAdvance(Consumer action) { 70 | Objects.requireNonNull(action); 71 | if (getFence() > index && index >= 0) { 72 | action.accept((E) array[index++]); 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | @Override 79 | public long estimateSize() { return getFence() - index; } 80 | 81 | @Override 82 | public int characteristics() { 83 | return (Spliterator.NONNULL | 84 | Spliterator.SIZED | 85 | Spliterator.SUBSIZED); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/java9/util/RefConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Stefan Zobel and released to the 3 | * public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | package java9.util; 7 | 8 | import java9.util.function.Consumer; 9 | import java9.util.function.DoubleConsumer; 10 | import java9.util.function.IntConsumer; 11 | import java9.util.function.LongConsumer; 12 | 13 | final class RefConsumer { 14 | 15 | static IntConsumer toIntConsumer(Consumer action) { 16 | return (IntConsumer) action::accept; 17 | } 18 | 19 | static LongConsumer toLongConsumer(Consumer action) { 20 | return (LongConsumer) action::accept; 21 | } 22 | 23 | static DoubleConsumer toDoubleConsumer(Consumer action) { 24 | return (DoubleConsumer) action::accept; 25 | } 26 | 27 | private RefConsumer() { 28 | // no instances 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/java9/util/UnsafeAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Stefan Zobel and released to the 3 | * public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | package java9.util; 7 | 8 | import java.lang.reflect.Field; 9 | 10 | import sun.misc.Unsafe; 11 | 12 | class UnsafeAccess { 13 | 14 | static final Unsafe unsafe; 15 | 16 | static { 17 | try { 18 | Field field = null; 19 | try { 20 | field = Unsafe.class.getDeclaredField("theUnsafe"); 21 | } catch (NoSuchFieldException oldAndroid) { 22 | field = Unsafe.class.getDeclaredField("THE_ONE"); 23 | } 24 | field.setAccessible(true); 25 | unsafe = (Unsafe) field.get(null); 26 | } catch (Exception e) { 27 | throw new Error(e); 28 | } 29 | } 30 | 31 | private UnsafeAccess() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/java9/util/concurrent/Mock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Stefan Zobel and released to the 3 | * public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | package java9.util.concurrent; 7 | 8 | /** 9 | * A mock class for the {@code ForkJoinPool.MemBar} emulation of the 10 | * {@code sun.misc.Unsafe fence()} methods 11 | */ 12 | final class Mock { 13 | 14 | private volatile int v; 15 | 16 | Mock() { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/java9/util/concurrent/RecursiveTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Doug Lea with assistance from members of JCP JSR-166 3 | * Expert Group and released to the public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | /* 7 | * Any changes or additions made by the maintainers of the 8 | * streamsupport (https://github.com/stefan-zobel/streamsupport) 9 | * or retrostreams (https://github.com/retrostreams) libraries are 10 | * also released to the public domain, as explained at 11 | * https://creativecommons.org/publicdomain/zero/1.0/ 12 | */ 13 | package java9.util.concurrent; 14 | 15 | /** 16 | * A recursive result-bearing {@link ForkJoinTask}. 17 | * 18 | *

For a classic example, here is a task computing Fibonacci numbers: 19 | * 20 | *

 {@code
21 |  * class Fibonacci extends RecursiveTask {
22 |  *   final int n;
23 |  *   Fibonacci(int n) { this.n = n; }
24 |  *   protected Integer compute() {
25 |  *     if (n <= 1)
26 |  *       return n;
27 |  *     Fibonacci f1 = new Fibonacci(n - 1);
28 |  *     f1.fork();
29 |  *     Fibonacci f2 = new Fibonacci(n - 2);
30 |  *     return f2.compute() + f1.join();
31 |  *   }
32 |  * }}
33 | * 34 | * However, besides being a dumb way to compute Fibonacci functions 35 | * (there is a simple fast linear algorithm that you'd use in 36 | * practice), this is likely to perform poorly because the smallest 37 | * subtasks are too small to be worthwhile splitting up. Instead, as 38 | * is the case for nearly all fork/join applications, you'd pick some 39 | * minimum granularity size (for example 10 here) for which you always 40 | * sequentially solve rather than subdividing. 41 | * 42 | * @since 1.7 43 | * @author Doug Lea 44 | */ 45 | public abstract class RecursiveTask extends ForkJoinTask { 46 | // CVS rev. 1.11 47 | private static final long serialVersionUID = 5232453952276485270L; 48 | 49 | /** 50 | * Constructor for subclasses to call. 51 | */ 52 | public RecursiveTask() {} 53 | 54 | /** 55 | * The result of the computation. 56 | */ 57 | V result; 58 | 59 | /** 60 | * The main computation performed by this task. 61 | * @return the result of the computation 62 | */ 63 | protected abstract V compute(); 64 | 65 | public final V getRawResult() { 66 | return result; 67 | } 68 | 69 | protected final void setRawResult(V value) { 70 | result = value; 71 | } 72 | 73 | /** 74 | * Implements execution conventions for RecursiveTask. 75 | */ 76 | protected final boolean exec() { 77 | result = compute(); 78 | return true; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/java9/util/concurrent/UnsafeAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Stefan Zobel and released to the 3 | * public domain, as explained at 4 | * http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | package java9.util.concurrent; 7 | 8 | import java.lang.reflect.Field; 9 | 10 | import sun.misc.Unsafe; 11 | 12 | class UnsafeAccess { 13 | 14 | static final Unsafe unsafe; 15 | 16 | static { 17 | try { 18 | Field field = null; 19 | try { 20 | field = Unsafe.class.getDeclaredField("theUnsafe"); 21 | } catch (NoSuchFieldException oldAndroid) { 22 | field = Unsafe.class.getDeclaredField("THE_ONE"); 23 | } 24 | field.setAccessible(true); 25 | unsafe = (Unsafe) field.get(null); 26 | } catch (Exception e) { 27 | throw new Error(e); 28 | } 29 | } 30 | 31 | private UnsafeAccess() { 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/java9/util/concurrent/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | /** 27 | * The Java 7 and Java 8 utility classes commonly used in concurrent programming. 28 | * 29 | *

Memory Consistency Properties

30 | * 31 | * 32 | * Chapter 17 of 33 | * The Java™ Language Specification defines the 34 | * happens-before relation on memory operations such as reads and 35 | * writes of shared variables. The results of a write by one thread are 36 | * guaranteed to be visible to a read by another thread only if the write 37 | * operation happens-before the read operation. The 38 | * {@code synchronized} and {@code volatile} constructs, as well as the 39 | * {@code Thread.start()} and {@code Thread.join()} methods, can form 40 | * happens-before relationships. In particular: 41 | * 42 | *
    43 | *
  • Each action in a thread happens-before every action in that 44 | * thread that comes later in the program's order. 45 | * 46 | *
  • An unlock ({@code synchronized} block or method exit) of a 47 | * monitor happens-before every subsequent lock ({@code synchronized} 48 | * block or method entry) of that same monitor. And because 49 | * the happens-before relation is transitive, all actions 50 | * of a thread prior to unlocking happen-before all actions 51 | * subsequent to any thread locking that monitor. 52 | * 53 | *
  • A write to a {@code volatile} field happens-before every 54 | * subsequent read of that same field. Writes and reads of 55 | * {@code volatile} fields have similar memory consistency effects 56 | * as entering and exiting monitors, but do not entail 57 | * mutual exclusion locking. 58 | * 59 | *
  • A call to {@code start} on a thread happens-before any 60 | * action in the started thread. 61 | * 62 | *
  • All actions in a thread happen-before any other thread 63 | * successfully returns from a {@code join} on that thread. 64 | * 65 | *
66 | * 67 | * @since 1.8 68 | */ 69 | package java9.util.concurrent; 70 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/BiConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Consumer; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation that accepts two input arguments and returns no 32 | * result. This is the two-arity specialization of {@link Consumer}. 33 | * Unlike most other functional interfaces, {@code BiConsumer} is expected 34 | * to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(Object, Object)}. 38 | * 39 | * @param the type of the first argument to the operation 40 | * @param the type of the second argument to the operation 41 | * 42 | * @see Consumer 43 | * @since 1.8 44 | */ 45 | public interface BiConsumer { 46 | 47 | /** 48 | * Performs this operation on the given arguments. 49 | * 50 | * @param t the first input argument 51 | * @param u the second input argument 52 | */ 53 | void accept(T t, U u); 54 | 55 | /** 56 | * Returns a composed {@code BiConsumer} that performs, in sequence, this 57 | * operation followed by the {@code after} operation. If performing either 58 | * operation throws an exception, it is relayed to the caller of the 59 | * composed operation. If performing this operation throws an exception, 60 | * the {@code after} operation will not be performed. 61 | * 62 | * @param after the operation to perform after this operation 63 | * @return a composed {@code BiConsumer} that performs in sequence this 64 | * operation followed by the {@code after} operation 65 | * @throws NullPointerException if {@code after} is null 66 | */ 67 | default BiConsumer andThen(BiConsumer after) { 68 | Objects.requireNonNull(after); 69 | 70 | return (l, r) -> { 71 | accept(l, r); 72 | after.accept(l, r); 73 | }; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/BiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents a function that accepts two arguments and produces a result. 32 | * This is the two-arity specialization of {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #apply(Object, Object)}. 36 | * 37 | * @param the type of the first argument to the function 38 | * @param the type of the second argument to the function 39 | * @param the type of the result of the function 40 | * 41 | * @see Function 42 | * @since 1.8 43 | */ 44 | public interface BiFunction { 45 | 46 | /** 47 | * Applies this function to the given arguments. 48 | * 49 | * @param t the first function argument 50 | * @param u the second function argument 51 | * @return the function result 52 | */ 53 | R apply(T t, U u); 54 | 55 | /** 56 | * Returns a composed function that first applies this function to 57 | * its input, and then applies the {@code after} function to the result. 58 | * If evaluation of either function throws an exception, it is relayed to 59 | * the caller of the composed function. 60 | * 61 | * @param the type of output of the {@code after} function, and of the 62 | * composed function 63 | * @param after the function to apply after this function is applied 64 | * @return a composed function that first applies this function and then 65 | * applies the {@code after} function 66 | * @throws NullPointerException if after is null 67 | */ 68 | default BiFunction andThen(Function after) { 69 | Objects.requireNonNull(after); 70 | return (T t, U u) -> after.apply(apply(t, u)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/BiPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Predicate; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents a predicate (boolean-valued function) of two arguments. This is 32 | * the two-arity specialization of {@link Predicate}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #test(Object, Object)}. 36 | * 37 | * @param the type of the first argument to the predicate 38 | * @param the type of the second argument the predicate 39 | * 40 | * @see Predicate 41 | * @since 1.8 42 | */ 43 | public interface BiPredicate { 44 | 45 | /** 46 | * Evaluates this predicate on the given arguments. 47 | * 48 | * @param t the first input argument 49 | * @param u the second input argument 50 | * @return {@code true} if the input arguments match the predicate, 51 | * otherwise {@code false} 52 | */ 53 | boolean test(T t, U u); 54 | 55 | /** 56 | * Returns a composed predicate that represents a short-circuiting logical 57 | * AND of this predicate and another. When evaluating the composed 58 | * predicate, if this predicate is {@code false}, then the {@code other} 59 | * predicate is not evaluated. 60 | * 61 | *

Any exceptions thrown during evaluation of either predicate are relayed 62 | * to the caller; if evaluation of this predicate throws an exception, the 63 | * {@code other} predicate will not be evaluated. 64 | * 65 | * @param other a predicate that will be logically-ANDed with this 66 | * predicate 67 | * @return a composed predicate that represents the short-circuiting logical 68 | * AND of this predicate and the {@code other} predicate 69 | * @throws NullPointerException if other is null 70 | */ 71 | default BiPredicate and(BiPredicate other) { 72 | Objects.requireNonNull(other); 73 | return (T t, U u) -> test(t, u) && other.test(t, u); 74 | } 75 | 76 | /** 77 | * Returns a predicate that represents the logical negation of this 78 | * predicate. 79 | * 80 | * @return a predicate that represents the logical negation of this 81 | * predicate 82 | */ 83 | default BiPredicate negate() { 84 | return (T t, U u) -> !test(t, u); 85 | } 86 | 87 | /** 88 | * Returns a composed predicate that represents a short-circuiting logical 89 | * OR of this predicate and another. When evaluating the composed 90 | * predicate, if this predicate is {@code true}, then the {@code other} 91 | * predicate is not evaluated. 92 | * 93 | *

Any exceptions thrown during evaluation of either predicate are relayed 94 | * to the caller; if evaluation of this predicate throws an exception, the 95 | * {@code other} predicate will not be evaluated. 96 | * 97 | * @param other a predicate that will be logically-ORed with this 98 | * predicate 99 | * @return a composed predicate that represents the short-circuiting logical 100 | * OR of this predicate and the {@code other} predicate 101 | * @throws NullPointerException if other is null 102 | */ 103 | default BiPredicate or(BiPredicate other) { 104 | Objects.requireNonNull(other); 105 | return (T t, U u) -> test(t, u) || other.test(t, u); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/BinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java.util.Comparator; 28 | import java9.util.Objects; 29 | import java9.util.function.BiFunction; 30 | import java9.util.function.UnaryOperator; 31 | 32 | /** 33 | * Represents an operation upon two operands of the same type, producing a result 34 | * of the same type as the operands. This is a specialization of 35 | * {@link BiFunction} for the case where the operands and the result are all of 36 | * the same type. 37 | * 38 | *

This is a functional interface 39 | * whose functional method is {@link #apply(Object, Object)}. 40 | * 41 | * @param the type of the operands and result of the operator 42 | * 43 | * @see BiFunction 44 | * @see UnaryOperator 45 | * @since 1.8 46 | */ 47 | public interface BinaryOperator extends BiFunction { 48 | /** 49 | * Returns a {@link BinaryOperator} which returns the lesser of two elements 50 | * according to the specified {@code Comparator}. 51 | * 52 | * @param the type of the input arguments of the comparator 53 | * @param comparator a {@code Comparator} for comparing the two values 54 | * @return a {@code BinaryOperator} which returns the lesser of its operands, 55 | * according to the supplied {@code Comparator} 56 | * @throws NullPointerException if the argument is null 57 | */ 58 | public static BinaryOperator minBy(Comparator comparator) { 59 | Objects.requireNonNull(comparator); 60 | return (a, b) -> comparator.compare(a, b) <= 0 ? a : b; 61 | } 62 | 63 | /** 64 | * Returns a {@link BinaryOperator} which returns the greater of two elements 65 | * according to the specified {@code Comparator}. 66 | * 67 | * @param the type of the input arguments of the comparator 68 | * @param comparator a {@code Comparator} for comparing the two values 69 | * @return a {@code BinaryOperator} which returns the greater of its operands, 70 | * according to the supplied {@code Comparator} 71 | * @throws NullPointerException if the argument is null 72 | */ 73 | public static BinaryOperator maxBy(Comparator comparator) { 74 | Objects.requireNonNull(comparator); 75 | return (a, b) -> comparator.compare(a, b) >= 0 ? a : b; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/BooleanSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Supplier; 28 | 29 | 30 | /** 31 | * Represents a supplier of {@code boolean}-valued results. This is the 32 | * {@code boolean}-producing primitive specialization of {@link Supplier}. 33 | * 34 | *

There is no requirement that a new or distinct result be returned each 35 | * time the supplier is invoked. 36 | * 37 | *

This is a functional interface 38 | * whose functional method is {@link #getAsBoolean()}. 39 | * 40 | * @see Supplier 41 | * @since 1.8 42 | */ 43 | public interface BooleanSupplier { 44 | 45 | /** 46 | * Gets a result. 47 | * 48 | * @return a result 49 | */ 50 | boolean getAsBoolean(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/Consumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.Objects; 28 | 29 | /** 30 | * Represents an operation that accepts a single input argument and returns no 31 | * result. Unlike most other functional interfaces, {@code Consumer} is expected 32 | * to operate via side-effects. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #accept(Object)}. 36 | * 37 | * @param the type of the input to the operation 38 | * 39 | * @since 1.8 40 | */ 41 | public interface Consumer { 42 | 43 | /** 44 | * Performs this operation on the given argument. 45 | * 46 | * @param t the input argument 47 | */ 48 | void accept(T t); 49 | 50 | /** 51 | * Returns a composed {@code Consumer} that performs, in sequence, this 52 | * operation followed by the {@code after} operation. If performing either 53 | * operation throws an exception, it is relayed to the caller of the 54 | * composed operation. If performing this operation throws an exception, 55 | * the {@code after} operation will not be performed. 56 | * 57 | * @param after the operation to perform after this operation 58 | * @return a composed {@code Consumer} that performs in sequence this 59 | * operation followed by the {@code after} operation 60 | * @throws NullPointerException if {@code after} is null 61 | */ 62 | default Consumer andThen(Consumer after) { 63 | Objects.requireNonNull(after); 64 | return (T t) -> { accept(t); after.accept(t); }; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BinaryOperator; 28 | import java9.util.function.DoubleUnaryOperator; 29 | 30 | /** 31 | * Represents an operation upon two {@code double}-valued operands and producing a 32 | * {@code double}-valued result. This is the primitive type specialization of 33 | * {@link BinaryOperator} for {@code double}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsDouble(double, double)}. 37 | * 38 | * @see BinaryOperator 39 | * @see DoubleUnaryOperator 40 | * @since 1.8 41 | */ 42 | public interface DoubleBinaryOperator { 43 | /** 44 | * Applies this operator to the given operands. 45 | * 46 | * @param left the first operand 47 | * @param right the second operand 48 | * @return the operator result 49 | */ 50 | double applyAsDouble(double left, double right); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Consumer; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation that accepts a single {@code double}-valued argument and 32 | * returns no result. This is the primitive type specialization of 33 | * {@link Consumer} for {@code double}. Unlike most other functional interfaces, 34 | * {@code DoubleConsumer} is expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(double)}. 38 | * 39 | * @see Consumer 40 | * @since 1.8 41 | */ 42 | public interface DoubleConsumer { 43 | 44 | /** 45 | * Performs this operation on the given argument. 46 | * 47 | * @param value the input argument 48 | */ 49 | void accept(double value); 50 | 51 | /** 52 | * Returns a composed {@code DoubleConsumer} that performs, in sequence, this 53 | * operation followed by the {@code after} operation. If performing either 54 | * operation throws an exception, it is relayed to the caller of the 55 | * composed operation. If performing this operation throws an exception, 56 | * the {@code after} operation will not be performed. 57 | * 58 | * @param after the operation to perform after this operation 59 | * @return a composed {@code DoubleConsumer} that performs in sequence this 60 | * operation followed by the {@code after} operation 61 | * @throws NullPointerException if {@code after} is null 62 | */ 63 | default DoubleConsumer andThen(DoubleConsumer after) { 64 | Objects.requireNonNull(after); 65 | return (double t) -> { accept(t); after.accept(t); }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a double-valued argument and produces a 31 | * result. This is the {@code double}-consuming primitive specialization for 32 | * {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #apply(double)}. 36 | * 37 | * @param the type of the result of the function 38 | * 39 | * @see Function 40 | * @since 1.8 41 | */ 42 | public interface DoubleFunction { 43 | 44 | /** 45 | * Applies this function to the given argument. 46 | * 47 | * @param value the function argument 48 | * @return the function result 49 | */ 50 | R apply(double value); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoublePredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Predicate; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents a predicate (boolean-valued function) of one {@code double}-valued 32 | * argument. This is the {@code double}-consuming primitive type specialization 33 | * of {@link Predicate}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #test(double)}. 37 | * 38 | * @see Predicate 39 | * @since 1.8 40 | */ 41 | public interface DoublePredicate { 42 | 43 | /** 44 | * Evaluates this predicate on the given argument. 45 | * 46 | * @param value the input argument 47 | * @return {@code true} if the input argument matches the predicate, 48 | * otherwise {@code false} 49 | */ 50 | boolean test(double value); 51 | 52 | /** 53 | * Returns a composed predicate that represents a short-circuiting logical 54 | * AND of this predicate and another. When evaluating the composed 55 | * predicate, if this predicate is {@code false}, then the {@code other} 56 | * predicate is not evaluated. 57 | * 58 | *

Any exceptions thrown during evaluation of either predicate are relayed 59 | * to the caller; if evaluation of this predicate throws an exception, the 60 | * {@code other} predicate will not be evaluated. 61 | * 62 | * @param other a predicate that will be logically-ANDed with this 63 | * predicate 64 | * @return a composed predicate that represents the short-circuiting logical 65 | * AND of this predicate and the {@code other} predicate 66 | * @throws NullPointerException if other is null 67 | */ 68 | default DoublePredicate and(DoublePredicate other) { 69 | Objects.requireNonNull(other); 70 | return (value) -> test(value) && other.test(value); 71 | } 72 | 73 | /** 74 | * Returns a predicate that represents the logical negation of this 75 | * predicate. 76 | * 77 | * @return a predicate that represents the logical negation of this 78 | * predicate 79 | */ 80 | default DoublePredicate negate() { 81 | return (value) -> !test(value); 82 | } 83 | 84 | /** 85 | * Returns a composed predicate that represents a short-circuiting logical 86 | * OR of this predicate and another. When evaluating the composed 87 | * predicate, if this predicate is {@code true}, then the {@code other} 88 | * predicate is not evaluated. 89 | * 90 | *

Any exceptions thrown during evaluation of either predicate are relayed 91 | * to the caller; if evaluation of this predicate throws an exception, the 92 | * {@code other} predicate will not be evaluated. 93 | * 94 | * @param other a predicate that will be logically-ORed with this 95 | * predicate 96 | * @return a composed predicate that represents the short-circuiting logical 97 | * OR of this predicate and the {@code other} predicate 98 | * @throws NullPointerException if other is null 99 | */ 100 | default DoublePredicate or(DoublePredicate other) { 101 | Objects.requireNonNull(other); 102 | return (value) -> test(value) || other.test(value); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Supplier; 28 | 29 | /** 30 | * Represents a supplier of {@code double}-valued results. This is the 31 | * {@code double}-producing primitive specialization of {@link Supplier}. 32 | * 33 | *

There is no requirement that a distinct result be returned each 34 | * time the supplier is invoked. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #getAsDouble()}. 38 | * 39 | * @see Supplier 40 | * @since 1.8 41 | */ 42 | public interface DoubleSupplier { 43 | 44 | /** 45 | * Gets a result. 46 | * 47 | * @return a result 48 | */ 49 | double getAsDouble(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a double-valued argument and produces an 31 | * int-valued result. This is the {@code double}-to-{@code int} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsInt(double)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface DoubleToIntFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | int applyAsInt(double value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a double-valued argument and produces a 31 | * long-valued result. This is the {@code double}-to-{@code long} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsLong(double)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface DoubleToLongFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | long applyAsLong(double value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/DoubleUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.UnaryOperator; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation on a single {@code double}-valued operand that produces 32 | * a {@code double}-valued result. This is the primitive type specialization of 33 | * {@link UnaryOperator} for {@code double}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsDouble(double)}. 37 | * 38 | * @see UnaryOperator 39 | * @since 1.8 40 | */ 41 | public interface DoubleUnaryOperator { 42 | 43 | /** 44 | * Applies this operator to the given operand. 45 | * 46 | * @param operand the operand 47 | * @return the operator result 48 | */ 49 | double applyAsDouble(double operand); 50 | 51 | /** 52 | * Returns a composed operator that first applies the {@code before} 53 | * operator to its input, and then applies this operator to the result. 54 | * If evaluation of either operator throws an exception, it is relayed to 55 | * the caller of the composed operator. 56 | * 57 | * @param before the operator to apply before this operator is applied 58 | * @return a composed operator that first applies the {@code before} 59 | * operator and then applies this operator 60 | * @throws NullPointerException if before is null 61 | * 62 | * @see #andThen(DoubleUnaryOperator) 63 | */ 64 | default DoubleUnaryOperator compose(DoubleUnaryOperator before) { 65 | Objects.requireNonNull(before); 66 | return (double v) -> applyAsDouble(before.applyAsDouble(v)); 67 | } 68 | 69 | /** 70 | * Returns a composed operator that first applies this operator to 71 | * its input, and then applies the {@code after} operator to the result. 72 | * If evaluation of either operator throws an exception, it is relayed to 73 | * the caller of the composed operator. 74 | * 75 | * @param after the operator to apply after this operator is applied 76 | * @return a composed operator that first applies this operator and then 77 | * applies the {@code after} operator 78 | * @throws NullPointerException if after is null 79 | * 80 | * @see #compose(DoubleUnaryOperator) 81 | */ 82 | default DoubleUnaryOperator andThen(DoubleUnaryOperator after) { 83 | Objects.requireNonNull(after); 84 | return (double t) -> after.applyAsDouble(applyAsDouble(t)); 85 | } 86 | 87 | /** 88 | * Returns a unary operator that always returns its input argument. 89 | * 90 | * @return a unary operator that always returns its input argument 91 | */ 92 | static DoubleUnaryOperator identity() { 93 | return t -> t; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/Function.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.Objects; 28 | 29 | /** 30 | * Represents a function that accepts one argument and produces a result. 31 | * 32 | *

This is a functional interface 33 | * whose functional method is {@link #apply(Object)}. 34 | * 35 | * @param the type of the input to the function 36 | * @param the type of the result of the function 37 | * 38 | * @since 1.8 39 | */ 40 | public interface Function { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param t the function argument 46 | * @return the function result 47 | */ 48 | R apply(T t); 49 | 50 | /** 51 | * Returns a composed function that first applies the {@code before} 52 | * function to its input, and then applies this function to the result. 53 | * If evaluation of either function throws an exception, it is relayed to 54 | * the caller of the composed function. 55 | * 56 | * @param the type of input to the {@code before} function, and to the 57 | * composed function 58 | * @param before the function to apply before this function is applied 59 | * @return a composed function that first applies the {@code before} 60 | * function and then applies this function 61 | * @throws NullPointerException if before is null 62 | * 63 | * @see #andThen(Function) 64 | */ 65 | default Function compose(Function before) { 66 | Objects.requireNonNull(before); 67 | return (V v) -> apply(before.apply(v)); 68 | } 69 | 70 | /** 71 | * Returns a composed function that first applies this function to 72 | * its input, and then applies the {@code after} function to the result. 73 | * If evaluation of either function throws an exception, it is relayed to 74 | * the caller of the composed function. 75 | * 76 | * @param the type of output of the {@code after} function, and of the 77 | * composed function 78 | * @param after the function to apply after this function is applied 79 | * @return a composed function that first applies this function and then 80 | * applies the {@code after} function 81 | * @throws NullPointerException if after is null 82 | * 83 | * @see #compose(Function) 84 | */ 85 | default Function andThen(Function after) { 86 | Objects.requireNonNull(after); 87 | return (T t) -> after.apply(apply(t)); 88 | } 89 | 90 | /** 91 | * Returns a function that always returns its input argument. 92 | * 93 | * @param the type of the input and output objects to the function 94 | * @return a function that always returns its input argument 95 | */ 96 | static Function identity() { 97 | return t -> t; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BinaryOperator; 28 | import java9.util.function.IntUnaryOperator; 29 | 30 | /** 31 | * Represents an operation upon two {@code int}-valued operands and producing an 32 | * {@code int}-valued result. This is the primitive type specialization of 33 | * {@link BinaryOperator} for {@code int}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsInt(int, int)}. 37 | * 38 | * @see BinaryOperator 39 | * @see IntUnaryOperator 40 | * @since 1.8 41 | */ 42 | public interface IntBinaryOperator { 43 | 44 | /** 45 | * Applies this operator to the given operands. 46 | * 47 | * @param left the first operand 48 | * @param right the second operand 49 | * @return the operator result 50 | */ 51 | int applyAsInt(int left, int right); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Consumer; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation that accepts a single {@code int}-valued argument and 32 | * returns no result. This is the primitive type specialization of 33 | * {@link Consumer} for {@code int}. Unlike most other functional interfaces, 34 | * {@code IntConsumer} is expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(int)}. 38 | * 39 | * @see Consumer 40 | * @since 1.8 41 | */ 42 | public interface IntConsumer { 43 | 44 | /** 45 | * Performs this operation on the given argument. 46 | * 47 | * @param value the input argument 48 | */ 49 | void accept(int value); 50 | 51 | /** 52 | * Returns a composed {@code IntConsumer} that performs, in sequence, this 53 | * operation followed by the {@code after} operation. If performing either 54 | * operation throws an exception, it is relayed to the caller of the 55 | * composed operation. If performing this operation throws an exception, 56 | * the {@code after} operation will not be performed. 57 | * 58 | * @param after the operation to perform after this operation 59 | * @return a composed {@code IntConsumer} that performs in sequence this 60 | * operation followed by the {@code after} operation 61 | * @throws NullPointerException if {@code after} is null 62 | */ 63 | default IntConsumer andThen(IntConsumer after) { 64 | Objects.requireNonNull(after); 65 | return (int t) -> { accept(t); after.accept(t); }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts an int-valued argument and produces a 31 | * result. This is the {@code int}-consuming primitive specialization for 32 | * {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #apply(int)}. 36 | * 37 | * @param the type of the result of the function 38 | * 39 | * @see Function 40 | * @since 1.8 41 | */ 42 | public interface IntFunction { 43 | 44 | /** 45 | * Applies this function to the given argument. 46 | * 47 | * @param value the function argument 48 | * @return the function result 49 | */ 50 | R apply(int value); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Predicate; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents a predicate (boolean-valued function) of one {@code int}-valued 32 | * argument. This is the {@code int}-consuming primitive type specialization of 33 | * {@link Predicate}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #test(int)}. 37 | * 38 | * @see Predicate 39 | * @since 1.8 40 | */ 41 | public interface IntPredicate { 42 | 43 | /** 44 | * Evaluates this predicate on the given argument. 45 | * 46 | * @param value the input argument 47 | * @return {@code true} if the input argument matches the predicate, 48 | * otherwise {@code false} 49 | */ 50 | boolean test(int value); 51 | 52 | /** 53 | * Returns a composed predicate that represents a short-circuiting logical 54 | * AND of this predicate and another. When evaluating the composed 55 | * predicate, if this predicate is {@code false}, then the {@code other} 56 | * predicate is not evaluated. 57 | * 58 | *

Any exceptions thrown during evaluation of either predicate are relayed 59 | * to the caller; if evaluation of this predicate throws an exception, the 60 | * {@code other} predicate will not be evaluated. 61 | * 62 | * @param other a predicate that will be logically-ANDed with this 63 | * predicate 64 | * @return a composed predicate that represents the short-circuiting logical 65 | * AND of this predicate and the {@code other} predicate 66 | * @throws NullPointerException if other is null 67 | */ 68 | default IntPredicate and(IntPredicate other) { 69 | Objects.requireNonNull(other); 70 | return (value) -> test(value) && other.test(value); 71 | } 72 | 73 | /** 74 | * Returns a predicate that represents the logical negation of this 75 | * predicate. 76 | * 77 | * @return a predicate that represents the logical negation of this 78 | * predicate 79 | */ 80 | default IntPredicate negate() { 81 | return (value) -> !test(value); 82 | } 83 | 84 | /** 85 | * Returns a composed predicate that represents a short-circuiting logical 86 | * OR of this predicate and another. When evaluating the composed 87 | * predicate, if this predicate is {@code true}, then the {@code other} 88 | * predicate is not evaluated. 89 | * 90 | *

Any exceptions thrown during evaluation of either predicate are relayed 91 | * to the caller; if evaluation of this predicate throws an exception, the 92 | * {@code other} predicate will not be evaluated. 93 | * 94 | * @param other a predicate that will be logically-ORed with this 95 | * predicate 96 | * @return a composed predicate that represents the short-circuiting logical 97 | * OR of this predicate and the {@code other} predicate 98 | * @throws NullPointerException if other is null 99 | */ 100 | default IntPredicate or(IntPredicate other) { 101 | Objects.requireNonNull(other); 102 | return (value) -> test(value) || other.test(value); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Supplier; 28 | 29 | /** 30 | * Represents a supplier of {@code int}-valued results. This is the 31 | * {@code int}-producing primitive specialization of {@link Supplier}. 32 | * 33 | *

There is no requirement that a distinct result be returned each 34 | * time the supplier is invoked. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #getAsInt()}. 38 | * 39 | * @see Supplier 40 | * @since 1.8 41 | */ 42 | public interface IntSupplier { 43 | 44 | /** 45 | * Gets a result. 46 | * 47 | * @return a result 48 | */ 49 | int getAsInt(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts an int-valued argument and produces a 31 | * double-valued result. This is the {@code int}-to-{@code double} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsDouble(int)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface IntToDoubleFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | double applyAsDouble(int value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts an int-valued argument and produces a 31 | * long-valued result. This is the {@code int}-to-{@code long} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsLong(int)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface IntToLongFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | long applyAsLong(int value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/IntUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.UnaryOperator; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation on a single {@code int}-valued operand that produces 32 | * an {@code int}-valued result. This is the primitive type specialization of 33 | * {@link UnaryOperator} for {@code int}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsInt(int)}. 37 | * 38 | * @see UnaryOperator 39 | * @since 1.8 40 | */ 41 | public interface IntUnaryOperator { 42 | 43 | /** 44 | * Applies this operator to the given operand. 45 | * 46 | * @param operand the operand 47 | * @return the operator result 48 | */ 49 | int applyAsInt(int operand); 50 | 51 | /** 52 | * Returns a composed operator that first applies the {@code before} 53 | * operator to its input, and then applies this operator to the result. 54 | * If evaluation of either operator throws an exception, it is relayed to 55 | * the caller of the composed operator. 56 | * 57 | * @param before the operator to apply before this operator is applied 58 | * @return a composed operator that first applies the {@code before} 59 | * operator and then applies this operator 60 | * @throws NullPointerException if before is null 61 | * 62 | * @see #andThen(IntUnaryOperator) 63 | */ 64 | default IntUnaryOperator compose(IntUnaryOperator before) { 65 | Objects.requireNonNull(before); 66 | return (int v) -> applyAsInt(before.applyAsInt(v)); 67 | } 68 | 69 | /** 70 | * Returns a composed operator that first applies this operator to 71 | * its input, and then applies the {@code after} operator to the result. 72 | * If evaluation of either operator throws an exception, it is relayed to 73 | * the caller of the composed operator. 74 | * 75 | * @param after the operator to apply after this operator is applied 76 | * @return a composed operator that first applies this operator and then 77 | * applies the {@code after} operator 78 | * @throws NullPointerException if after is null 79 | * 80 | * @see #compose(IntUnaryOperator) 81 | */ 82 | default IntUnaryOperator andThen(IntUnaryOperator after) { 83 | Objects.requireNonNull(after); 84 | return (int t) -> after.applyAsInt(applyAsInt(t)); 85 | } 86 | 87 | /** 88 | * Returns a unary operator that always returns its input argument. 89 | * 90 | * @return a unary operator that always returns its input argument 91 | */ 92 | static IntUnaryOperator identity() { 93 | return t -> t; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongBinaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BinaryOperator; 28 | import java9.util.function.LongUnaryOperator; 29 | 30 | /** 31 | * Represents an operation upon two {@code long}-valued operands and producing a 32 | * {@code long}-valued result. This is the primitive type specialization of 33 | * {@link BinaryOperator} for {@code long}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsLong(long, long)}. 37 | * 38 | * @see BinaryOperator 39 | * @see LongUnaryOperator 40 | * @since 1.8 41 | */ 42 | public interface LongBinaryOperator { 43 | 44 | /** 45 | * Applies this operator to the given operands. 46 | * 47 | * @param left the first operand 48 | * @param right the second operand 49 | * @return the operator result 50 | */ 51 | long applyAsLong(long left, long right); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Consumer; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation that accepts a single {@code long}-valued argument and 32 | * returns no result. This is the primitive type specialization of 33 | * {@link Consumer} for {@code long}. Unlike most other functional interfaces, 34 | * {@code LongConsumer} is expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(long)}. 38 | * 39 | * @see Consumer 40 | * @since 1.8 41 | */ 42 | public interface LongConsumer { 43 | 44 | /** 45 | * Performs this operation on the given argument. 46 | * 47 | * @param value the input argument 48 | */ 49 | void accept(long value); 50 | 51 | /** 52 | * Returns a composed {@code LongConsumer} that performs, in sequence, this 53 | * operation followed by the {@code after} operation. If performing either 54 | * operation throws an exception, it is relayed to the caller of the 55 | * composed operation. If performing this operation throws an exception, 56 | * the {@code after} operation will not be performed. 57 | * 58 | * @param after the operation to perform after this operation 59 | * @return a composed {@code LongConsumer} that performs in sequence this 60 | * operation followed by the {@code after} operation 61 | * @throws NullPointerException if {@code after} is null 62 | */ 63 | default LongConsumer andThen(LongConsumer after) { 64 | Objects.requireNonNull(after); 65 | return (long t) -> { accept(t); after.accept(t); }; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a long-valued argument and produces a 31 | * result. This is the {@code long}-consuming primitive specialization for 32 | * {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #apply(long)}. 36 | * 37 | * @param the type of the result of the function 38 | * 39 | * @see Function 40 | * @since 1.8 41 | */ 42 | public interface LongFunction { 43 | 44 | /** 45 | * Applies this function to the given argument. 46 | * 47 | * @param value the function argument 48 | * @return the function result 49 | */ 50 | R apply(long value); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Predicate; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents a predicate (boolean-valued function) of one {@code long}-valued 32 | * argument. This is the {@code long}-consuming primitive type specialization of 33 | * {@link Predicate}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #test(long)}. 37 | * 38 | * @see Predicate 39 | * @since 1.8 40 | */ 41 | public interface LongPredicate { 42 | 43 | /** 44 | * Evaluates this predicate on the given argument. 45 | * 46 | * @param value the input argument 47 | * @return {@code true} if the input argument matches the predicate, 48 | * otherwise {@code false} 49 | */ 50 | boolean test(long value); 51 | 52 | /** 53 | * Returns a composed predicate that represents a short-circuiting logical 54 | * AND of this predicate and another. When evaluating the composed 55 | * predicate, if this predicate is {@code false}, then the {@code other} 56 | * predicate is not evaluated. 57 | * 58 | *

Any exceptions thrown during evaluation of either predicate are relayed 59 | * to the caller; if evaluation of this predicate throws an exception, the 60 | * {@code other} predicate will not be evaluated. 61 | * 62 | * @param other a predicate that will be logically-ANDed with this 63 | * predicate 64 | * @return a composed predicate that represents the short-circuiting logical 65 | * AND of this predicate and the {@code other} predicate 66 | * @throws NullPointerException if other is null 67 | */ 68 | default LongPredicate and(LongPredicate other) { 69 | Objects.requireNonNull(other); 70 | return (value) -> test(value) && other.test(value); 71 | } 72 | 73 | /** 74 | * Returns a predicate that represents the logical negation of this 75 | * predicate. 76 | * 77 | * @return a predicate that represents the logical negation of this 78 | * predicate 79 | */ 80 | default LongPredicate negate() { 81 | return (value) -> !test(value); 82 | } 83 | 84 | /** 85 | * Returns a composed predicate that represents a short-circuiting logical 86 | * OR of this predicate and another. When evaluating the composed 87 | * predicate, if this predicate is {@code true}, then the {@code other} 88 | * predicate is not evaluated. 89 | * 90 | *

Any exceptions thrown during evaluation of either predicate are relayed 91 | * to the caller; if evaluation of this predicate throws an exception, the 92 | * {@code other} predicate will not be evaluated. 93 | * 94 | * @param other a predicate that will be logically-ORed with this 95 | * predicate 96 | * @return a composed predicate that represents the short-circuiting logical 97 | * OR of this predicate and the {@code other} predicate 98 | * @throws NullPointerException if other is null 99 | */ 100 | default LongPredicate or(LongPredicate other) { 101 | Objects.requireNonNull(other); 102 | return (value) -> test(value) || other.test(value); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Supplier; 28 | 29 | /** 30 | * Represents a supplier of {@code long}-valued results. This is the 31 | * {@code long}-producing primitive specialization of {@link Supplier}. 32 | * 33 | *

There is no requirement that a distinct result be returned each 34 | * time the supplier is invoked. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #getAsLong()}. 38 | * 39 | * @see Supplier 40 | * @since 1.8 41 | */ 42 | public interface LongSupplier { 43 | 44 | /** 45 | * Gets a result. 46 | * 47 | * @return a result 48 | */ 49 | long getAsLong(); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a long-valued argument and produces a 31 | * double-valued result. This is the {@code long}-to-{@code double} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsDouble(long)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface LongToDoubleFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | double applyAsDouble(long value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that accepts a long-valued argument and produces an 31 | * int-valued result. This is the {@code long}-to-{@code int} primitive 32 | * specialization for {@link Function}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsInt(long)}. 36 | * 37 | * @see Function 38 | * @since 1.8 39 | */ 40 | public interface LongToIntFunction { 41 | 42 | /** 43 | * Applies this function to the given argument. 44 | * 45 | * @param value the function argument 46 | * @return the function result 47 | */ 48 | int applyAsInt(long value); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/LongUnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.UnaryOperator; 28 | import java9.util.Objects; 29 | 30 | /** 31 | * Represents an operation on a single {@code long}-valued operand that produces 32 | * a {@code long}-valued result. This is the primitive type specialization of 33 | * {@link UnaryOperator} for {@code long}. 34 | * 35 | *

This is a functional interface 36 | * whose functional method is {@link #applyAsLong(long)}. 37 | * 38 | * @see UnaryOperator 39 | * @since 1.8 40 | */ 41 | public interface LongUnaryOperator { 42 | 43 | /** 44 | * Applies this operator to the given operand. 45 | * 46 | * @param operand the operand 47 | * @return the operator result 48 | */ 49 | long applyAsLong(long operand); 50 | 51 | /** 52 | * Returns a composed operator that first applies the {@code before} 53 | * operator to its input, and then applies this operator to the result. 54 | * If evaluation of either operator throws an exception, it is relayed to 55 | * the caller of the composed operator. 56 | * 57 | * @param before the operator to apply before this operator is applied 58 | * @return a composed operator that first applies the {@code before} 59 | * operator and then applies this operator 60 | * @throws NullPointerException if before is null 61 | * 62 | * @see #andThen(LongUnaryOperator) 63 | */ 64 | default LongUnaryOperator compose(LongUnaryOperator before) { 65 | Objects.requireNonNull(before); 66 | return (long v) -> applyAsLong(before.applyAsLong(v)); 67 | } 68 | 69 | /** 70 | * Returns a composed operator that first applies this operator to 71 | * its input, and then applies the {@code after} operator to the result. 72 | * If evaluation of either operator throws an exception, it is relayed to 73 | * the caller of the composed operator. 74 | * 75 | * @param after the operator to apply after this operator is applied 76 | * @return a composed operator that first applies this operator and then 77 | * applies the {@code after} operator 78 | * @throws NullPointerException if after is null 79 | * 80 | * @see #compose(LongUnaryOperator) 81 | */ 82 | default LongUnaryOperator andThen(LongUnaryOperator after) { 83 | Objects.requireNonNull(after); 84 | return (long t) -> after.applyAsLong(applyAsLong(t)); 85 | } 86 | 87 | /** 88 | * Returns a unary operator that always returns its input argument. 89 | * 90 | * @return a unary operator that always returns its input argument 91 | */ 92 | static LongUnaryOperator identity() { 93 | return t -> t; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ObjDoubleConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiConsumer; 28 | 29 | /** 30 | * Represents an operation that accepts an object-valued and a 31 | * {@code double}-valued argument, and returns no result. This is the 32 | * {@code (reference, double)} specialization of {@link BiConsumer}. 33 | * Unlike most other functional interfaces, {@code ObjDoubleConsumer} is 34 | * expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(Object, double)}. 38 | * 39 | * @param the type of the object argument to the operation 40 | * 41 | * @see BiConsumer 42 | * @since 1.8 43 | */ 44 | public interface ObjDoubleConsumer { 45 | 46 | /** 47 | * Performs this operation on the given arguments. 48 | * 49 | * @param t the first input argument 50 | * @param value the second input argument 51 | */ 52 | void accept(T t, double value); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ObjIntConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiConsumer; 28 | 29 | /** 30 | * Represents an operation that accepts an object-valued and a 31 | * {@code int}-valued argument, and returns no result. This is the 32 | * {@code (reference, int)} specialization of {@link BiConsumer}. 33 | * Unlike most other functional interfaces, {@code ObjIntConsumer} is 34 | * expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(Object, int)}. 38 | * 39 | * @param the type of the object argument to the operation 40 | * 41 | * @see BiConsumer 42 | * @since 1.8 43 | */ 44 | public interface ObjIntConsumer { 45 | 46 | /** 47 | * Performs this operation on the given arguments. 48 | * 49 | * @param t the first input argument 50 | * @param value the second input argument 51 | */ 52 | void accept(T t, int value); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ObjLongConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiConsumer; 28 | 29 | /** 30 | * Represents an operation that accepts an object-valued and a 31 | * {@code long}-valued argument, and returns no result. This is the 32 | * {@code (reference, long)} specialization of {@link BiConsumer}. 33 | * Unlike most other functional interfaces, {@code ObjLongConsumer} is 34 | * expected to operate via side-effects. 35 | * 36 | *

This is a functional interface 37 | * whose functional method is {@link #accept(Object, long)}. 38 | * 39 | * @param the type of the object argument to the operation 40 | * 41 | * @see BiConsumer 42 | * @since 1.8 43 | */ 44 | public interface ObjLongConsumer { 45 | 46 | /** 47 | * Performs this operation on the given arguments. 48 | * 49 | * @param t the first input argument 50 | * @param value the second input argument 51 | */ 52 | void accept(T t, long value); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/Supplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | /** 28 | * Represents a supplier of results. 29 | * 30 | *

There is no requirement that a new or distinct result be returned each 31 | * time the supplier is invoked. 32 | * 33 | *

This is a functional interface 34 | * whose functional method is {@link #get()}. 35 | * 36 | * @param the type of results supplied by this supplier 37 | * 38 | * @since 1.8 39 | */ 40 | public interface Supplier { 41 | 42 | /** 43 | * Gets a result. 44 | * 45 | * @return a result 46 | */ 47 | T get(); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToDoubleBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiFunction; 28 | 29 | /** 30 | * Represents a function that accepts two arguments and produces a double-valued 31 | * result. This is the {@code double}-producing primitive specialization for 32 | * {@link BiFunction}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsDouble(Object, Object)}. 36 | * 37 | * @param the type of the first argument to the function 38 | * @param the type of the second argument to the function 39 | * 40 | * @see BiFunction 41 | * @since 1.8 42 | */ 43 | public interface ToDoubleBiFunction { 44 | 45 | /** 46 | * Applies this function to the given arguments. 47 | * 48 | * @param t the first function argument 49 | * @param u the second function argument 50 | * @return the function result 51 | */ 52 | double applyAsDouble(T t, U u); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToDoubleFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that produces a double-valued result. This is the 31 | * {@code double}-producing primitive specialization for {@link Function}. 32 | * 33 | *

This is a functional interface 34 | * whose functional method is {@link #applyAsDouble(Object)}. 35 | * 36 | * @param the type of the input to the function 37 | * 38 | * @see Function 39 | * @since 1.8 40 | */ 41 | public interface ToDoubleFunction { 42 | 43 | /** 44 | * Applies this function to the given argument. 45 | * 46 | * @param value the function argument 47 | * @return the function result 48 | */ 49 | double applyAsDouble(T value); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToIntBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiFunction; 28 | 29 | /** 30 | * Represents a function that accepts two arguments and produces an int-valued 31 | * result. This is the {@code int}-producing primitive specialization for 32 | * {@link BiFunction}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsInt(Object, Object)}. 36 | * 37 | * @param the type of the first argument to the function 38 | * @param the type of the second argument to the function 39 | * 40 | * @see BiFunction 41 | * @since 1.8 42 | */ 43 | public interface ToIntBiFunction { 44 | 45 | /** 46 | * Applies this function to the given arguments. 47 | * 48 | * @param t the first function argument 49 | * @param u the second function argument 50 | * @return the function result 51 | */ 52 | int applyAsInt(T t, U u); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToIntFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that produces an int-valued result. This is the 31 | * {@code int}-producing primitive specialization for {@link Function}. 32 | * 33 | *

This is a functional interface 34 | * whose functional method is {@link #applyAsInt(Object)}. 35 | * 36 | * @param the type of the input to the function 37 | * 38 | * @see Function 39 | * @since 1.8 40 | */ 41 | public interface ToIntFunction { 42 | 43 | /** 44 | * Applies this function to the given argument. 45 | * 46 | * @param value the function argument 47 | * @return the function result 48 | */ 49 | int applyAsInt(T value); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToLongBiFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.BiFunction; 28 | 29 | /** 30 | * Represents a function that accepts two arguments and produces a long-valued 31 | * result. This is the {@code long}-producing primitive specialization for 32 | * {@link BiFunction}. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #applyAsLong(Object, Object)}. 36 | * 37 | * @param the type of the first argument to the function 38 | * @param the type of the second argument to the function 39 | * 40 | * @see BiFunction 41 | * @since 1.8 42 | */ 43 | public interface ToLongBiFunction { 44 | 45 | /** 46 | * Applies this function to the given arguments. 47 | * 48 | * @param t the first function argument 49 | * @param u the second function argument 50 | * @return the function result 51 | */ 52 | long applyAsLong(T t, U u); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/ToLongFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents a function that produces a long-valued result. This is the 31 | * {@code long}-producing primitive specialization for {@link Function}. 32 | * 33 | *

This is a functional interface 34 | * whose functional method is {@link #applyAsLong(Object)}. 35 | * 36 | * @param the type of the input to the function 37 | * 38 | * @see Function 39 | * @since 1.8 40 | */ 41 | public interface ToLongFunction { 42 | 43 | /** 44 | * Applies this function to the given argument. 45 | * 46 | * @param value the function argument 47 | * @return the function result 48 | */ 49 | long applyAsLong(T value); 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/java9/util/function/UnaryOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.function; 26 | 27 | import java9.util.function.Function; 28 | 29 | /** 30 | * Represents an operation on a single operand that produces a result of the 31 | * same type as its operand. This is a specialization of {@code Function} for 32 | * the case where the operand and result are of the same type. 33 | * 34 | *

This is a functional interface 35 | * whose functional method is {@link #apply(Object)}. 36 | * 37 | * @param the type of the operand and result of the operator 38 | * 39 | * @see Function 40 | * @since 1.8 41 | */ 42 | public interface UnaryOperator extends Function { 43 | 44 | /** 45 | * Returns a unary operator that always returns its input argument. 46 | * 47 | * @param the type of the input and output of the operator 48 | * @return a unary operator that always returns its input argument 49 | */ 50 | static UnaryOperator identity() { 51 | return t -> t; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | 26 | /** 27 | * Provides some of the new {@code java.util} classes and implementations of 28 | * static and default interface methods added in Java 8 and, in addition, the 29 | * JEP 269: Convenience Factory 30 | * Methods for Collections that were introduced in Java 9. 31 | * 32 | *

Unmodifiable collections

33 | *

34 | * An unmodifiable collection is a collection, all of whose mutator 35 | * methods are specified to throw {@code UnsupportedOperationException}. Such a 36 | * collection thus cannot be modified by calling any methods on it. For a 37 | * collection to be properly unmodifiable, any view collections derived from it 38 | * must also be unmodifiable. For example, if a List is unmodifiable, the List 39 | * returned by {@link java.util.List#subList List.subList} is also unmodifiable. 40 | * 41 | *

42 | * An unmodifiable collection is not necessarily immutable. If the contained 43 | * elements are mutable, the entire collection is clearly mutable, even though 44 | * it might be unmodifiable. For example, consider two unmodifiable lists 45 | * containing mutable elements. The result of calling 46 | * {@code list1.equals(list2)} might differ from one call to the next if the 47 | * elements had been mutated, even though both lists are unmodifiable. However, 48 | * if an unmodifiable collection contains all immutable elements, it can be 49 | * considered effectively immutable. 50 | * 51 | * @since 1.8 52 | */ 53 | package java9.util; 54 | -------------------------------------------------------------------------------- /src/main/java/java9/util/stream/AbstractSpinedBuffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.stream; 26 | 27 | /** 28 | * Base class for a data structure for gathering elements into a buffer and then 29 | * iterating them. Maintains an array of increasingly sized arrays, so there is 30 | * no copying cost associated with growing the data structure. 31 | * @since 1.8 32 | */ 33 | abstract class AbstractSpinedBuffer { 34 | /** 35 | * Minimum power-of-two for the first chunk. 36 | */ 37 | public static final int MIN_CHUNK_POWER = 4; 38 | 39 | /** 40 | * Minimum size for the first chunk. 41 | */ 42 | public static final int MIN_CHUNK_SIZE = 1 << MIN_CHUNK_POWER; 43 | 44 | /** 45 | * Max power-of-two for chunks. 46 | */ 47 | public static final int MAX_CHUNK_POWER = 30; 48 | 49 | /** 50 | * Minimum array size for array-of-chunks. 51 | */ 52 | public static final int MIN_SPINE_SIZE = 8; 53 | 54 | 55 | /** 56 | * log2 of the size of the first chunk. 57 | */ 58 | protected final int initialChunkPower; 59 | 60 | /** 61 | * Index of the *next* element to write; may point into, or just outside of, 62 | * the current chunk. 63 | */ 64 | protected int elementIndex; 65 | 66 | /** 67 | * Index of the *current* chunk in the spine array, if the spine array is 68 | * non-null. 69 | */ 70 | protected int spineIndex; 71 | 72 | /** 73 | * Count of elements in all prior chunks. 74 | */ 75 | protected long[] priorElementCount; 76 | 77 | /** 78 | * Construct with an initial capacity of 16. 79 | */ 80 | protected AbstractSpinedBuffer() { 81 | this.initialChunkPower = MIN_CHUNK_POWER; 82 | } 83 | 84 | /** 85 | * Construct with a specified initial capacity. 86 | * 87 | * @param initialCapacity The minimum expected number of elements 88 | */ 89 | protected AbstractSpinedBuffer(int initialCapacity) { 90 | if (initialCapacity < 0) 91 | throw new IllegalArgumentException("Illegal Capacity: "+ initialCapacity); 92 | 93 | this.initialChunkPower = Math.max(MIN_CHUNK_POWER, 94 | Integer.SIZE - Integer.numberOfLeadingZeros(initialCapacity - 1)); 95 | } 96 | 97 | /** 98 | * Is the buffer currently empty? 99 | */ 100 | public boolean isEmpty() { 101 | return (spineIndex == 0) && (elementIndex == 0); 102 | } 103 | 104 | /** 105 | * How many elements are currently in the buffer? 106 | */ 107 | public long count() { 108 | return (spineIndex == 0) 109 | ? elementIndex 110 | : priorElementCount[spineIndex] + elementIndex; 111 | } 112 | 113 | /** 114 | * How big should the nth chunk be? 115 | */ 116 | protected int chunkSize(int n) { 117 | int power = (n == 0 || n == 1) 118 | ? initialChunkPower 119 | : Math.min(initialChunkPower + n - 1, AbstractSpinedBuffer.MAX_CHUNK_POWER); 120 | return 1 << power; 121 | } 122 | 123 | /** 124 | * Remove all data from the buffer 125 | */ 126 | public abstract void clear(); 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/java9/util/stream/StreamShape.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.stream; 26 | 27 | import java9.util.stream.BaseStream; 28 | 29 | /** 30 | * An enum describing the known shape specializations for stream abstractions. 31 | * Each will correspond to a specific subinterface of {@link BaseStream} 32 | * (e.g., {@code REFERENCE} corresponds to {@code Stream}, {@code INT_VALUE} 33 | * corresponds to {@code IntStream}). Each may also correspond to 34 | * specializations of value-handling abstractions such as {@code Spliterator}, 35 | * {@code Consumer}, etc. 36 | * 37 | *

API Note:
38 | * This enum is used by implementations to determine compatibility between 39 | * streams and operations (i.e., if the output shape of a stream is compatible 40 | * with the input shape of the next operation). 41 | * 42 | *

Some APIs require you to specify both a generic type and a stream shape 43 | * for input or output elements, such as {@link TerminalOp} which has both 44 | * generic type parameters for its input types, and a getter for the 45 | * input shape. When representing primitive streams in this way, the 46 | * generic type parameter should correspond to the wrapper type for that 47 | * primitive type. 48 | * 49 | * @since 1.8 50 | */ 51 | enum StreamShape { 52 | /** 53 | * The shape specialization corresponding to {@code Stream} and elements 54 | * that are object references. 55 | */ 56 | REFERENCE, 57 | /** 58 | * The shape specialization corresponding to {@code IntStream} and elements 59 | * that are {@code int} values. 60 | */ 61 | INT_VALUE, 62 | /** 63 | * The shape specialization corresponding to {@code LongStream} and elements 64 | * that are {@code long} values. 65 | */ 66 | LONG_VALUE, 67 | /** 68 | * The shape specialization corresponding to {@code DoubleStream} and 69 | * elements that are {@code double} values. 70 | */ 71 | DOUBLE_VALUE 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/java9/util/stream/TerminalOp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.stream; 26 | 27 | import java9.util.Spliterator; 28 | 29 | /** 30 | * An operation in a stream pipeline that takes a stream as input and produces 31 | * a result or side-effect. A {@code TerminalOp} has an input type and stream 32 | * shape, and a result type. A {@code TerminalOp} also has a set of 33 | * operation flags that describes how the operation processes elements 34 | * of the stream (such as short-circuiting or respecting encounter order; see 35 | * {@link StreamOpFlag}). 36 | * 37 | *

A {@code TerminalOp} must provide a sequential and parallel implementation 38 | * of the operation relative to a given stream source and set of intermediate 39 | * operations. 40 | * 41 | * @param the type of input elements 42 | * @param the type of the result 43 | * @since 1.8 44 | */ 45 | interface TerminalOp { 46 | /** 47 | * Gets the shape of the input type of this operation. 48 | * 49 | *

Implementation Requirements:
The default returns {@code StreamShape.REFERENCE}. 50 | * 51 | * @return StreamShape of the input type of this operation 52 | */ 53 | default StreamShape inputShape() { return StreamShape.REFERENCE; } 54 | 55 | /** 56 | * Gets the stream flags of the operation. Terminal operations may set a 57 | * limited subset of the stream flags defined in {@link StreamOpFlag}, and 58 | * these flags are combined with the previously combined stream and 59 | * intermediate operation flags for the pipeline. 60 | * 61 | *

Implementation Requirements:
The default implementation returns zero. 62 | * 63 | * @return the stream flags for this operation 64 | * @see StreamOpFlag 65 | */ 66 | default int getOpFlags() { return 0; } 67 | 68 | /** 69 | * Performs a parallel evaluation of the operation using the specified 70 | * {@code PipelineHelper}, which describes the upstream intermediate 71 | * operations. 72 | * 73 | *

Implementation Requirements:
The default performs a sequential evaluation of the operation 74 | * using the specified {@code PipelineHelper}. 75 | * 76 | * @param helper the pipeline helper 77 | * @param spliterator the source spliterator 78 | * @return the result of the evaluation 79 | */ 80 | default R evaluateParallel(PipelineHelper helper, 81 | Spliterator spliterator) { 82 | return evaluateSequential(helper, spliterator); 83 | } 84 | 85 | /** 86 | * Performs a sequential evaluation of the operation using the specified 87 | * {@code PipelineHelper}, which describes the upstream intermediate 88 | * operations. 89 | * 90 | * @param helper the pipeline helper 91 | * @param spliterator the source spliterator 92 | * @return the result of the evaluation 93 | */ 94 | R evaluateSequential(PipelineHelper helper, 95 | Spliterator spliterator); 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/java9/util/stream/TerminalSink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Oracle designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Oracle in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 | * or visit www.oracle.com if you need additional information or have any 23 | * questions. 24 | */ 25 | package java9.util.stream; 26 | 27 | import java9.util.function.Supplier; 28 | 29 | /** 30 | * A {@link Sink} which accumulates state as elements are accepted, and allows 31 | * a result to be retrieved after the computation is finished. 32 | * 33 | * @param the type of elements to be accepted 34 | * @param the type of the result 35 | * 36 | * @since 1.8 37 | */ 38 | interface TerminalSink extends Sink, Supplier { } 39 | --------------------------------------------------------------------------------