-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
17
ADDITIONAL SYSTEM INFORMATION :
Win10x64, JDK-17ea21
A DESCRIPTION OF THE PROBLEM :
The java.util.Collection Interface has the two Methods java.util.Collection.stream() and java.util.Collection.parallelStream. But the Iterable Interface is missing these two methods. Is ther any reason?
For example - the stream/parallelStream() method could be added as default methods to the Iterable Interface.
----
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Main {
public static void main(String[] args) {
final List<String> list = List.of("43", "44", "42", "41");
System.out.println("colStream: " + colStream(list).orElse("not found"));
System.out.println("colParallelStream: " + colParallelStream(list).orElse("not found"));
System.out.println("iterStream: " + iterStream(list).orElse("not found"));
System.out.println("iterParallelStream: " + iterParallelStream(list).orElse("not found"));
}
private final static Optional<String> colStream(final Collection<String> col) {
// from java.util.Collection
// as return StreamSupport.stream(spliterator(), false);
return col.stream()// from java.util.Collection
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> colParallelStream(final Collection<String> col) {
// from java.util.Collection
// as return StreamSupport.stream(spliterator(), true);
return col.parallelStream()//
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> iterStream(final Iterable<String> iterable) {
// Iterable is missing .stream() but why not
return stream(iterable) //
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> iterParallelStream(final Iterable<String> iterable) {
// Iterable is missing .parallelStream() but why not
return parallelStream(iterable) //
.filter("42"::equals)//
.findAny();
}
public static <E> Stream<E> stream(final Iterable<E> iterable)
{
// Iterable is missing .stream() but why not?
return StreamSupport.stream(iterable.spliterator(), false);
}
public static <E> Stream<E> parallelStream(final Iterable<E> iterable)
{
// Iterable is missing .stream() but why not?
return StreamSupport.stream(iterable.spliterator(), true);
}
}
Win10x64, JDK-17ea21
A DESCRIPTION OF THE PROBLEM :
The java.util.Collection Interface has the two Methods java.util.Collection.stream() and java.util.Collection.parallelStream. But the Iterable Interface is missing these two methods. Is ther any reason?
For example - the stream/parallelStream() method could be added as default methods to the Iterable Interface.
----
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class Main {
public static void main(String[] args) {
final List<String> list = List.of("43", "44", "42", "41");
System.out.println("colStream: " + colStream(list).orElse("not found"));
System.out.println("colParallelStream: " + colParallelStream(list).orElse("not found"));
System.out.println("iterStream: " + iterStream(list).orElse("not found"));
System.out.println("iterParallelStream: " + iterParallelStream(list).orElse("not found"));
}
private final static Optional<String> colStream(final Collection<String> col) {
// from java.util.Collection
// as return StreamSupport.stream(spliterator(), false);
return col.stream()// from java.util.Collection
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> colParallelStream(final Collection<String> col) {
// from java.util.Collection
// as return StreamSupport.stream(spliterator(), true);
return col.parallelStream()//
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> iterStream(final Iterable<String> iterable) {
// Iterable is missing .stream() but why not
return stream(iterable) //
.filter("42"::equals)//
.findAny();
}
private final static Optional<String> iterParallelStream(final Iterable<String> iterable) {
// Iterable is missing .parallelStream() but why not
return parallelStream(iterable) //
.filter("42"::equals)//
.findAny();
}
public static <E> Stream<E> stream(final Iterable<E> iterable)
{
// Iterable is missing .stream() but why not?
return StreamSupport.stream(iterable.spliterator(), false);
}
public static <E> Stream<E> parallelStream(final Iterable<E> iterable)
{
// Iterable is missing .stream() but why not?
return StreamSupport.stream(iterable.spliterator(), true);
}
}
- duplicates
-
JDK-8272137 Make Iterable classes streamable
-
- Closed
-
- relates to
-
JDK-8272137 Make Iterable classes streamable
-
- Closed
-