com.landawn.abacus.util.stream.ArrayStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-util-all Show documentation
Show all versions of abacus-util-all Show documentation
A general programming library in Java
/*
* Copyright (C) 2016 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.util.stream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import com.landawn.abacus.util.ByteIterator;
import com.landawn.abacus.util.CharIterator;
import com.landawn.abacus.util.DoubleIterator;
import com.landawn.abacus.util.FloatIterator;
import com.landawn.abacus.util.IntIterator;
import com.landawn.abacus.util.LongIterator;
import com.landawn.abacus.util.LongMultiset;
import com.landawn.abacus.util.Multimap;
import com.landawn.abacus.util.Multiset;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.NullabLe;
import com.landawn.abacus.util.ShortIterator;
import com.landawn.abacus.util.function.BiConsumer;
import com.landawn.abacus.util.function.BiFunction;
import com.landawn.abacus.util.function.BiPredicate;
import com.landawn.abacus.util.function.BinaryOperator;
import com.landawn.abacus.util.function.Consumer;
import com.landawn.abacus.util.function.Function;
import com.landawn.abacus.util.function.IntFunction;
import com.landawn.abacus.util.function.Predicate;
import com.landawn.abacus.util.function.Supplier;
import com.landawn.abacus.util.function.ToByteFunction;
import com.landawn.abacus.util.function.ToCharFunction;
import com.landawn.abacus.util.function.ToDoubleFunction;
import com.landawn.abacus.util.function.ToFloatFunction;
import com.landawn.abacus.util.function.ToIntFunction;
import com.landawn.abacus.util.function.ToLongFunction;
import com.landawn.abacus.util.function.ToShortFunction;
import com.landawn.abacus.util.function.TriConsumer;
import com.landawn.abacus.util.function.TriFunction;
/**
* This class is a sequential, stateful and immutable stream implementation.
*
* @param
* @since 0.8
*
* @author Haiyang Li
*/
class ArrayStream extends AbstractStream {
final T[] elements;
final int fromIndex;
final int toIndex;
ArrayStream(final T[] values) {
this(values, 0, values.length);
}
ArrayStream(final T[] values, final Collection closeHandlers) {
this(values, 0, values.length, closeHandlers);
}
ArrayStream(final T[] values, final Collection closeHandlers, final boolean sorted, final Comparator super T> comparator) {
this(values, 0, values.length, closeHandlers, sorted, comparator);
}
ArrayStream(final T[] values, final int fromIndex, final int toIndex) {
this(values, fromIndex, toIndex, null);
}
ArrayStream(final T[] values, final int fromIndex, final int toIndex, final Collection closeHandlers) {
this(values, fromIndex, toIndex, closeHandlers, false, null);
}
ArrayStream(final T[] values, final int fromIndex, final int toIndex, final Collection closeHandlers, final boolean sorted,
Comparator super T> comparator) {
super(closeHandlers, sorted, comparator);
checkFromToIndex(fromIndex, toIndex, values.length);
this.elements = values;
this.fromIndex = fromIndex;
this.toIndex = toIndex;
}
@Override
public Stream filter(final Predicate super T> predicate) {
return new IteratorStream<>(new ExIterator() {
private boolean hasNext = false;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
if (hasNext == false && cursor < toIndex) {
do {
if (predicate.test(elements[cursor])) {
hasNext = true;
break;
}
} while (++cursor < toIndex);
}
return hasNext;
}
@Override
public T next() {
if (hasNext == false && hasNext() == false) {
throw new NoSuchElementException();
}
hasNext = false;
return elements[cursor++];
}
}, closeHandlers, sorted, cmp);
}
@Override
public Stream takeWhile(final Predicate super T> predicate) {
return new IteratorStream<>(new ExIterator() {
private boolean hasMore = true;
private boolean hasNext = false;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
if (hasNext == false && hasMore && cursor < toIndex) {
if (predicate.test(elements[cursor])) {
hasNext = true;
} else {
hasMore = false;
}
}
return hasNext;
}
@Override
public T next() {
if (hasNext == false && hasNext() == false) {
throw new NoSuchElementException();
}
hasNext = false;
return elements[cursor++];
}
}, closeHandlers, sorted, cmp);
}
@Override
public Stream dropWhile(final Predicate super T> predicate) {
return new IteratorStream<>(new ExIterator() {
private boolean hasNext = false;
private int cursor = fromIndex;
private boolean dropped = false;
@Override
public boolean hasNext() {
if (hasNext == false && cursor < toIndex) {
if (dropped == false) {
do {
if (predicate.test(elements[cursor]) == false) {
hasNext = true;
break;
}
} while (++cursor < toIndex);
dropped = true;
} else {
hasNext = true;
}
}
return hasNext;
}
@Override
public T next() {
if (hasNext == false && hasNext() == false) {
throw new NoSuchElementException();
}
hasNext = false;
return elements[cursor++];
}
}, closeHandlers, sorted, cmp);
}
@Override
public Stream map(final Function super T, ? extends R> mapper) {
return new IteratorStream<>(new ExIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public R next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.apply(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = (A) mapper.apply(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public Stream biMap(final BiFunction super T, ? super T, ? extends R> mapper, final boolean ignoreNotPaired) {
return new IteratorStream<>(new ExIterator() {
private final int atLeast = ignoreNotPaired ? 2 : 1;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return toIndex - cursor >= atLeast;
}
@Override
public R next() {
if (toIndex - cursor < atLeast) {
throw new NoSuchElementException();
}
return mapper.apply(elements[cursor++], cursor == toIndex ? null : elements[cursor++]);
}
@Override
public long count() {
return (toIndex - cursor) / 2 + (ignoreNotPaired || (toIndex - cursor) % 2 == 0 ? 0 : 1);
}
@Override
public void skip(long n) {
cursor = n < count() ? cursor + (int) n * 2 : toIndex;
}
@Override
public A[] toArray(A[] a) {
final int len = (int) count();
a = a.length >= len ? a : (A[]) N.newArray(a.getClass().getComponentType(), len);
for (int i = 0, len2 = (toIndex - cursor) / 2; i < len2; i++) {
a[i] = (A) mapper.apply(elements[cursor++], elements[cursor++]);
}
if (cursor < toIndex) {
a[len - 1] = (A) mapper.apply(elements[cursor++], null);
}
return a;
}
}, closeHandlers);
}
@Override
public Stream triMap(final TriFunction super T, ? super T, ? super T, ? extends R> mapper, final boolean ignoreNotPaired) {
return new IteratorStream<>(new ExIterator() {
private final int atLeast = ignoreNotPaired ? 3 : 1;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return toIndex - cursor >= atLeast;
}
@Override
public R next() {
if (toIndex - cursor < atLeast) {
throw new NoSuchElementException();
}
return mapper.apply(elements[cursor++], cursor == toIndex ? null : elements[cursor++], cursor == toIndex ? null : elements[cursor++]);
}
@Override
public long count() {
return (toIndex - cursor) / 3 + (ignoreNotPaired || (toIndex - cursor) % 3 == 0 ? 0 : 1);
}
@Override
public void skip(long n) {
cursor = n < count() ? cursor + (int) n * 3 : toIndex;
}
@Override
public A[] toArray(A[] a) {
final int len = (int) count();
a = a.length >= len ? a : (A[]) N.newArray(a.getClass().getComponentType(), len);
for (int i = 0, len2 = (toIndex - cursor) / 3; i < len2; i++) {
a[i] = (A) mapper.apply(elements[cursor++], elements[cursor++], elements[cursor++]);
}
if (cursor < toIndex) {
a[len - 1] = (A) mapper.apply(elements[cursor++], cursor == toIndex ? null : elements[cursor++], null);
}
return a;
}
}, closeHandlers);
}
@Override
public Stream mapFirst(final Function super T, ? extends T> mapperForFirst) {
N.requireNonNull(mapperForFirst);
return new IteratorStream<>(new ExIterator() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public T next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
if (cursor == fromIndex) {
return mapperForFirst.apply(elements[cursor++]);
} else {
return elements[cursor++];
}
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
if (cursor == fromIndex) {
a[i] = (A) mapperForFirst.apply(elements[cursor++]);
} else {
a[i] = (A) elements[cursor++];
}
}
return a;
}
}, closeHandlers);
}
@Override
public Stream mapFirstOrElse(final Function super T, ? extends R> mapperForFirst, final Function super T, ? extends R> mapperForElse) {
N.requireNonNull(mapperForFirst);
N.requireNonNull(mapperForElse);
return new IteratorStream<>(new ExIterator() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public R next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
if (cursor == fromIndex) {
return mapperForFirst.apply(elements[cursor++]);
} else {
return mapperForElse.apply(elements[cursor++]);
}
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
if (cursor == fromIndex) {
a[i] = (A) mapperForFirst.apply(elements[cursor++]);
} else {
a[i] = (A) mapperForElse.apply(elements[cursor++]);
}
}
return a;
}
}, closeHandlers);
}
@Override
public Stream mapLast(final Function super T, ? extends T> mapperForLast) {
N.requireNonNull(mapperForLast);
return new IteratorStream<>(new ExIterator() {
private int last = toIndex - 1;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public T next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
if (cursor == last) {
return mapperForLast.apply(elements[cursor++]);
} else {
return elements[cursor++];
}
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
if (cursor == last) {
a[i] = (A) mapperForLast.apply(elements[cursor++]);
} else {
a[i] = (A) elements[cursor++];
}
}
return a;
}
}, closeHandlers);
}
@Override
public Stream mapLastOrElse(final Function super T, ? extends R> mapperForLast, final Function super T, ? extends R> mapperForElse) {
N.requireNonNull(mapperForLast);
N.requireNonNull(mapperForElse);
return new IteratorStream<>(new ExIterator() {
private int last = toIndex - 1;
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public R next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
if (cursor == last) {
return mapperForLast.apply(elements[cursor++]);
} else {
return mapperForElse.apply(elements[cursor++]);
}
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
if (cursor == last) {
a[i] = (A) mapperForLast.apply(elements[cursor++]);
} else {
a[i] = (A) mapperForElse.apply(elements[cursor++]);
}
}
return a;
}
}, closeHandlers);
}
@Override
public CharStream mapToChar(final ToCharFunction super T> mapper) {
return new IteratorCharStream(new ExCharIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public char nextChar() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsChar(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public char[] toArray() {
final char[] a = new char[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsChar(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public ByteStream mapToByte(final ToByteFunction super T> mapper) {
return new IteratorByteStream(new ExByteIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public byte nextByte() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsByte(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public byte[] toArray() {
final byte[] a = new byte[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsByte(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public ShortStream mapToShort(final ToShortFunction super T> mapper) {
return new IteratorShortStream(new ExShortIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public short nextShort() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsShort(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public short[] toArray() {
final short[] a = new short[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsShort(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public IntStream mapToInt(final ToIntFunction super T> mapper) {
return new IteratorIntStream(new ExIntIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public int nextInt() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsInt(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public int[] toArray() {
final int[] a = new int[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsInt(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public LongStream mapToLong(final ToLongFunction super T> mapper) {
return new IteratorLongStream(new ExLongIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public long nextLong() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsLong(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public long[] toArray() {
final long[] a = new long[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsLong(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public FloatStream mapToFloat(final ToFloatFunction super T> mapper) {
return new IteratorFloatStream(new ExFloatIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public float nextFloat() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsFloat(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public float[] toArray() {
final float[] a = new float[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsFloat(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
public DoubleStream mapToDouble(final ToDoubleFunction super T> mapper) {
return new IteratorDoubleStream(new ExDoubleIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public double nextDouble() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return mapper.applyAsDouble(elements[cursor++]);
}
@Override
public long count() {
return toIndex - cursor;
}
@Override
public void skip(long n) {
cursor = n < toIndex - cursor ? cursor + (int) n : toIndex;
}
@Override
public double[] toArray() {
final double[] a = new double[toIndex - cursor];
for (int i = 0, len = toIndex - cursor; i < len; i++) {
a[i] = mapper.applyAsDouble(elements[cursor++]);
}
return a;
}
}, closeHandlers);
}
@Override
Stream flatMap0(final Function super T, ? extends Iterator extends R>> mapper) {
return new IteratorStream<>(new ExIterator() {
private int cursor = fromIndex;
private Iterator extends R> cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public R next() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.next();
}
}, closeHandlers);
}
@Override
CharStream flatMapToChar0(final Function super T, CharIterator> mapper) {
return new IteratorCharStream(new ExCharIterator() {
private int cursor = fromIndex;
private CharIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public char nextChar() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextChar();
}
}, closeHandlers);
}
@Override
ByteStream flatMapToByte0(final Function super T, ByteIterator> mapper) {
return new IteratorByteStream(new ExByteIterator() {
private int cursor = fromIndex;
private ByteIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public byte nextByte() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextByte();
}
}, closeHandlers);
}
@Override
ShortStream flatMapToShort0(final Function super T, ShortIterator> mapper) {
return new IteratorShortStream(new ExShortIterator() {
private int cursor = fromIndex;
private ShortIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public short nextShort() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextShort();
}
}, closeHandlers);
}
@Override
IntStream flatMapToInt0(final Function super T, IntIterator> mapper) {
return new IteratorIntStream(new ExIntIterator() {
private int cursor = fromIndex;
private IntIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public int nextInt() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextInt();
}
}, closeHandlers);
}
@Override
LongStream flatMapToLong0(final Function super T, LongIterator> mapper) {
return new IteratorLongStream(new ExLongIterator() {
private int cursor = fromIndex;
private LongIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public long nextLong() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextLong();
}
}, closeHandlers);
}
@Override
FloatStream flatMapToFloat0(final Function super T, FloatIterator> mapper) {
return new IteratorFloatStream(new ExFloatIterator() {
private int cursor = fromIndex;
private FloatIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public float nextFloat() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextFloat();
}
}, closeHandlers);
}
@Override
DoubleStream flatMapToDouble0(final Function super T, DoubleIterator> mapper) {
return new IteratorDoubleStream(new ExDoubleIterator() {
private int cursor = fromIndex;
private DoubleIterator cur = null;
@Override
public boolean hasNext() {
while ((cur == null || cur.hasNext() == false) && cursor < toIndex) {
cur = mapper.apply(elements[cursor++]);
}
return cur != null && cur.hasNext();
}
@Override
public double nextDouble() {
if ((cur == null || cur.hasNext() == false) && hasNext() == false) {
throw new NoSuchElementException();
}
return cur.nextDouble();
}
}, closeHandlers);
}
@Override
public Stream slidingMap(final BiFunction super T, ? super T, R> mapper, final int increment) {
final int windowSize = 2;
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
return new IteratorStream<>(new ExIterator() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public R next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final R result = mapper.apply(elements[cursor], cursor < toIndex - 1 ? elements[cursor + 1] : null);
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
return result;
}
}, closeHandlers);
}
@Override
public Stream slidingMap(final TriFunction super T, ? super T, ? super T, R> mapper, final int increment) {
final int windowSize = 3;
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
return new IteratorStream<>(new ExIterator() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public R next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final R result = mapper.apply(elements[cursor], cursor < toIndex - 1 ? elements[cursor + 1] : null,
cursor < toIndex - 2 ? elements[cursor + 2] : null);
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
return result;
}
}, closeHandlers);
}
@Override
public Stream> split(final int size) {
N.checkArgument(size > 0, "'size' must be bigger than 0");
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Stream next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return new ArrayStream<>(elements, cursor, (cursor = size < toIndex - cursor ? cursor + size : toIndex), null, sorted, cmp);
}
}, closeHandlers);
}
@Override
public Stream> splitToList(final int size) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public List next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
return N.asList(N.copyOfRange(elements, cursor, (cursor = size < toIndex - cursor ? cursor + size : toIndex)));
}
}, closeHandlers);
}
@Override
public Stream> splitToSet(final int size) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Set next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final Set result = new HashSet<>(N.min(9, toIndex - cursor > size ? size : toIndex - cursor));
for (int i = cursor, to = (cursor = size < toIndex - cursor ? cursor + size : toIndex); i < to; i++) {
result.add(elements[i]);
}
return result;
}
}, closeHandlers);
}
@Override
public Stream> split(final Predicate super T> predicate) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
private boolean preCondition = false;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Stream next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final int from = cursor;
while (cursor < toIndex) {
if (from == cursor) {
preCondition = predicate.test(elements[from]);
cursor++;
} else if (predicate.test(elements[cursor]) == preCondition) {
cursor++;
} else {
break;
}
}
return new ArrayStream<>(elements, from, cursor, null, sorted, cmp);
}
}, closeHandlers);
}
@Override
public Stream> splitToList(final Predicate super T> predicate) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
private boolean preCondition = false;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public List next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final List result = new ArrayList<>();
while (cursor < toIndex) {
if (result.size() == 0) {
preCondition = predicate.test(elements[cursor]);
result.add(elements[cursor]);
cursor++;
} else if (predicate.test(elements[cursor]) == preCondition) {
result.add(elements[cursor]);
cursor++;
} else {
break;
}
}
return result;
}
}, closeHandlers);
}
@Override
public Stream> split(final U identity, final BiFunction super T, ? super U, Boolean> predicate, final Consumer super U> identityUpdate) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
private boolean preCondition = false;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Stream next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final int from = cursor;
while (cursor < toIndex) {
if (from == cursor) {
preCondition = predicate.apply(elements[from], identity);
cursor++;
} else if (predicate.apply(elements[cursor], identity) == preCondition) {
cursor++;
} else {
if (identityUpdate != null) {
identityUpdate.accept(identity);
}
break;
}
}
return new ArrayStream<>(elements, from, cursor, null, sorted, cmp);
}
}, closeHandlers);
}
@Override
public Stream> splitToList(final U identity, final BiFunction super T, ? super U, Boolean> predicate,
final Consumer super U> identityUpdate) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
private boolean preCondition = false;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public List next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final List result = new ArrayList<>();
while (cursor < toIndex) {
if (result.size() == 0) {
preCondition = predicate.apply(elements[cursor], identity);
result.add(elements[cursor]);
cursor++;
} else if (predicate.apply(elements[cursor], identity) == preCondition) {
result.add(elements[cursor]);
cursor++;
} else {
if (identityUpdate != null) {
identityUpdate.accept(identity);
}
break;
}
}
return result;
}
}, closeHandlers);
}
@Override
public Stream> splitToSet(final U identity, final BiFunction super T, ? super U, Boolean> predicate,
final Consumer super U> identityUpdate) {
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
private boolean preCondition = false;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Set next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final Set result = new HashSet<>();
while (cursor < toIndex) {
if (result.size() == 0) {
preCondition = predicate.apply(elements[cursor], identity);
result.add(elements[cursor]);
cursor++;
} else if (predicate.apply(elements[cursor], identity) == preCondition) {
result.add(elements[cursor]);
cursor++;
} else {
if (identityUpdate != null) {
identityUpdate.accept(identity);
}
break;
}
}
return result;
}
}, closeHandlers);
}
@Override
public Stream> splitAt(final int n) {
if (n < 0) {
throw new IllegalArgumentException("'n' can't be negative");
}
final Stream[] a = new Stream[2];
final int middleIndex = n < toIndex - fromIndex ? fromIndex + n : toIndex;
a[0] = middleIndex == fromIndex ? (Stream) Stream.empty() : new ArrayStream<>(elements, fromIndex, middleIndex, null, sorted, cmp);
a[1] = middleIndex == toIndex ? (Stream) Stream.empty() : new ArrayStream<>(elements, middleIndex, toIndex, null, sorted, cmp);
return new ArrayStream<>(a, closeHandlers);
}
@Override
public Stream> splitBy(Predicate super T> where) {
N.requireNonNull(where);
int n = 0;
for (int i = fromIndex; i < toIndex; i++) {
if (where.test(elements[i])) {
n++;
} else {
break;
}
}
return splitAt(n);
}
@Override
public Stream> sliding(final int windowSize, final int increment) {
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public Stream next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final Stream result = new ArrayStream<>(elements, cursor, windowSize < toIndex - cursor ? cursor + windowSize : toIndex, null, sorted, cmp);
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
return result;
}
}, closeHandlers);
}
@Override
public Stream> slidingToList(final int windowSize, final int increment) {
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
return new IteratorStream<>(new ExIterator>() {
private int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public List next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
final List result = N.asList(N.copyOfRange(elements, cursor, windowSize < toIndex - cursor ? cursor + windowSize : toIndex));
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
return result;
}
}, closeHandlers);
}
@Override
public Stream top(int n) {
return top(n, OBJECT_COMPARATOR);
}
@Override
public Stream top(int n, Comparator super T> comparator) {
N.checkArgument(n > 0, "'n' must be bigger than 0");
if (n >= toIndex - fromIndex) {
return this;
} else if (sorted && isSameComparator(comparator, cmp)) {
return new ArrayStream<>(elements, toIndex - n, toIndex, closeHandlers, sorted, cmp);
} else {
return new ArrayStream<>(N.top(elements, fromIndex, toIndex, n, comparator), closeHandlers, sorted, cmp);
}
}
@Override
public Stream sorted() {
return sorted(OBJECT_COMPARATOR);
}
@Override
public Stream sorted(Comparator super T> comparator) {
if (sorted && isSameComparator(comparator, cmp)) {
return this;
}
final T[] a = N.copyOfRange(elements, fromIndex, toIndex);
N.sort(a, comparator);
return new ArrayStream<>(a, closeHandlers, true, comparator);
}
@Override
public Stream peek(final Consumer super T> action) {
return new IteratorStream<>(new ExIterator() {
int cursor = fromIndex;
@Override
public boolean hasNext() {
return cursor < toIndex;
}
@Override
public T next() {
if (cursor >= toIndex) {
throw new NoSuchElementException();
}
action.accept(elements[cursor]);
return elements[cursor++];
}
@Override
public A[] toArray(A[] a) {
a = a.length >= toIndex - cursor ? a : (A[]) N.newArray(a.getClass().getComponentType(), toIndex - cursor);
for (int i = 0, len = toIndex - cursor; i < len; i++) {
action.accept(elements[cursor]);
a[i] = (A) elements[cursor++];
}
return a;
}
}, closeHandlers, sorted, cmp);
}
@Override
public Stream limit(long maxSize) {
if (maxSize < 0) {
throw new IllegalArgumentException("'maxSize' can't be negative: " + maxSize);
} else if (maxSize >= toIndex - fromIndex) {
return this;
}
return new ArrayStream<>(elements, fromIndex, (int) (fromIndex + maxSize), closeHandlers, sorted, cmp);
}
@Override
public Stream skip(long n) {
if (n < 0) {
throw new IllegalArgumentException("The skipped number can't be negative: " + n);
} else if (n == 0) {
return this;
}
if (n >= toIndex - fromIndex) {
return new ArrayStream<>(elements, toIndex, toIndex, closeHandlers, sorted, cmp);
} else {
return new ArrayStream<>(elements, (int) (fromIndex + n), toIndex, closeHandlers, sorted, cmp);
}
}
@Override
public void forEach(Consumer super T> action) {
for (int i = fromIndex; i < toIndex; i++) {
action.accept(elements[i]);
}
}
@Override
public R forEach(R seed, BiFunction accumulator, BiPredicate super R, ? super T> conditionToBreak) {
R result = seed;
for (int i = fromIndex; i < toIndex; i++) {
result = accumulator.apply(result, elements[i]);
if (conditionToBreak.test(result, elements[i])) {
break;
}
}
return result;
}
@Override
public void forEachPair(final BiConsumer super T, ? super T> action, final int increment) {
final int windowSize = 2;
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
int cursor = fromIndex;
while (cursor < toIndex) {
action.accept(elements[cursor], cursor < toIndex - 1 ? elements[cursor + 1] : null);
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
}
}
@Override
public void forEachTriple(final TriConsumer super T, ? super T, ? super T> action, final int increment) {
final int windowSize = 3;
N.checkArgument(windowSize > 0 && increment > 0, "'windowSize'=%s and 'increment'=%s must not be less than 1", windowSize, increment);
int cursor = fromIndex;
while (cursor < toIndex) {
action.accept(elements[cursor], cursor < toIndex - 1 ? elements[cursor + 1] : null, cursor < toIndex - 2 ? elements[cursor + 2] : null);
cursor = increment < toIndex - cursor && windowSize < toIndex - cursor ? cursor + increment : toIndex;
}
}
@Override
public Object[] toArray() {
return N.copyOfRange(elements, fromIndex, toIndex);
}
A[] toArray(A[] a) {
if (a.length < (toIndex - fromIndex)) {
a = N.newArray(a.getClass().getComponentType(), toIndex - fromIndex);
}
N.copy(elements, fromIndex, a, 0, toIndex - fromIndex);
return a;
}
@Override
public A[] toArray(IntFunction generator) {
return toArray(generator.apply(toIndex - fromIndex));
}
@Override
public List toList() {
// return N.asList(N.copyOfRange(elements, fromIndex, toIndex));
if (fromIndex == 0 && toIndex == elements.length && elements.length > 9) {
return new ArrayList<>(Arrays.asList(elements));
}
final List result = new ArrayList<>(toIndex - fromIndex);
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public > R toList(Supplier supplier) {
final R result = supplier.get();
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public Set toSet() {
final Set result = new HashSet<>(N.min(9, N.initHashCapacity(toIndex - fromIndex)));
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public > R toSet(Supplier supplier) {
final R result = supplier.get();
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public Multiset toMultiset() {
final Multiset result = new Multiset<>(N.min(9, N.initHashCapacity(toIndex - fromIndex)));
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public Multiset toMultiset(Supplier extends Multiset> supplier) {
final Multiset result = supplier.get();
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public LongMultiset toLongMultiset() {
final LongMultiset result = new LongMultiset<>(N.min(9, N.initHashCapacity(toIndex - fromIndex)));
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public LongMultiset toLongMultiset(Supplier extends LongMultiset> supplier) {
final LongMultiset result = supplier.get();
for (int i = fromIndex; i < toIndex; i++) {
result.add(elements[i]);
}
return result;
}
@Override
public > M toMap(Function super T, ? extends K> keyExtractor, Function super T, ? extends U> valueMapper,
BinaryOperator mergeFunction, Supplier mapFactory) {
final M result = mapFactory.get();
for (int i = fromIndex; i < toIndex; i++) {
Collectors.merge(result, keyExtractor.apply(elements[i]), valueMapper.apply(elements[i]), mergeFunction);
}
return result;
}
@Override
public > M toMap(final Function super T, ? extends K> classifier, final Collector super T, A, D> downstream,
final Supplier mapFactory) {
final M result = mapFactory.get();
final Supplier downstreamSupplier = downstream.supplier();
final BiConsumer downstreamAccumulator = downstream.accumulator();
final Map intermediate = (Map) result;
K key = null;
A v = null;
for (int i = fromIndex; i < toIndex; i++) {
key = N.requireNonNull(classifier.apply(elements[i]), "element cannot be mapped to a null key");
if ((v = intermediate.get(key)) == null) {
if ((v = downstreamSupplier.get()) != null) {
intermediate.put(key, v);
}
}
downstreamAccumulator.accept(v, elements[i]);
}
final BiFunction super K, ? super A, ? extends A> function = new BiFunction() {
@Override
public A apply(K k, A v) {
return (A) downstream.finisher().apply(v);
}
};
Collectors.replaceAll(intermediate, function);
return result;
}
@Override
public , M extends Multimap> M toMultimap(Function super T, ? extends K> keyExtractor,
Function super T, ? extends U> valueMapper, Supplier mapFactory) {
final M result = mapFactory.get();
for (int i = fromIndex; i < toIndex; i++) {
result.put(keyExtractor.apply(elements[i]), valueMapper.apply(elements[i]));
}
return result;
}
@Override
public NullabLe first() {
if (fromIndex == toIndex) {
return NullabLe.empty();
}
return NullabLe.of(elements[fromIndex]);
}
@Override
public NullabLe last() {
if (fromIndex == toIndex) {
return NullabLe.empty();
}
return NullabLe.of(elements[toIndex - 1]);
}
@Override
public T reduce(T identity, BinaryOperator accumulator) {
T result = identity;
for (int i = fromIndex; i < toIndex; i++) {
result = accumulator.apply(result, elements[i]);
}
return result;
}
@Override
public NullabLe reduce(BinaryOperator accumulator) {
if (fromIndex == toIndex) {
NullabLe.empty();
}
T result = elements[fromIndex];
for (int i = fromIndex + 1; i < toIndex; i++) {
result = accumulator.apply(result, elements[i]);
}
return NullabLe.of(result);
}
@Override
public U reduce(U identity, BiFunction accumulator, BinaryOperator combiner) {
U result = identity;
for (int i = fromIndex; i < toIndex; i++) {
result = accumulator.apply(result, elements[i]);
}
return result;
}
@Override
public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) {
final R result = supplier.get();
for (int i = fromIndex; i < toIndex; i++) {
accumulator.accept(result, elements[i]);
}
return result;
}
@Override
public R collect(Collector super T, A, R> collector) {
final A container = collector.supplier().get();
final BiConsumer accumulator = collector.accumulator();
for (int i = fromIndex; i < toIndex; i++) {
accumulator.accept(container, elements[i]);
}
return collector.finisher().apply(container);
}
@Override
public NullabLe head() {
return fromIndex == toIndex ? NullabLe. empty() : NullabLe.of(elements[fromIndex]);
}
@Override
public Stream tail() {
if (fromIndex == toIndex) {
return this;
}
return new ArrayStream<>(elements, fromIndex + 1, toIndex, closeHandlers, sorted, cmp);
}
@Override
public Stream head2() {
if (fromIndex == toIndex) {
return this;
}
return new ArrayStream<>(elements, fromIndex, toIndex - 1, closeHandlers, sorted, cmp);
}
@Override
public NullabLe tail2() {
return fromIndex == toIndex ? NullabLe. empty() : NullabLe.of(elements[toIndex - 1]);
}
@Override
public Stream last(final int n) {
N.checkArgument(n >= 0, "'n' can't be negative");
if (toIndex - fromIndex <= n) {
return this;
}
return new ArrayStream<>(elements, toIndex - n, toIndex, closeHandlers, sorted, cmp);
}
@Override
public Stream skipLast(int n) {
N.checkArgument(n >= 0, "'n' can't be negative");
if (n == 0) {
return this;
}
return new ArrayStream<>(elements, fromIndex, N.max(fromIndex, toIndex - n), closeHandlers, sorted, cmp);
}
@Override
public NullabLe min(Comparator super T> comparator) {
if (fromIndex == toIndex) {
return NullabLe.empty();
} else if (sorted && isSameComparator(cmp, comparator)) {
return NullabLe.of(elements[fromIndex]);
}
return NullabLe.of(N.min(elements, fromIndex, toIndex, comparator));
}
@Override
public NullabLe max(Comparator super T> comparator) {
if (fromIndex == toIndex) {
return NullabLe.empty();
} else if (sorted && isSameComparator(cmp, comparator)) {
return NullabLe.of(elements[toIndex - 1]);
}
return NullabLe.of(N.max(elements, fromIndex, toIndex, comparator));
}
@Override
public NullabLe kthLargest(int k, Comparator super T> comparator) {
N.checkArgument(k > 0, "'k' must be bigger than 0");
if (k > toIndex - fromIndex) {
return NullabLe.empty();
} else if (sorted && isSameComparator(cmp, comparator)) {
return NullabLe.of(elements[toIndex - k]);
}
return NullabLe.of(N.kthLargest(elements, fromIndex, toIndex, k, comparator));
}
@Override
public long count() {
return toIndex - fromIndex;
}
@Override
public Stream reversed() {
return new IteratorStream<>(new ExIterator() {
private int cursor = toIndex;
@Override
public boolean hasNext() {
return cursor > fromIndex;
}
@Override
public T next() {
if (cursor <= fromIndex) {
throw new NoSuchElementException();
}
return elements[--cursor];
}
@Override
public long count() {
return cursor - fromIndex;
}
@Override
public void skip(long n) {
cursor = n < cursor - fromIndex ? cursor - (int) n : fromIndex;
}
@Override
public A[] toArray(A[] a) {
a = a.length >= cursor - fromIndex ? a : (A[]) N.newArray(a.getClass().getComponentType(), cursor - fromIndex);
for (int i = 0, len = cursor - fromIndex; i < len; i++) {
a[i] = (A) elements[cursor - i - 1];
}
return a;
}
}, closeHandlers);
}
@Override
public boolean anyMatch(final Predicate super T> predicate) {
for (int i = fromIndex; i < toIndex; i++) {
if (predicate.test(elements[i])) {
return true;
}
}
return false;
}
@Override
public boolean allMatch(final Predicate super T> predicate) {
for (int i = fromIndex; i < toIndex; i++) {
if (predicate.test(elements[i]) == false) {
return false;
}
}
return true;
}
@Override
public boolean noneMatch(final Predicate super T> predicate) {
for (int i = fromIndex; i < toIndex; i++) {
if (predicate.test(elements[i])) {
return false;
}
}
return true;
}
@Override
public NullabLe findFirst(final Predicate super T> predicate) {
for (int i = fromIndex; i < toIndex; i++) {
if (predicate.test(elements[i])) {
return NullabLe.of(elements[i]);
}
}
return (NullabLe) NullabLe.empty();
}
@Override
public NullabLe findLast(final Predicate super T> predicate) {
for (int i = toIndex - 1; i >= fromIndex; i--) {
if (predicate.test(elements[i])) {
return NullabLe.of(elements[i]);
}
}
return (NullabLe) NullabLe.empty();
}
@Override
public Stream cached() {
return this;
}
/**
* Returns a Stream with elements from a temporary queue which is filled by reading the elements from the specified iterator asynchronously.
*
* @param stream
* @param queueSize Default value is 8
* @return
*/
@Override
public Stream queued(int queueSize) {
return this;
}
@Override
ExIterator exIterator() {
return ExIterator.of(elements, fromIndex, toIndex);
}
@Override
public Stream parallel(int maxThreadNum, BaseStream.Splitor splitor) {
if (maxThreadNum < 1 || maxThreadNum > MAX_THREAD_NUM_PER_OPERATION) {
throw new IllegalArgumentException("'maxThreadNum' must not less than 1 or exceeded: " + MAX_THREAD_NUM_PER_OPERATION);
}
return new ParallelArrayStream<>(elements, fromIndex, toIndex, closeHandlers, sorted, cmp, maxThreadNum, splitor);
}
@Override
public Stream onClose(Runnable closeHandler) {
final Set newCloseHandlers = new LocalLinkedHashSet<>(N.isNullOrEmpty(this.closeHandlers) ? 1 : this.closeHandlers.size() + 1);
if (N.notNullOrEmpty(this.closeHandlers)) {
newCloseHandlers.addAll(this.closeHandlers);
}
newCloseHandlers.add(closeHandler);
return new ArrayStream<>(elements, fromIndex, toIndex, newCloseHandlers, sorted, cmp);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy