Exemplo n.º 1
0
 public Spliterator<V> spliterator() {
   return Spliterators.spliterator(
       this,
       Spliterator.ORDERED
           | Spliterator.DISTINCT
           | Spliterator.IMMUTABLE
           | Spliterator.NONNULL
           | Spliterator.SIZED);
 }
Exemplo n.º 2
0
  public static <A, B> Stream<Pair<A, B>> zip(Stream<A> s1, Stream<B> s2, int size) {

    PairIterator<A, B, Pair<A, B>> itr =
        new PairIterator<>(s1.iterator(), s2.iterator(), Pair<A, B>::new);

    int characteristics = Spliterator.IMMUTABLE | Spliterator.NONNULL;

    if (size < 0) {
      return StreamSupport.stream(Spliterators.spliteratorUnknownSize(itr, characteristics), false);
    }

    return StreamSupport.stream(Spliterators.spliterator(itr, size, characteristics), false);
  }
Exemplo n.º 3
0
 public Spliterator<E> trySplit() {
   Node<E> p;
   final ConcurrentLinkedQueue<E> q = this.queue;
   int b = batch;
   int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1;
   if (!exhausted && ((p = current) != null || (p = q.first()) != null) && p.next != null) {
     Object[] a = new Object[n];
     int i = 0;
     do {
       if ((a[i] = p.item) != null) ++i;
       if (p == (p = p.next)) p = q.first();
     } while (p != null && i < n);
     if ((current = p) == null) exhausted = true;
     if (i > 0) {
       batch = i;
       return Spliterators.spliterator(
           a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.CONCURRENT);
     }
   }
   return null;
 }
Exemplo n.º 4
0
 @Override
 default Spliterator<T> spliterator() {
   // the focus of the Stream API is on random-access collections of *known size*
   return Spliterators.spliterator(
       iterator(), length(), Spliterator.ORDERED | Spliterator.IMMUTABLE);
 }
Exemplo n.º 5
0
 @Override
 public Spliterator<T> spliterator() {
   return Spliterators.spliterator(
       iterator(), length(), Spliterator.ORDERED | Spliterator.IMMUTABLE);
 }