Add missing #(stream|parallelStream|spliterator) in Collections
Bug: 27692239
Bug: 27605529
Change-Id: I10c20ff4a20e0ad1c2769c275de7dffaa7ba9543
diff --git a/ojluni/src/main/java/java/util/Collection.java b/ojluni/src/main/java/java/util/Collection.java
index d3542d9..09f10e6 100755
--- a/ojluni/src/main/java/java/util/Collection.java
+++ b/ojluni/src/main/java/java/util/Collection.java
@@ -494,7 +494,6 @@
*/
int hashCode();
- // TODO: Restore links to #stream and #parallelStream.
/**
* Creates a {@link Spliterator} over the elements in this collection.
*
@@ -505,20 +504,20 @@
*
* <p>The default implementation should be overridden by subclasses that
* can return a more efficient spliterator. In order to
- * preserve expected laziness behavior for the {@code stream} and
- * {@code parallelStream()}} methods, spliterators should either have the
+ * preserve expected laziness behavior for the {@link #stream()} and
+ * {@link #parallelStream()}} methods, spliterators should either have the
* characteristic of {@code IMMUTABLE} or {@code CONCURRENT}, or be
* <em><a href="Spliterator.html#binding">late-binding</a></em>.
* If none of these is practical, the overriding class should describe the
* spliterator's documented policy of binding and structural interference,
- * and should override the {@code stream} and {@code parallelStream}
+ * and should override the {@link #stream()} and {@link #parallelStream()}
* methods to create streams using a {@code Supplier} of the spliterator,
* as in:
* <pre>{@code
* Stream<E> s = StreamSupport.stream(() -> spliterator(), spliteratorCharacteristics)
* }</pre>
* <p>These requirements ensure that streams produced by the
- * {@code stream} and {@code parallelStream} methods will reflect the
+ * {@link #stream()} and {@link #parallelStream()} methods will reflect the
* contents of the collection as of initiation of the terminal stream
* operation.
*
diff --git a/ojluni/src/main/java/java/util/Collections.java b/ojluni/src/main/java/java/util/Collections.java
index 9912283..7e12f38 100755
--- a/ojluni/src/main/java/java/util/Collections.java
+++ b/ojluni/src/main/java/java/util/Collections.java
@@ -34,6 +34,9 @@
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Predicate;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
/**
* This class consists exclusively of static methods that operate on or return
@@ -1155,6 +1158,16 @@
public Spliterator<E> spliterator() {
return (Spliterator<E>)c.spliterator();
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Stream<E> stream() {
+ return (Stream<E>)c.stream();
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public Stream<E> parallelStream() {
+ return (Stream<E>)c.parallelStream();
+ }
}
/**
@@ -1544,6 +1557,16 @@
(Spliterator<Map.Entry<K, V>>) c.spliterator());
}
+ @Override
+ public Stream<Entry<K,V>> stream() {
+ return StreamSupport.stream(spliterator(), false);
+ }
+
+ @Override
+ public Stream<Entry<K,V>> parallelStream() {
+ return StreamSupport.stream(spliterator(), true);
+ }
+
public Iterator<Map.Entry<K,V>> iterator() {
return new Iterator<Map.Entry<K,V>>() {
private final Iterator<? extends Map.Entry<? extends K, ? extends V>> i = c.iterator();
@@ -1824,7 +1847,14 @@
public Spliterator<E> spliterator() {
return c.spliterator(); // Must be manually synched by user!
}
-
+ @Override
+ public Stream<E> stream() {
+ return c.stream(); // Must be manually synched by user!
+ }
+ @Override
+ public Stream<E> parallelStream() {
+ return c.parallelStream(); // Must be manually synched by user!
+ }
private void writeObject(ObjectOutputStream s) throws IOException {
synchronized (mutex) {s.defaultWriteObject();}
}
@@ -2549,6 +2579,11 @@
}
@Override
public Spliterator<E> spliterator() {return c.spliterator();}
+ @Override
+ public Stream<E> stream() {return c.stream();}
+ @Override
+ public Stream<E> parallelStream() {return c.parallelStream();}
+
}
/**
@@ -3830,6 +3865,22 @@
") > toIndex(" + toIndex + ")");
return new CopiesList<>(toIndex - fromIndex, element);
}
+
+ // Override default methods in Collection
+ @Override
+ public Stream<E> stream() {
+ return IntStream.range(0, n).mapToObj(i -> element);
+ }
+
+ @Override
+ public Stream<E> parallelStream() {
+ return IntStream.range(0, n).parallel().mapToObj(i -> element);
+ }
+
+ @Override
+ public Spliterator<E> spliterator() {
+ return stream().spliterator();
+ }
}
/**
@@ -4214,8 +4265,6 @@
public boolean retainAll(Collection<?> c) {return s.retainAll(c);}
// addAll is the only inherited implementation
- private static final long serialVersionUID = 2454657854757543876L;
-
// Override default methods in Collection
@Override
public void forEach(Consumer<? super E> action) {
@@ -4226,6 +4275,15 @@
return s.removeIf(filter);
}
+ @Override
+ public Spliterator<E> spliterator() {return s.spliterator();}
+ @Override
+ public Stream<E> stream() {return s.stream();}
+ @Override
+ public Stream<E> parallelStream() {return s.parallelStream();}
+
+ private static final long serialVersionUID = 2454657854757543876L;
+
private void readObject(java.io.ObjectInputStream stream)
throws IOException, ClassNotFoundException
{
@@ -4289,5 +4347,12 @@
public boolean removeIf(Predicate<? super E> filter) {
return q.removeIf(filter);
}
+
+ @Override
+ public Spliterator<E> spliterator() {return q.spliterator();}
+ @Override
+ public Stream<E> stream() {return q.stream();}
+ @Override
+ public Stream<E> parallelStream() {return q.parallelStream();}
}
}