diff --git a/lib/abacus-util-1.5.jar b/lib/abacus-util-1.5.jar index 8f8a452a..01994759 100644 Binary files a/lib/abacus-util-1.5.jar and b/lib/abacus-util-1.5.jar differ diff --git a/lib/abacus-util-jdk7-1.5.jar b/lib/abacus-util-jdk7-1.5.jar index 2384346e..1e0d3ee3 100644 Binary files a/lib/abacus-util-jdk7-1.5.jar and b/lib/abacus-util-jdk7-1.5.jar differ diff --git a/src/com/landawn/abacus/util/ExceptionalStream.java b/src/com/landawn/abacus/util/ExceptionalStream.java index d294b2df..b218a572 100644 --- a/src/com/landawn/abacus/util/ExceptionalStream.java +++ b/src/com/landawn/abacus/util/ExceptionalStream.java @@ -1561,6 +1561,7 @@ private void init() throws E { public void forEach(Try.Consumer action) throws E { N.checkArgNotNull(action, "action"); + assertNotClosed(); try { while (elements.hasNext()) { @@ -1572,6 +1573,8 @@ public void forEach(Try.Consumer action) throws E { } public Optional min(Comparator comparator) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -1600,6 +1603,7 @@ public Optional min(Comparator comparator) throws E { public Optional minBy(final Function keyExtractor) throws E { N.checkArgNotNull(keyExtractor, "keyExtractor"); + assertNotClosed(); try { final Comparator comparator = Fn.comparingBy(keyExtractor); @@ -1611,6 +1615,8 @@ public Optional minBy(final Function keyExtr } public Optional max(Comparator comparator) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -1646,6 +1652,7 @@ public Optional max(Comparator comparator) throws E { public Optional maxBy(final Function keyExtractor) throws E { N.checkArgNotNull(keyExtractor, "keyExtractor"); + assertNotClosed(); try { final Comparator comparator = Fn.comparingBy(keyExtractor); @@ -1658,6 +1665,7 @@ public Optional maxBy(final Function keyExtr public boolean anyMatch(final Try.Predicate predicate) throws E { N.checkArgNotNull(predicate, "predicate"); + assertNotClosed(); try { while (elements.hasNext()) { @@ -1674,6 +1682,7 @@ public boolean anyMatch(final Try.Predicate predicate) t public boolean allMatch(final Try.Predicate predicate) throws E { N.checkArgNotNull(predicate, "predicate"); + assertNotClosed(); try { while (elements.hasNext()) { @@ -1690,6 +1699,7 @@ public boolean allMatch(final Try.Predicate predicate) t public boolean noneMatch(final Try.Predicate predicate) throws E { N.checkArgNotNull(predicate, "predicate"); + assertNotClosed(); try { while (elements.hasNext()) { @@ -1706,6 +1716,7 @@ public boolean noneMatch(final Try.Predicate predicate) public Optional findFirst(final Try.Predicate predicate) throws E { N.checkArgNotNull(predicate, "predicate"); + assertNotClosed(); try { while (elements.hasNext()) { @@ -1724,6 +1735,7 @@ public Optional findFirst(final Try.Predicate predica public Optional findLast(final Try.Predicate predicate) throws E { N.checkArgNotNull(predicate, "predicate"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1750,6 +1762,8 @@ public Optional findLast(final Try.Predicate predicat } public Optional first() throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -1762,6 +1776,8 @@ public Optional first() throws E { } public Optional last() throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -1780,6 +1796,8 @@ public Optional last() throws E { } public Object[] toArray() throws E { + assertNotClosed(); + try { return toList().toArray(); } finally { @@ -1789,6 +1807,7 @@ public Object[] toArray() throws E { public A[] toArray(IntFunction generator) throws E { N.checkArgNotNull(generator, "generator"); + assertNotClosed(); try { final List list = toList(); @@ -1800,6 +1819,8 @@ public A[] toArray(IntFunction generator) throws E { } public List toList() throws E { + assertNotClosed(); + try { final List result = new ArrayList<>(); @@ -1814,6 +1835,8 @@ public List toList() throws E { } public Set toSet() throws E { + assertNotClosed(); + try { final Set result = new HashSet<>(); @@ -1829,6 +1852,7 @@ public Set toSet() throws E { public > C toCollection(final Supplier supplier) throws E { N.checkArgNotNull(supplier, "supplier"); + assertNotClosed(); try { final C result = supplier.get(); @@ -1911,6 +1935,7 @@ public > M toMap(final Try.Function> M toMap(final Try.Function downstreamSupplier = downstream.supplier(); @@ -2057,6 +2083,7 @@ public >> M groupTo(Try.Function>> M groupTo(Try.Function onlyOne() throws DuplicatedResultException, E { + assertNotClosed(); + try { Optional result = Optional.empty(); @@ -2113,6 +2144,8 @@ public Optional onlyOne() throws DuplicatedResultException, E { } public OptionalInt sumInt(Try.ToIntFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalInt.empty(); @@ -2131,6 +2164,8 @@ public OptionalInt sumInt(Try.ToIntFunction func) throws E { } public OptionalLong sumLong(Try.ToLongFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalLong.empty(); @@ -2149,6 +2184,8 @@ public OptionalLong sumLong(Try.ToLongFunction func) throws E { } public OptionalDouble sumDouble(Try.ToDoubleFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -2167,6 +2204,8 @@ public OptionalDouble sumDouble(Try.ToDoubleFunction func) throws E { } public OptionalDouble averageInt(Try.ToIntFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -2187,6 +2226,8 @@ public OptionalDouble averageInt(Try.ToIntFunction func) throws E { } public OptionalDouble averageLong(Try.ToLongFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -2207,6 +2248,8 @@ public OptionalDouble averageLong(Try.ToLongFunction func) throws E { } public OptionalDouble averageDouble(Try.ToDoubleFunction func) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -2226,6 +2269,7 @@ public OptionalDouble averageDouble(Try.ToDoubleFunction func) throws E { public T reduce(T identity, Try.BinaryOperator accumulator) throws E { N.checkArgNotNull(accumulator, "accumulator"); + assertNotClosed(); try { T result = identity; @@ -2242,6 +2286,7 @@ public T reduce(T identity, Try.BinaryOperator accumulator) thro public Optional reduce(Try.BinaryOperator accumulator) throws E { N.checkArgNotNull(accumulator, "accumulator"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -2263,6 +2308,7 @@ public Optional reduce(Try.BinaryOperator accumulator) throws public R collect(Supplier supplier, final Try.BiConsumer accumulator) throws E { N.checkArgNotNull(supplier, "supplier"); N.checkArgNotNull(accumulator, "accumulator"); + assertNotClosed(); try { final R result = supplier.get(); @@ -2282,6 +2328,7 @@ public RR collect(Supplier supplier, final Try.BiConsumer RR collect(Supplier supplier, final Try.BiConsumer R collect(final Collector collector) throws E { N.checkArgNotNull(collector, "collector"); + assertNotClosed(); try { final A container = collector.supplier().get(); @@ -2316,6 +2364,7 @@ public R collect(final Collector collector) throws E { public RR collectAndThen(final Collector collector, final Try.Function func) throws E { N.checkArgNotNull(collector, "collector"); N.checkArgNotNull(func, "func"); + assertNotClosed(); try { final A container = collector.supplier().get(); @@ -2504,6 +2553,12 @@ public synchronized void close() throws E { } } + void assertNotClosed() { + if (isClosed) { + throw new IllegalStateException("This stream has been closed"); + } + } + static ExceptionalStream newStream(final ExceptionalIterator iter) { return new ExceptionalStream<>(iter, null); } diff --git a/src/com/landawn/abacus/util/URLEncodedUtil.java b/src/com/landawn/abacus/util/URLEncodedUtil.java index 436f8ac3..1cc58c43 100644 --- a/src/com/landawn/abacus/util/URLEncodedUtil.java +++ b/src/com/landawn/abacus/util/URLEncodedUtil.java @@ -323,8 +323,9 @@ public static String encode(final String url, final Object parameters) { return encode(url, parameters, Charsets.UTF_8); } + @SuppressWarnings("rawtypes") public static String encode(final String url, final Object parameters, final Charset charset) { - if (parameters == null) { + if (parameters == null || (parameters instanceof Map && ((Map) parameters).isEmpty())) { return url; } @@ -345,8 +346,9 @@ public static void encode(final StringBuilder output, final Object parameters) { encode(output, parameters, Charsets.UTF_8); } + @SuppressWarnings("rawtypes") public static void encode(final StringBuilder output, final Object parameters, final Charset charset) { - if (parameters == null) { + if (parameters == null || (parameters instanceof Map && ((Map) parameters).isEmpty())) { return; } diff --git a/src/com/landawn/abacus/util/stream/AbstractByteStream.java b/src/com/landawn/abacus/util/stream/AbstractByteStream.java index ffed656a..386ff858 100644 --- a/src/com/landawn/abacus/util/stream/AbstractByteStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractByteStream.java @@ -885,6 +885,8 @@ public ByteMatrix toMatrix() { @Override public OptionalByte first() { + assertNotClosed(); + try { final ByteIterator iter = this.iteratorEx(); @@ -896,6 +898,8 @@ public OptionalByte first() { @Override public OptionalByte last() { + assertNotClosed(); + try { final ByteIterator iter = this.iteratorEx(); @@ -917,6 +921,8 @@ public OptionalByte last() { @Override public OptionalByte onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final ByteIterator iter = this.iteratorEx(); @@ -940,6 +946,8 @@ public OptionalByte findAny(final Try.BytePredicate pre @Override public OptionalByte findFirstOrLast(Try.BytePredicate predicateForFirst, Try.BytePredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final ByteIteratorEx iter = iteratorEx(); MutableByte last = null; @@ -967,6 +975,8 @@ public OptionalByte findFirstOrLast( @Override public Optional> percentiles() { + assertNotClosed(); + try { final byte[] a = sorted().toArray(); @@ -982,6 +992,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final byte[] a = sorted().toArray(); @@ -997,6 +1009,8 @@ public Pair>> summarizeAnd @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final ByteIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractCharStream.java b/src/com/landawn/abacus/util/stream/AbstractCharStream.java index 55305e0f..e9b1f1c0 100644 --- a/src/com/landawn/abacus/util/stream/AbstractCharStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractCharStream.java @@ -874,6 +874,8 @@ public CharMatrix toMatrix() { @Override public OptionalChar first() { + assertNotClosed(); + try { final CharIterator iter = this.iteratorEx(); @@ -885,6 +887,8 @@ public OptionalChar first() { @Override public OptionalChar last() { + assertNotClosed(); + try { final CharIterator iter = this.iteratorEx(); @@ -906,6 +910,8 @@ public OptionalChar last() { @Override public OptionalChar onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final CharIterator iter = this.iteratorEx(); @@ -929,6 +935,8 @@ public OptionalChar findAny(final Try.CharPredicate pre @Override public OptionalChar findFirstOrLast(Try.CharPredicate predicateForFirst, Try.CharPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final CharIteratorEx iter = iteratorEx(); MutableChar last = null; @@ -956,6 +964,8 @@ public OptionalChar findFirstOrLast( @Override public Optional> percentiles() { + assertNotClosed(); + try { final char[] a = sorted().toArray(); @@ -971,6 +981,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final char[] a = sorted().toArray(); @@ -986,6 +998,8 @@ public Pair>> summari @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final CharIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractDoubleStream.java b/src/com/landawn/abacus/util/stream/AbstractDoubleStream.java index b82655d1..b06a82d2 100644 --- a/src/com/landawn/abacus/util/stream/AbstractDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractDoubleStream.java @@ -881,6 +881,8 @@ public DoubleMatrix toMatrix() { @Override public double sum() { + assertNotClosed(); + try { return summation().sum(); } finally { @@ -904,6 +906,8 @@ public void accept(double t) { @Override public OptionalDouble average() { + assertNotClosed(); + try { return summation().average(); } finally { @@ -913,6 +917,8 @@ public OptionalDouble average() { @Override public OptionalDouble first() { + assertNotClosed(); + try { final DoubleIterator iter = this.iteratorEx(); @@ -924,6 +930,8 @@ public OptionalDouble first() { @Override public OptionalDouble last() { + assertNotClosed(); + try { final DoubleIterator iter = this.iteratorEx(); @@ -945,6 +953,8 @@ public OptionalDouble last() { @Override public OptionalDouble onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final DoubleIterator iter = this.iteratorEx(); @@ -968,6 +978,8 @@ public OptionalDouble findAny(final Try.DoublePredicate @Override public OptionalDouble findFirstOrLast(Try.DoublePredicate predicateForFirst, Try.DoublePredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final DoubleIteratorEx iter = iteratorEx(); MutableDouble last = null; @@ -995,6 +1007,8 @@ public OptionalDouble findFirstOrLas @Override public Optional> percentiles() { + assertNotClosed(); + try { final double[] a = sorted().toArray(); @@ -1011,6 +1025,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final double[] a = sorted().toArray(); @@ -1026,6 +1042,8 @@ public Pair>> summariz @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final DoubleIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractFloatStream.java b/src/com/landawn/abacus/util/stream/AbstractFloatStream.java index 2627ea10..a9d6fe70 100644 --- a/src/com/landawn/abacus/util/stream/AbstractFloatStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractFloatStream.java @@ -882,6 +882,8 @@ public FloatMatrix toMatrix() { @Override public double sum() { + assertNotClosed(); + try { return summation().sum(); } finally { @@ -905,6 +907,8 @@ public void accept(float t) { @Override public OptionalDouble average() { + assertNotClosed(); + try { return summation().average(); } finally { @@ -914,6 +918,8 @@ public OptionalDouble average() { @Override public OptionalFloat first() { + assertNotClosed(); + try { final FloatIterator iter = this.iteratorEx(); @@ -925,6 +931,8 @@ public OptionalFloat first() { @Override public OptionalFloat last() { + assertNotClosed(); + try { final FloatIterator iter = this.iteratorEx(); @@ -946,6 +954,8 @@ public OptionalFloat last() { @Override public OptionalFloat onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final FloatIterator iter = this.iteratorEx(); @@ -969,6 +979,8 @@ public OptionalFloat findAny(final Try.FloatPredicate p @Override public OptionalFloat findFirstOrLast(Try.FloatPredicate predicateForFirst, Try.FloatPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final FloatIteratorEx iter = iteratorEx(); MutableFloat last = null; @@ -996,6 +1008,8 @@ public OptionalFloat findFirstOrLast @Override public Optional> percentiles() { + assertNotClosed(); + try { final float[] a = sorted().toArray(); @@ -1011,6 +1025,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final float[] a = sorted().toArray(); @@ -1026,6 +1042,8 @@ public Pair>> summarizeA @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final FloatIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractIntStream.java b/src/com/landawn/abacus/util/stream/AbstractIntStream.java index e56ab910..25e0b4d3 100644 --- a/src/com/landawn/abacus/util/stream/AbstractIntStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractIntStream.java @@ -879,6 +879,8 @@ public IntMatrix toMatrix() { @Override public OptionalInt first() { + assertNotClosed(); + try { final IntIterator iter = this.iteratorEx(); @@ -890,6 +892,8 @@ public OptionalInt first() { @Override public OptionalInt last() { + assertNotClosed(); + try { final IntIterator iter = this.iteratorEx(); @@ -911,6 +915,8 @@ public OptionalInt last() { @Override public OptionalInt onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final IntIterator iter = this.iteratorEx(); @@ -934,6 +940,8 @@ public OptionalInt findAny(final Try.IntPredicate predi @Override public OptionalInt findFirstOrLast(Try.IntPredicate predicateForFirst, Try.IntPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final IntIteratorEx iter = iteratorEx(); MutableInt last = null; @@ -961,6 +969,8 @@ public OptionalInt findFirstOrLast(T @Override public Optional> percentiles() { + assertNotClosed(); + try { final int[] a = sorted().toArray(); @@ -976,6 +986,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final int[] a = sorted().toArray(); @@ -991,6 +1003,8 @@ public Pair>> summarizeA @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final IntIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractLongStream.java b/src/com/landawn/abacus/util/stream/AbstractLongStream.java index ddbbc7e1..d15f7d4a 100644 --- a/src/com/landawn/abacus/util/stream/AbstractLongStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractLongStream.java @@ -878,6 +878,8 @@ public LongMatrix toMatrix() { @Override public OptionalLong first() { + assertNotClosed(); + try { final LongIterator iter = this.iteratorEx(); @@ -889,6 +891,8 @@ public OptionalLong first() { @Override public OptionalLong last() { + assertNotClosed(); + try { final LongIterator iter = this.iteratorEx(); @@ -910,6 +914,8 @@ public OptionalLong last() { @Override public OptionalLong onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final LongIterator iter = this.iteratorEx(); @@ -933,6 +939,8 @@ public OptionalLong findAny(final Try.LongPredicate pre @Override public OptionalLong findFirstOrLast(Try.LongPredicate predicateForFirst, Try.LongPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final LongIteratorEx iter = iteratorEx(); MutableLong last = null; @@ -960,6 +968,8 @@ public OptionalLong findFirstOrLast( @Override public Optional> percentiles() { + assertNotClosed(); + try { final long[] a = sorted().toArray(); @@ -975,6 +985,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final long[] a = sorted().toArray(); @@ -990,6 +1002,8 @@ public Pair>> summarizeAnd @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final LongIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractShortStream.java b/src/com/landawn/abacus/util/stream/AbstractShortStream.java index b560b67e..8d46b714 100644 --- a/src/com/landawn/abacus/util/stream/AbstractShortStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractShortStream.java @@ -880,6 +880,8 @@ public ShortMatrix toMatrix() { @Override public OptionalShort first() { + assertNotClosed(); + try { final ShortIterator iter = this.iteratorEx(); @@ -891,6 +893,8 @@ public OptionalShort first() { @Override public OptionalShort last() { + assertNotClosed(); + try { final ShortIterator iter = this.iteratorEx(); @@ -912,6 +916,8 @@ public OptionalShort last() { @Override public OptionalShort onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final ShortIterator iter = this.iteratorEx(); @@ -935,6 +941,8 @@ public OptionalShort findAny(final Try.ShortPredicate p @Override public OptionalShort findFirstOrLast(Try.ShortPredicate predicateForFirst, Try.ShortPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final ShortIteratorEx iter = iteratorEx(); MutableShort last = null; @@ -962,6 +970,8 @@ public OptionalShort findFirstOrLast @Override public Optional> percentiles() { + assertNotClosed(); + try { final short[] a = sorted().toArray(); @@ -977,6 +987,8 @@ public Optional> percentiles() { @Override public Pair>> summarizeAndPercentiles() { + assertNotClosed(); + try { final short[] a = sorted().toArray(); @@ -992,6 +1004,8 @@ public Pair>> summarizeA @Override public String join(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final ShortIteratorEx iter = this.iteratorEx(); diff --git a/src/com/landawn/abacus/util/stream/AbstractStream.java b/src/com/landawn/abacus/util/stream/AbstractStream.java index d7349a28..3f66e262 100644 --- a/src/com/landawn/abacus/util/stream/AbstractStream.java +++ b/src/com/landawn/abacus/util/stream/AbstractStream.java @@ -1333,6 +1333,8 @@ public Optional findAny(final Try.Predicate Optional findFirstOrLast(final Try.Predicate predicateForFirst, final Try.Predicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final ObjIteratorEx iter = iteratorEx(); T last = (T) NONE; @@ -1357,6 +1359,8 @@ public Optional findFirstOrLast(f @Override public Optional findFirstOrLast(final U seed, final Try.BiPredicate predicateForFirst, final Try.BiPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final ObjIteratorEx iter = iteratorEx(); T last = (T) NONE; @@ -1381,6 +1385,8 @@ public Optional findFirstOrLas @Override public Optional findFirstOrLast(final Function preFunc, final Try.BiPredicate predicateForFirst, final Try.BiPredicate predicateForLast) throws E, E2 { + assertNotClosed(); + try { final ObjIteratorEx iter = iteratorEx(); U seed = null; @@ -1407,6 +1413,8 @@ public Optional findFirstOrLas @Override @SafeVarargs public final boolean containsAll(final T... a) { + assertNotClosed(); + try { if (N.isNullOrEmpty(a)) { return true; @@ -1432,6 +1440,8 @@ public boolean test(T t) { @Override public boolean containsAll(final Collection c) { + assertNotClosed(); + try { if (N.isNullOrEmpty(c)) { return true; @@ -1454,6 +1464,8 @@ public boolean test(T t) { @Override public Optional first() { + assertNotClosed(); + try { final Iterator iter = this.iterator(); @@ -1469,6 +1481,8 @@ public Optional first() { @Override public Optional last() { + assertNotClosed(); + try { final Iterator iter = this.iterator(); @@ -1490,6 +1504,8 @@ public Optional last() { @Override public Optional onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final Iterator iter = this.iteratorEx(); @@ -2005,6 +2021,8 @@ public Stream top(int n) { @Override public Optional> percentiles() { + assertNotClosed(); + try { final Object[] a = sorted().toArray(); @@ -2020,6 +2038,8 @@ public Optional> percentiles() { @Override public Optional> percentiles(Comparator comparator) { + assertNotClosed(); + try { final Object[] a = sorted(comparator).toArray(); @@ -2228,6 +2248,8 @@ private void init() { @Override public A[] toArray(IntFunction generator) { + assertNotClosed(); + try { final Object[] src = toArray(); final A[] res = generator.apply(src.length); @@ -2245,6 +2267,8 @@ public DataSet toDataSet() { @Override public DataSet toDataSet(boolean isFirstHeader) { + assertNotClosed(); + try { if (isFirstHeader) { final ObjIterator iter = this.iterator(); @@ -2289,6 +2313,8 @@ public DataSet toDataSet(List columnNames) { @Override public String join(CharSequence delimiter, CharSequence prefix, CharSequence suffix) { + assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, prefix, suffix).reuseCachedBuffer(true); final IteratorEx iter = this.iteratorEx(); @@ -2305,6 +2331,8 @@ public String join(CharSequence delimiter, CharSequence prefix, CharSequence suf @Override public boolean hasDuplicates() { + assertNotClosed(); + try { final Set set = new HashSet<>(); final Iterator iter = iterator(); @@ -2469,6 +2497,8 @@ public long persist(OutputStream os, Try.Function toLine) throws IOException { + assertNotClosed(); + try { final Iterator iter = iterator(); final BufferedWriter bw = writer instanceof BufferedWriter ? (BufferedWriter) writer : Objectory.createBufferedWriter(writer); @@ -2511,6 +2541,7 @@ public long persist(final PreparedStatement stmt, final int batchSize, final int final Try.BiConsumer stmtSetter) throws SQLException { N.checkArgument(batchSize > 0 && batchInterval >= 0, "'batchSize'=%s must be greater than 0 and 'batchInterval'=%s can't be negative", batchSize, batchInterval); + assertNotClosed(); try { final Iterator iter = iterator(); diff --git a/src/com/landawn/abacus/util/stream/ArrayByteStream.java b/src/com/landawn/abacus/util/stream/ArrayByteStream.java index be705ec9..68ba1d84 100644 --- a/src/com/landawn/abacus/util/stream/ArrayByteStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayByteStream.java @@ -894,6 +894,8 @@ public ByteStream skip(long n) { @Override public void forEach(final Try.ByteConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -905,6 +907,8 @@ public void forEach(final Try.ByteConsumer action) thro @Override public byte[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -914,6 +918,8 @@ public byte[] toArray() { @Override public ByteList toByteList() { + assertNotClosed(); + try { return ByteList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -923,6 +929,8 @@ public ByteList toByteList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -938,6 +946,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -953,6 +963,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -968,6 +980,8 @@ public > C toCollection(Supplier supplie @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -983,6 +997,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -998,6 +1014,8 @@ public Multiset toMultiset(Supplier> supplier) { @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1013,6 +1031,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1029,6 +1049,8 @@ public LongMultiset toLongMultiset(Supplier> @Override public > M toMap(ByteFunction keyExtractor, ByteFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1045,6 +1067,8 @@ public > M toMap(ByteFunction keyExtracto @Override public > M toMap(final ByteFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1082,6 +1106,8 @@ public A apply(K k, A v) { @Override public OptionalByte first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalByte.of(elements[fromIndex]) : OptionalByte.empty(); } finally { @@ -1091,6 +1117,8 @@ public OptionalByte first() { @Override public OptionalByte last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalByte.of(elements[toIndex - 1]) : OptionalByte.empty(); } finally { @@ -1100,6 +1128,8 @@ public OptionalByte last() { @Override public OptionalByte onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1117,6 +1147,8 @@ public OptionalByte onlyOne() throws DuplicatedResultException { @Override public byte reduce(byte identity, ByteBinaryOperator op) { + assertNotClosed(); + try { byte result = identity; @@ -1132,6 +1164,8 @@ public byte reduce(byte identity, ByteBinaryOperator op) { @Override public OptionalByte reduce(ByteBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalByte.empty(); @@ -1151,6 +1185,8 @@ public OptionalByte reduce(ByteBinaryOperator op) { @Override public R collect(Supplier supplier, ObjByteConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1194,6 +1230,8 @@ public R collect(Supplier supplier, ObjByteConsumer accumulator, BiCon @Override public OptionalByte min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalByte.empty(); @@ -1209,6 +1247,8 @@ public OptionalByte min() { @Override public OptionalByte max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalByte.empty(); @@ -1225,6 +1265,7 @@ public OptionalByte max() { @Override public OptionalByte kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1241,6 +1282,8 @@ public OptionalByte kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { return sum(elements, fromIndex, toIndex); } finally { @@ -1250,6 +1293,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1263,6 +1308,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1372,6 +1419,8 @@ public byte[] toArray() { @Override public ByteSummaryStatistics summarize() { + assertNotClosed(); + try { final ByteSummaryStatistics result = new ByteSummaryStatistics(); @@ -1387,6 +1436,8 @@ public ByteSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1402,6 +1453,8 @@ public boolean anyMatch(final Try.BytePredicate predica @Override public boolean allMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1417,6 +1470,8 @@ public boolean allMatch(final Try.BytePredicate predica @Override public boolean noneMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1432,6 +1487,8 @@ public boolean noneMatch(final Try.BytePredicate predic @Override public OptionalByte findFirst(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1447,6 +1504,8 @@ public OptionalByte findFirst(final Try.BytePredicate p @Override public OptionalByte findLast(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayCharStream.java b/src/com/landawn/abacus/util/stream/ArrayCharStream.java index 3e50b4f7..78cd442c 100644 --- a/src/com/landawn/abacus/util/stream/ArrayCharStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayCharStream.java @@ -894,6 +894,8 @@ public CharStream skip(long n) { @Override public void forEach(final Try.CharConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -905,6 +907,8 @@ public void forEach(final Try.CharConsumer action) thro @Override public char[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -914,6 +918,8 @@ public char[] toArray() { @Override public CharList toCharList() { + assertNotClosed(); + try { return CharList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -923,6 +929,8 @@ public CharList toCharList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -938,6 +946,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -953,6 +963,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -968,6 +980,8 @@ public > C toCollection(Supplier su @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -983,6 +997,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -998,6 +1014,8 @@ public Multiset toMultiset(Supplier> su @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1013,6 +1031,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1029,6 +1049,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(CharFunction keyExtractor, CharFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1045,6 +1067,8 @@ public > M toMap(CharFunction keyExtracto @Override public > M toMap(final CharFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1082,6 +1106,8 @@ public A apply(K k, A v) { @Override public OptionalChar first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalChar.of(elements[fromIndex]) : OptionalChar.empty(); } finally { @@ -1091,6 +1117,8 @@ public OptionalChar first() { @Override public OptionalChar last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalChar.of(elements[toIndex - 1]) : OptionalChar.empty(); } finally { @@ -1100,6 +1128,8 @@ public OptionalChar last() { @Override public OptionalChar onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1117,6 +1147,8 @@ public OptionalChar onlyOne() throws DuplicatedResultException { @Override public char reduce(char identity, CharBinaryOperator op) { + assertNotClosed(); + try { char result = identity; @@ -1132,6 +1164,8 @@ public char reduce(char identity, CharBinaryOperator op) { @Override public OptionalChar reduce(CharBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalChar.empty(); @@ -1151,6 +1185,8 @@ public OptionalChar reduce(CharBinaryOperator op) { @Override public R collect(Supplier supplier, ObjCharConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1194,6 +1230,8 @@ public R collect(Supplier supplier, ObjCharConsumer accumulator, BiCon @Override public OptionalChar min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalChar.empty(); @@ -1209,6 +1247,8 @@ public OptionalChar min() { @Override public OptionalChar max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalChar.empty(); @@ -1225,6 +1265,7 @@ public OptionalChar max() { @Override public OptionalChar kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1241,6 +1282,8 @@ public OptionalChar kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { return sum(elements, fromIndex, toIndex); } finally { @@ -1250,6 +1293,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1263,6 +1308,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1372,6 +1419,8 @@ public char[] toArray() { @Override public CharSummaryStatistics summarize() { + assertNotClosed(); + try { final CharSummaryStatistics result = new CharSummaryStatistics(); @@ -1387,6 +1436,8 @@ public CharSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1402,6 +1453,8 @@ public boolean anyMatch(final Try.CharPredicate predica @Override public boolean allMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1417,6 +1470,8 @@ public boolean allMatch(final Try.CharPredicate predica @Override public boolean noneMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1432,6 +1487,8 @@ public boolean noneMatch(final Try.CharPredicate predic @Override public OptionalChar findFirst(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1447,6 +1504,8 @@ public OptionalChar findFirst(final Try.CharPredicate p @Override public OptionalChar findLast(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java b/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java index e719dc0c..62d8bc41 100644 --- a/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayDoubleStream.java @@ -1202,6 +1202,8 @@ public DoubleStream skip(long n) { @Override public void forEach(final Try.DoubleConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -1213,6 +1215,8 @@ public void forEach(final Try.DoubleConsumer action) th @Override public double[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -1222,6 +1226,8 @@ public double[] toArray() { @Override public DoubleList toDoubleList() { + assertNotClosed(); + try { return DoubleList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -1231,6 +1237,8 @@ public DoubleList toDoubleList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -1246,6 +1254,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1261,6 +1271,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1276,6 +1288,8 @@ public > C toCollection(Supplier suppl @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1291,6 +1305,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1306,6 +1322,8 @@ public Multiset toMultiset(Supplier> supplier @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1321,6 +1339,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1337,6 +1357,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(DoubleFunction keyExtractor, DoubleFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1353,6 +1375,8 @@ public > M toMap(DoubleFunction keyExtrac @Override public > M toMap(final DoubleFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1390,6 +1414,8 @@ public A apply(K k, A v) { @Override public OptionalDouble first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalDouble.of(elements[fromIndex]) : OptionalDouble.empty(); } finally { @@ -1399,6 +1425,8 @@ public OptionalDouble first() { @Override public OptionalDouble last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalDouble.of(elements[toIndex - 1]) : OptionalDouble.empty(); } finally { @@ -1408,6 +1436,8 @@ public OptionalDouble last() { @Override public OptionalDouble onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1425,6 +1455,8 @@ public OptionalDouble onlyOne() throws DuplicatedResultException { @Override public double reduce(double identity, DoubleBinaryOperator op) { + assertNotClosed(); + try { double result = identity; @@ -1440,6 +1472,8 @@ public double reduce(double identity, DoubleBinaryOperator op) { @Override public OptionalDouble reduce(DoubleBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1459,6 +1493,8 @@ public OptionalDouble reduce(DoubleBinaryOperator op) { @Override public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1502,6 +1538,8 @@ public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiC @Override public OptionalDouble min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1517,6 +1555,8 @@ public OptionalDouble min() { @Override public OptionalDouble max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1533,6 +1573,7 @@ public OptionalDouble max() { @Override public OptionalDouble kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1549,6 +1590,8 @@ public OptionalDouble kthLargest(int k) { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1658,6 +1701,8 @@ public double[] toArray() { @Override public DoubleSummaryStatistics summarize() { + assertNotClosed(); + try { final DoubleSummaryStatistics result = new DoubleSummaryStatistics(); @@ -1673,6 +1718,8 @@ public DoubleSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1688,6 +1735,8 @@ public boolean anyMatch(final Try.DoublePredicate predi @Override public boolean allMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1703,6 +1752,8 @@ public boolean allMatch(final Try.DoublePredicate predi @Override public boolean noneMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1718,6 +1769,8 @@ public boolean noneMatch(final Try.DoublePredicate pred @Override public OptionalDouble findFirst(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1733,6 +1786,8 @@ public OptionalDouble findFirst(final Try.DoublePredicate< @Override public OptionalDouble findLast(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayFloatStream.java b/src/com/landawn/abacus/util/stream/ArrayFloatStream.java index 70f6e894..bcb342c2 100644 --- a/src/com/landawn/abacus/util/stream/ArrayFloatStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayFloatStream.java @@ -1202,6 +1202,8 @@ public FloatStream skip(long n) { @Override public void forEach(final Try.FloatConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -1213,6 +1215,8 @@ public void forEach(final Try.FloatConsumer action) thr @Override public float[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -1222,6 +1226,8 @@ public float[] toArray() { @Override public FloatList toFloatList() { + assertNotClosed(); + try { return FloatList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -1231,6 +1237,8 @@ public FloatList toFloatList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -1246,6 +1254,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1261,6 +1271,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1276,6 +1288,8 @@ public > C toCollection(Supplier suppli @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1291,6 +1305,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1306,6 +1322,8 @@ public Multiset toMultiset(Supplier> supplier) @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1321,6 +1339,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1337,6 +1357,8 @@ public LongMultiset toLongMultiset(Supplier @Override public > M toMap(FloatFunction keyExtractor, FloatFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1353,6 +1375,8 @@ public > M toMap(FloatFunction keyExtract @Override public > M toMap(final FloatFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1390,6 +1414,8 @@ public A apply(K k, A v) { @Override public OptionalFloat first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalFloat.of(elements[fromIndex]) : OptionalFloat.empty(); } finally { @@ -1399,6 +1425,8 @@ public OptionalFloat first() { @Override public OptionalFloat last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalFloat.of(elements[toIndex - 1]) : OptionalFloat.empty(); } finally { @@ -1408,6 +1436,8 @@ public OptionalFloat last() { @Override public OptionalFloat onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1425,6 +1455,8 @@ public OptionalFloat onlyOne() throws DuplicatedResultException { @Override public float reduce(float identity, FloatBinaryOperator op) { + assertNotClosed(); + try { float result = identity; @@ -1440,6 +1472,8 @@ public float reduce(float identity, FloatBinaryOperator op) { @Override public OptionalFloat reduce(FloatBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalFloat.empty(); @@ -1459,6 +1493,8 @@ public OptionalFloat reduce(FloatBinaryOperator op) { @Override public R collect(Supplier supplier, ObjFloatConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1502,6 +1538,8 @@ public R collect(Supplier supplier, ObjFloatConsumer accumulator, BiCo @Override public OptionalFloat min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalFloat.empty(); @@ -1517,6 +1555,8 @@ public OptionalFloat min() { @Override public OptionalFloat max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalFloat.empty(); @@ -1533,6 +1573,7 @@ public OptionalFloat max() { @Override public OptionalFloat kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1549,6 +1590,8 @@ public OptionalFloat kthLargest(int k) { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1658,6 +1701,8 @@ public float[] toArray() { @Override public FloatSummaryStatistics summarize() { + assertNotClosed(); + try { final FloatSummaryStatistics result = new FloatSummaryStatistics(); @@ -1673,6 +1718,8 @@ public FloatSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1688,6 +1735,8 @@ public boolean anyMatch(final Try.FloatPredicate predic @Override public boolean allMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1703,6 +1752,8 @@ public boolean allMatch(final Try.FloatPredicate predic @Override public boolean noneMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1718,6 +1769,8 @@ public boolean noneMatch(final Try.FloatPredicate predi @Override public OptionalFloat findFirst(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1733,6 +1786,8 @@ public OptionalFloat findFirst(final Try.FloatPredicate @Override public OptionalFloat findLast(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayIntStream.java b/src/com/landawn/abacus/util/stream/ArrayIntStream.java index 9e97fe4a..33f91d3f 100644 --- a/src/com/landawn/abacus/util/stream/ArrayIntStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayIntStream.java @@ -1539,6 +1539,8 @@ public IntStream skip(long n) { @Override public void forEach(final Try.IntConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -1550,6 +1552,8 @@ public void forEach(final Try.IntConsumer action) throw @Override public int[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -1559,6 +1563,8 @@ public int[] toArray() { @Override public IntList toIntList() { + assertNotClosed(); + try { return IntList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -1568,6 +1574,8 @@ public IntList toIntList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -1583,6 +1591,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1598,6 +1608,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1613,6 +1625,8 @@ public > C toCollection(Supplier supp @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1628,6 +1642,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1643,6 +1659,8 @@ public Multiset toMultiset(Supplier> suppli @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1658,6 +1676,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1674,6 +1694,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(IntFunction keyExtractor, IntFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1690,6 +1712,8 @@ public > M toMap(IntFunction keyExtractor @Override public > M toMap(final IntFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1727,6 +1751,8 @@ public A apply(K k, A v) { @Override public OptionalInt first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalInt.of(elements[fromIndex]) : OptionalInt.empty(); } finally { @@ -1736,6 +1762,8 @@ public OptionalInt first() { @Override public OptionalInt last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalInt.of(elements[toIndex - 1]) : OptionalInt.empty(); } finally { @@ -1745,6 +1773,8 @@ public OptionalInt last() { @Override public OptionalInt onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1762,6 +1792,8 @@ public OptionalInt onlyOne() throws DuplicatedResultException { @Override public int reduce(int identity, IntBinaryOperator op) { + assertNotClosed(); + try { int result = identity; @@ -1777,6 +1809,8 @@ public int reduce(int identity, IntBinaryOperator op) { @Override public OptionalInt reduce(IntBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalInt.empty(); @@ -1796,6 +1830,8 @@ public OptionalInt reduce(IntBinaryOperator op) { @Override public R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1839,6 +1875,8 @@ public R collect(Supplier supplier, ObjIntConsumer accumulator, BiCons @Override public OptionalInt min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalInt.empty(); @@ -1854,6 +1892,8 @@ public OptionalInt min() { @Override public OptionalInt max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalInt.empty(); @@ -1870,6 +1910,7 @@ public OptionalInt max() { @Override public OptionalInt kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1886,6 +1927,8 @@ public OptionalInt kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { return sum(elements, fromIndex, toIndex); } finally { @@ -1895,6 +1938,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1908,6 +1953,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -2017,6 +2064,8 @@ public int[] toArray() { @Override public IntSummaryStatistics summarize() { + assertNotClosed(); + try { final IntSummaryStatistics result = new IntSummaryStatistics(); @@ -2032,6 +2081,8 @@ public IntSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2047,6 +2098,8 @@ public boolean anyMatch(final Try.IntPredicate predicat @Override public boolean allMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -2062,6 +2115,8 @@ public boolean allMatch(final Try.IntPredicate predicat @Override public boolean noneMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2077,6 +2132,8 @@ public boolean noneMatch(final Try.IntPredicate predica @Override public OptionalInt findFirst(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2092,6 +2149,8 @@ public OptionalInt findFirst(final Try.IntPredicate pre @Override public OptionalInt findLast(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayLongStream.java b/src/com/landawn/abacus/util/stream/ArrayLongStream.java index acb95a64..8e264bff 100644 --- a/src/com/landawn/abacus/util/stream/ArrayLongStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayLongStream.java @@ -1203,6 +1203,8 @@ public LongStream skip(long n) { @Override public void forEach(final Try.LongConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -1214,6 +1216,8 @@ public void forEach(final Try.LongConsumer action) thro @Override public long[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -1223,6 +1227,8 @@ public long[] toArray() { @Override public LongList toLongList() { + assertNotClosed(); + try { return LongList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -1232,6 +1238,8 @@ public LongList toLongList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -1247,6 +1255,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1262,6 +1272,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1277,6 +1289,8 @@ public > C toCollection(Supplier supplie @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1292,6 +1306,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1307,6 +1323,8 @@ public Multiset toMultiset(Supplier> supplier) { @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1322,6 +1340,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1338,6 +1358,8 @@ public LongMultiset toLongMultiset(Supplier> @Override public > M toMap(LongFunction keyExtractor, LongFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1354,6 +1376,8 @@ public > M toMap(LongFunction keyExtracto @Override public > M toMap(final LongFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1391,6 +1415,8 @@ public A apply(K k, A v) { @Override public OptionalLong first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalLong.of(elements[fromIndex]) : OptionalLong.empty(); } finally { @@ -1400,6 +1426,8 @@ public OptionalLong first() { @Override public OptionalLong last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalLong.of(elements[toIndex - 1]) : OptionalLong.empty(); } finally { @@ -1409,6 +1437,8 @@ public OptionalLong last() { @Override public OptionalLong onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1426,6 +1456,8 @@ public OptionalLong onlyOne() throws DuplicatedResultException { @Override public long reduce(long identity, LongBinaryOperator op) { + assertNotClosed(); + try { long result = identity; @@ -1441,6 +1473,8 @@ public long reduce(long identity, LongBinaryOperator op) { @Override public OptionalLong reduce(LongBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalLong.empty(); @@ -1460,6 +1494,8 @@ public OptionalLong reduce(LongBinaryOperator op) { @Override public R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1503,6 +1539,8 @@ public R collect(Supplier supplier, ObjLongConsumer accumulator, BiCon @Override public OptionalLong min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalLong.empty(); @@ -1518,6 +1556,8 @@ public OptionalLong min() { @Override public OptionalLong max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalLong.empty(); @@ -1534,6 +1574,7 @@ public OptionalLong max() { @Override public OptionalLong kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1550,6 +1591,8 @@ public OptionalLong kthLargest(int k) { @Override public long sum() { + assertNotClosed(); + try { return sum(elements, fromIndex, toIndex); } finally { @@ -1559,6 +1602,8 @@ public long sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1572,6 +1617,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1681,6 +1728,8 @@ public long[] toArray() { @Override public LongSummaryStatistics summarize() { + assertNotClosed(); + try { final LongSummaryStatistics result = new LongSummaryStatistics(); @@ -1696,6 +1745,8 @@ public LongSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1711,6 +1762,8 @@ public boolean anyMatch(final Try.LongPredicate predica @Override public boolean allMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1726,6 +1779,8 @@ public boolean allMatch(final Try.LongPredicate predica @Override public boolean noneMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1741,6 +1796,8 @@ public boolean noneMatch(final Try.LongPredicate predic @Override public OptionalLong findFirst(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1756,6 +1813,8 @@ public OptionalLong findFirst(final Try.LongPredicate p @Override public OptionalLong findLast(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayShortStream.java b/src/com/landawn/abacus/util/stream/ArrayShortStream.java index 089c2de9..1bb56cce 100644 --- a/src/com/landawn/abacus/util/stream/ArrayShortStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayShortStream.java @@ -979,6 +979,8 @@ public ShortStream skip(long n) { @Override public void forEach(final Try.ShortConsumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -990,6 +992,8 @@ public void forEach(final Try.ShortConsumer action) thr @Override public short[] toArray() { + assertNotClosed(); + try { return N.copyOfRange(elements, fromIndex, toIndex); } finally { @@ -999,6 +1003,8 @@ public short[] toArray() { @Override public ShortList toShortList() { + assertNotClosed(); + try { return ShortList.of(N.copyOfRange(elements, fromIndex, toIndex)); } finally { @@ -1008,6 +1014,8 @@ public ShortList toShortList() { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(toIndex - fromIndex); @@ -1023,6 +1031,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1038,6 +1048,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1053,6 +1065,8 @@ public > C toCollection(Supplier suppli @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1068,6 +1082,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1083,6 +1099,8 @@ public Multiset toMultiset(Supplier> supplier) @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -1098,6 +1116,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1114,6 +1134,8 @@ public LongMultiset toLongMultiset(Supplier @Override public > M toMap(ShortFunction keyExtractor, ShortFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -1130,6 +1152,8 @@ public > M toMap(ShortFunction keyExtract @Override public > M toMap(final ShortFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1167,6 +1191,8 @@ public A apply(K k, A v) { @Override public OptionalShort first() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalShort.of(elements[fromIndex]) : OptionalShort.empty(); } finally { @@ -1176,6 +1202,8 @@ public OptionalShort first() { @Override public OptionalShort last() { + assertNotClosed(); + try { return fromIndex < toIndex ? OptionalShort.of(elements[toIndex - 1]) : OptionalShort.empty(); } finally { @@ -1185,6 +1213,8 @@ public OptionalShort last() { @Override public OptionalShort onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -1202,6 +1232,8 @@ public OptionalShort onlyOne() throws DuplicatedResultException { @Override public short reduce(short identity, ShortBinaryOperator op) { + assertNotClosed(); + try { short result = identity; @@ -1217,6 +1249,8 @@ public short reduce(short identity, ShortBinaryOperator op) { @Override public OptionalShort reduce(ShortBinaryOperator op) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalShort.empty(); @@ -1236,6 +1270,8 @@ public OptionalShort reduce(ShortBinaryOperator op) { @Override public R collect(Supplier supplier, ObjShortConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1279,6 +1315,8 @@ public R collect(Supplier supplier, ObjShortConsumer accumulator, BiCo @Override public OptionalShort min() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalShort.empty(); @@ -1294,6 +1332,8 @@ public OptionalShort min() { @Override public OptionalShort max() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalShort.empty(); @@ -1310,6 +1350,7 @@ public OptionalShort max() { @Override public OptionalShort kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -1326,6 +1367,8 @@ public OptionalShort kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { return sum(elements, fromIndex, toIndex); } finally { @@ -1335,6 +1378,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); @@ -1348,6 +1393,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -1457,6 +1504,8 @@ public short[] toArray() { @Override public ShortSummaryStatistics summarize() { + assertNotClosed(); + try { final ShortSummaryStatistics result = new ShortSummaryStatistics(); @@ -1472,6 +1521,8 @@ public ShortSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1487,6 +1538,8 @@ public boolean anyMatch(final Try.ShortPredicate predic @Override public boolean allMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -1502,6 +1555,8 @@ public boolean allMatch(final Try.ShortPredicate predic @Override public boolean noneMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1517,6 +1572,8 @@ public boolean noneMatch(final Try.ShortPredicate predi @Override public OptionalShort findFirst(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -1532,6 +1589,8 @@ public OptionalShort findFirst(final Try.ShortPredicate @Override public OptionalShort findLast(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/ArrayStream.java b/src/com/landawn/abacus/util/stream/ArrayStream.java index 82f12a62..c188b46d 100644 --- a/src/com/landawn/abacus/util/stream/ArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ArrayStream.java @@ -2124,6 +2124,8 @@ public Stream skip(long n) { @Override public void forEach(Try.Consumer action) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { action.accept(elements[i]); @@ -2137,6 +2139,7 @@ public void forEach(Try.Consumer action) thr public void forEachPair(final Try.BiConsumer action, final int increment) throws E { final int windowSize = 2; N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + assertNotClosed(); try { int cursor = fromIndex; @@ -2155,6 +2158,7 @@ public void forEachPair(final Try.BiConsumer void forEachTriple(final Try.TriConsumer action, final int increment) throws E { final int windowSize = 3; N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + assertNotClosed(); try { int cursor = fromIndex; @@ -2171,6 +2175,8 @@ public void forEachTriple(final Try.TriConsumer A[] toArray(A[] a) { + assertNotClosed(); + try { if (a.length < (toIndex - fromIndex)) { a = N.newArray(a.getClass().getComponentType(), toIndex - fromIndex); @@ -2194,6 +2202,8 @@ A[] toArray(A[] a) { @Override public A[] toArray(IntFunction generator) { + assertNotClosed(); + try { return toArray(generator.apply(toIndex - fromIndex)); } finally { @@ -2203,6 +2213,8 @@ public A[] toArray(IntFunction generator) { @Override public List toList() { + assertNotClosed(); + try { // return N.asList(N.copyOfRange(elements, fromIndex, toIndex)); @@ -2224,6 +2236,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(N.initHashCapacity(toIndex - fromIndex)); @@ -2239,6 +2253,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -2254,6 +2270,8 @@ public > C toCollection(Supplier supplier) @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -2269,6 +2287,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -2284,6 +2304,8 @@ public Multiset toMultiset(Supplier> supplier) { @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(N.initHashCapacity(toIndex - fromIndex)); @@ -2299,6 +2321,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -2315,6 +2339,8 @@ public LongMultiset toLongMultiset(Supplier> suppli @Override public > M toMap(Function keyExtractor, Function valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -2331,6 +2357,8 @@ public > M toMap(Function keyE @Override public > M toMap(final Function classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -2370,6 +2398,8 @@ public A apply(K k, A v) { @Override public , M extends Multimap> M toMultimap(Function keyExtractor, Function valueMapper, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); @@ -2385,6 +2415,8 @@ public , M extends Multimap> M toMultimap @Override public Optional first() { + assertNotClosed(); + try { return fromIndex < toIndex ? Optional.of(elements[fromIndex]) : Optional. empty(); } finally { @@ -2394,6 +2426,8 @@ public Optional first() { @Override public Optional last() { + assertNotClosed(); + try { return fromIndex < toIndex ? Optional.of(elements[toIndex - 1]) : Optional. empty(); } finally { @@ -2403,6 +2437,8 @@ public Optional last() { @Override public Optional onlyOne() throws DuplicatedResultException { + assertNotClosed(); + try { final int size = toIndex - fromIndex; @@ -2420,6 +2456,8 @@ public Optional onlyOne() throws DuplicatedResultException { @Override public T reduce(T identity, BinaryOperator accumulator) { + assertNotClosed(); + try { T result = identity; @@ -2435,6 +2473,8 @@ public T reduce(T identity, BinaryOperator accumulator) { @Override public Optional reduce(BinaryOperator accumulator) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return Optional.empty(); @@ -2454,6 +2494,8 @@ public Optional reduce(BinaryOperator accumulator) { @Override public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -2469,6 +2511,8 @@ public R collect(Supplier supplier, BiConsumer accumulator, @Override public R collect(Collector collector) { + assertNotClosed(); + try { final A container = collector.supplier().get(); final BiConsumer accumulator = collector.accumulator(); @@ -2535,6 +2579,8 @@ public Stream skipLast(int n) { @Override public Optional min(Comparator comparator) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return Optional.empty(); @@ -2550,6 +2596,8 @@ public Optional min(Comparator comparator) { @Override public Optional max(Comparator comparator) { + assertNotClosed(); + try { if (fromIndex == toIndex) { return Optional.empty(); @@ -2566,6 +2614,7 @@ public Optional max(Comparator comparator) { @Override public Optional kthLargest(int k, Comparator comparator) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (k > toIndex - fromIndex) { @@ -2582,6 +2631,8 @@ public Optional kthLargest(int k, Comparator comparator) { @Override public long count() { + assertNotClosed(); + try { return toIndex - fromIndex; } finally { @@ -2692,6 +2743,8 @@ public A[] toArray(A[] a) { @Override public boolean anyMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2707,6 +2760,8 @@ public boolean anyMatch(final Try.Predicate @Override public boolean allMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i]) == false) { @@ -2722,6 +2777,8 @@ public boolean allMatch(final Try.Predicate @Override public boolean noneMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2737,6 +2794,8 @@ public boolean noneMatch(final Try.Predicate @Override public Optional findFirst(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { for (int i = fromIndex; i < toIndex; i++) { if (predicate.test(elements[i])) { @@ -2752,6 +2811,8 @@ public Optional findFirst(final Try.Predicate Optional findLast(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { for (int i = toIndex - 1; i >= fromIndex; i--) { if (predicate.test(elements[i])) { diff --git a/src/com/landawn/abacus/util/stream/EntryStream.java b/src/com/landawn/abacus/util/stream/EntryStream.java index 1b336e4a..a9ebfb17 100644 --- a/src/com/landawn/abacus/util/stream/EntryStream.java +++ b/src/com/landawn/abacus/util/stream/EntryStream.java @@ -1399,6 +1399,8 @@ public String join(CharSequence delimiter, CharSequence keyValueDelimiter) { @SequentialOnly public String join(CharSequence delimiter, CharSequence keyValueDelimiter, CharSequence prefix, CharSequence suffix) { + s.assertNotClosed(); + try { final Joiner joiner = Joiner.with(delimiter, keyValueDelimiter, prefix, suffix).reuseCachedBuffer(true); final Iterator> iter = this.iterator(); diff --git a/src/com/landawn/abacus/util/stream/IteratorByteStream.java b/src/com/landawn/abacus/util/stream/IteratorByteStream.java index e5ebb9a4..b9c89f11 100644 --- a/src/com/landawn/abacus/util/stream/IteratorByteStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorByteStream.java @@ -735,6 +735,8 @@ public byte[] toArray() { @Override public void forEach(final Try.ByteConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextByte()); @@ -746,6 +748,8 @@ public void forEach(final Try.ByteConsumer action) thro @Override public byte[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -755,6 +759,8 @@ public byte[] toArray() { @Override public ByteList toByteList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -774,6 +780,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -794,6 +802,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -814,6 +824,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -830,6 +842,8 @@ public LongMultiset toLongMultiset(Supplier> @Override public > M toMap(ByteFunction keyExtractor, ByteFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); byte element = 0; @@ -848,6 +862,8 @@ public > M toMap(ByteFunction keyExtracto @Override public > M toMap(final ByteFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -887,6 +903,8 @@ public A apply(K k, A v) { @Override public byte reduce(byte identity, ByteBinaryOperator op) { + assertNotClosed(); + try { byte result = identity; @@ -902,6 +920,8 @@ public byte reduce(byte identity, ByteBinaryOperator op) { @Override public OptionalByte reduce(ByteBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalByte.empty(); @@ -921,6 +941,8 @@ public OptionalByte reduce(ByteBinaryOperator op) { @Override public R collect(Supplier supplier, ObjByteConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -978,6 +1000,8 @@ public R collect(Supplier supplier, ObjByteConsumer accumulator, BiCon @Override public OptionalByte min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalByte.empty(); @@ -1004,6 +1028,8 @@ public OptionalByte min() { @Override public OptionalByte max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalByte.empty(); @@ -1037,6 +1063,7 @@ public OptionalByte max() { @Override public OptionalByte kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1053,6 +1080,8 @@ public OptionalByte kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { long result = 0; @@ -1068,6 +1097,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1089,6 +1120,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1098,6 +1131,8 @@ public long count() { @Override public ByteSummaryStatistics summarize() { + assertNotClosed(); + try { final ByteSummaryStatistics result = new ByteSummaryStatistics(); @@ -1113,6 +1148,8 @@ public ByteSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextByte())) { @@ -1128,6 +1165,8 @@ public boolean anyMatch(final Try.BytePredicate predica @Override public boolean allMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextByte()) == false) { @@ -1143,6 +1182,8 @@ public boolean allMatch(final Try.BytePredicate predica @Override public boolean noneMatch(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextByte())) { @@ -1158,6 +1199,8 @@ public boolean noneMatch(final Try.BytePredicate predic @Override public OptionalByte findFirst(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { byte e = elements.nextByte(); @@ -1175,6 +1218,8 @@ public OptionalByte findFirst(final Try.BytePredicate p @Override public OptionalByte findLast(final Try.BytePredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalByte.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorCharStream.java b/src/com/landawn/abacus/util/stream/IteratorCharStream.java index 79223026..290dcdfb 100644 --- a/src/com/landawn/abacus/util/stream/IteratorCharStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorCharStream.java @@ -735,6 +735,8 @@ public char[] toArray() { @Override public void forEach(final Try.CharConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextChar()); @@ -746,6 +748,8 @@ public void forEach(final Try.CharConsumer action) thro @Override public char[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -755,6 +759,8 @@ public char[] toArray() { @Override public CharList toCharList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -774,6 +780,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -794,6 +802,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -814,6 +824,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -830,6 +842,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(CharFunction keyExtractor, CharFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); char element = 0; @@ -848,6 +862,8 @@ public > M toMap(CharFunction keyExtracto @Override public > M toMap(final CharFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -887,6 +903,8 @@ public A apply(K k, A v) { @Override public char reduce(char identity, CharBinaryOperator op) { + assertNotClosed(); + try { char result = identity; @@ -902,6 +920,8 @@ public char reduce(char identity, CharBinaryOperator op) { @Override public OptionalChar reduce(CharBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalChar.empty(); @@ -921,6 +941,8 @@ public OptionalChar reduce(CharBinaryOperator op) { @Override public R collect(Supplier supplier, ObjCharConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -978,6 +1000,8 @@ public R collect(Supplier supplier, ObjCharConsumer accumulator, BiCon @Override public OptionalChar min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalChar.empty(); @@ -1004,6 +1028,8 @@ public OptionalChar min() { @Override public OptionalChar max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalChar.empty(); @@ -1037,6 +1063,7 @@ public OptionalChar max() { @Override public OptionalChar kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1053,6 +1080,8 @@ public OptionalChar kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { long result = 0; @@ -1068,6 +1097,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1089,6 +1120,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1098,6 +1131,8 @@ public long count() { @Override public CharSummaryStatistics summarize() { + assertNotClosed(); + try { final CharSummaryStatistics result = new CharSummaryStatistics(); @@ -1113,6 +1148,8 @@ public CharSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextChar())) { @@ -1128,6 +1165,8 @@ public boolean anyMatch(final Try.CharPredicate predica @Override public boolean allMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextChar()) == false) { @@ -1143,6 +1182,8 @@ public boolean allMatch(final Try.CharPredicate predica @Override public boolean noneMatch(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextChar())) { @@ -1158,6 +1199,8 @@ public boolean noneMatch(final Try.CharPredicate predic @Override public OptionalChar findFirst(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { char e = elements.nextChar(); @@ -1175,6 +1218,8 @@ public OptionalChar findFirst(final Try.CharPredicate p @Override public OptionalChar findLast(final Try.CharPredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalChar.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java b/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java index 43ed2f8b..33f43019 100644 --- a/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorDoubleStream.java @@ -1043,6 +1043,8 @@ public double[] toArray() { @Override public void forEach(final Try.DoubleConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextDouble()); @@ -1054,6 +1056,8 @@ public void forEach(final Try.DoubleConsumer action) th @Override public double[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -1063,6 +1067,8 @@ public double[] toArray() { @Override public DoubleList toDoubleList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -1082,6 +1088,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1102,6 +1110,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1122,6 +1132,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1138,6 +1150,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(DoubleFunction keyExtractor, DoubleFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); double element = 0; @@ -1156,6 +1170,8 @@ public > M toMap(DoubleFunction keyExtrac @Override public > M toMap(final DoubleFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1195,6 +1211,8 @@ public A apply(K k, A v) { @Override public double reduce(double identity, DoubleBinaryOperator op) { + assertNotClosed(); + try { double result = identity; @@ -1210,6 +1228,8 @@ public double reduce(double identity, DoubleBinaryOperator op) { @Override public OptionalDouble reduce(DoubleBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1229,6 +1249,8 @@ public OptionalDouble reduce(DoubleBinaryOperator op) { @Override public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1286,6 +1308,8 @@ public R collect(Supplier supplier, ObjDoubleConsumer accumulator, BiC @Override public OptionalDouble min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1312,6 +1336,8 @@ public OptionalDouble min() { @Override public OptionalDouble max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1345,6 +1371,7 @@ public OptionalDouble max() { @Override public OptionalDouble kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1361,6 +1388,8 @@ public OptionalDouble kthLargest(int k) { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1370,6 +1399,8 @@ public long count() { @Override public DoubleSummaryStatistics summarize() { + assertNotClosed(); + try { final DoubleSummaryStatistics result = new DoubleSummaryStatistics(); @@ -1385,6 +1416,8 @@ public DoubleSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextDouble())) { @@ -1400,6 +1433,8 @@ public boolean anyMatch(final Try.DoublePredicate predi @Override public boolean allMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextDouble()) == false) { @@ -1415,6 +1450,8 @@ public boolean allMatch(final Try.DoublePredicate predi @Override public boolean noneMatch(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextDouble())) { @@ -1430,6 +1467,8 @@ public boolean noneMatch(final Try.DoublePredicate pred @Override public OptionalDouble findFirst(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { double e = elements.nextDouble(); @@ -1447,6 +1486,8 @@ public OptionalDouble findFirst(final Try.DoublePredicate< @Override public OptionalDouble findLast(final Try.DoublePredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorFloatStream.java b/src/com/landawn/abacus/util/stream/IteratorFloatStream.java index f1f51545..1d4beb8f 100644 --- a/src/com/landawn/abacus/util/stream/IteratorFloatStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorFloatStream.java @@ -1039,6 +1039,8 @@ public float[] toArray() { @Override public void forEach(final Try.FloatConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextFloat()); @@ -1050,6 +1052,8 @@ public void forEach(final Try.FloatConsumer action) thr @Override public float[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -1059,6 +1063,8 @@ public float[] toArray() { @Override public FloatList toFloatList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -1078,6 +1084,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1098,6 +1106,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1118,6 +1128,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1134,6 +1146,8 @@ public LongMultiset toLongMultiset(Supplier @Override public > M toMap(FloatFunction keyExtractor, FloatFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); float element = 0; @@ -1152,6 +1166,8 @@ public > M toMap(FloatFunction keyExtract @Override public > M toMap(final FloatFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1191,6 +1207,8 @@ public A apply(K k, A v) { @Override public float reduce(float identity, FloatBinaryOperator op) { + assertNotClosed(); + try { float result = identity; @@ -1206,6 +1224,8 @@ public float reduce(float identity, FloatBinaryOperator op) { @Override public OptionalFloat reduce(FloatBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalFloat.empty(); @@ -1225,6 +1245,8 @@ public OptionalFloat reduce(FloatBinaryOperator op) { @Override public R collect(Supplier supplier, ObjFloatConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1282,6 +1304,8 @@ public R collect(Supplier supplier, ObjFloatConsumer accumulator, BiCo @Override public OptionalFloat min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalFloat.empty(); @@ -1308,6 +1332,8 @@ public OptionalFloat min() { @Override public OptionalFloat max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalFloat.empty(); @@ -1341,6 +1367,7 @@ public OptionalFloat max() { @Override public OptionalFloat kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1357,6 +1384,8 @@ public OptionalFloat kthLargest(int k) { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1366,6 +1395,8 @@ public long count() { @Override public FloatSummaryStatistics summarize() { + assertNotClosed(); + try { final FloatSummaryStatistics result = new FloatSummaryStatistics(); @@ -1381,6 +1412,8 @@ public FloatSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextFloat())) { @@ -1396,6 +1429,8 @@ public boolean anyMatch(final Try.FloatPredicate predic @Override public boolean allMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextFloat()) == false) { @@ -1411,6 +1446,8 @@ public boolean allMatch(final Try.FloatPredicate predic @Override public boolean noneMatch(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextFloat())) { @@ -1426,6 +1463,8 @@ public boolean noneMatch(final Try.FloatPredicate predi @Override public OptionalFloat findFirst(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { float e = elements.nextFloat(); @@ -1443,6 +1482,8 @@ public OptionalFloat findFirst(final Try.FloatPredicate @Override public OptionalFloat findLast(final Try.FloatPredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalFloat.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorIntStream.java b/src/com/landawn/abacus/util/stream/IteratorIntStream.java index 47ded138..9ca191ed 100644 --- a/src/com/landawn/abacus/util/stream/IteratorIntStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorIntStream.java @@ -1327,6 +1327,8 @@ public int[] toArray() { @Override public void forEach(final Try.IntConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextInt()); @@ -1338,6 +1340,8 @@ public void forEach(final Try.IntConsumer action) throw @Override public int[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -1347,6 +1351,8 @@ public int[] toArray() { @Override public IntList toIntList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -1366,6 +1372,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1386,6 +1394,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1406,6 +1416,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1422,6 +1434,8 @@ public LongMultiset toLongMultiset(Supplier> M toMap(IntFunction keyExtractor, IntFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); int element = 0; @@ -1440,6 +1454,8 @@ public > M toMap(IntFunction keyExtractor @Override public > M toMap(final IntFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1479,6 +1495,8 @@ public A apply(K k, A v) { @Override public int reduce(int identity, IntBinaryOperator op) { + assertNotClosed(); + try { int result = identity; @@ -1494,6 +1512,8 @@ public int reduce(int identity, IntBinaryOperator op) { @Override public OptionalInt reduce(IntBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalInt.empty(); @@ -1513,6 +1533,8 @@ public OptionalInt reduce(IntBinaryOperator op) { @Override public R collect(Supplier supplier, ObjIntConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1570,6 +1592,8 @@ public R collect(Supplier supplier, ObjIntConsumer accumulator, BiCons @Override public OptionalInt min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalInt.empty(); @@ -1596,6 +1620,8 @@ public OptionalInt min() { @Override public OptionalInt max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalInt.empty(); @@ -1629,6 +1655,7 @@ public OptionalInt max() { @Override public OptionalInt kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1645,6 +1672,8 @@ public OptionalInt kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { long result = 0; @@ -1660,6 +1689,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1681,6 +1712,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1690,6 +1723,8 @@ public long count() { @Override public IntSummaryStatistics summarize() { + assertNotClosed(); + try { final IntSummaryStatistics result = new IntSummaryStatistics(); @@ -1705,6 +1740,8 @@ public IntSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextInt())) { @@ -1720,6 +1757,8 @@ public boolean anyMatch(final Try.IntPredicate predicat @Override public boolean allMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextInt()) == false) { @@ -1735,6 +1774,8 @@ public boolean allMatch(final Try.IntPredicate predicat @Override public boolean noneMatch(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextInt())) { @@ -1750,6 +1791,8 @@ public boolean noneMatch(final Try.IntPredicate predica @Override public OptionalInt findFirst(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { int e = elements.nextInt(); @@ -1767,6 +1810,8 @@ public OptionalInt findFirst(final Try.IntPredicate pre @Override public OptionalInt findLast(final Try.IntPredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalInt.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorLongStream.java b/src/com/landawn/abacus/util/stream/IteratorLongStream.java index d403436c..a4047845 100644 --- a/src/com/landawn/abacus/util/stream/IteratorLongStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorLongStream.java @@ -1044,6 +1044,8 @@ public long[] toArray() { @Override public void forEach(final Try.LongConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextLong()); @@ -1055,6 +1057,8 @@ public void forEach(final Try.LongConsumer action) thro @Override public long[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -1064,6 +1068,8 @@ public long[] toArray() { @Override public LongList toLongList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -1083,6 +1089,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1103,6 +1111,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1123,6 +1133,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1139,6 +1151,8 @@ public LongMultiset toLongMultiset(Supplier> @Override public > M toMap(LongFunction keyExtractor, LongFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); long element = 0; @@ -1157,6 +1171,8 @@ public > M toMap(LongFunction keyExtracto @Override public > M toMap(final LongFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1196,6 +1212,8 @@ public A apply(K k, A v) { @Override public long reduce(long identity, LongBinaryOperator op) { + assertNotClosed(); + try { long result = identity; @@ -1211,6 +1229,8 @@ public long reduce(long identity, LongBinaryOperator op) { @Override public OptionalLong reduce(LongBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalLong.empty(); @@ -1230,6 +1250,8 @@ public OptionalLong reduce(LongBinaryOperator op) { @Override public R collect(Supplier supplier, ObjLongConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1287,6 +1309,8 @@ public R collect(Supplier supplier, ObjLongConsumer accumulator, BiCon @Override public OptionalLong min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalLong.empty(); @@ -1313,6 +1337,8 @@ public OptionalLong min() { @Override public OptionalLong max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalLong.empty(); @@ -1346,6 +1372,7 @@ public OptionalLong max() { @Override public OptionalLong kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1362,6 +1389,8 @@ public OptionalLong kthLargest(int k) { @Override public long sum() { + assertNotClosed(); + try { long result = 0; @@ -1377,6 +1406,8 @@ public long sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1398,6 +1429,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1407,6 +1440,8 @@ public long count() { @Override public LongSummaryStatistics summarize() { + assertNotClosed(); + try { final LongSummaryStatistics result = new LongSummaryStatistics(); @@ -1422,6 +1457,8 @@ public LongSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextLong())) { @@ -1437,6 +1474,8 @@ public boolean anyMatch(final Try.LongPredicate predica @Override public boolean allMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextLong()) == false) { @@ -1452,6 +1491,8 @@ public boolean allMatch(final Try.LongPredicate predica @Override public boolean noneMatch(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextLong())) { @@ -1467,6 +1508,8 @@ public boolean noneMatch(final Try.LongPredicate predic @Override public OptionalLong findFirst(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { long e = elements.nextLong(); @@ -1484,6 +1527,8 @@ public OptionalLong findFirst(final Try.LongPredicate p @Override public OptionalLong findLast(final Try.LongPredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalLong.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorShortStream.java b/src/com/landawn/abacus/util/stream/IteratorShortStream.java index 2d4f5b0e..7a0e76f2 100644 --- a/src/com/landawn/abacus/util/stream/IteratorShortStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorShortStream.java @@ -854,6 +854,8 @@ public short[] toArray() { @Override public void forEach(final Try.ShortConsumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.nextShort()); @@ -865,6 +867,8 @@ public void forEach(final Try.ShortConsumer action) thr @Override public short[] toArray() { + assertNotClosed(); + try { return elements.toArray(); } finally { @@ -874,6 +878,8 @@ public short[] toArray() { @Override public ShortList toShortList() { + assertNotClosed(); + try { return elements.toList(); } finally { @@ -893,6 +899,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -913,6 +921,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -933,6 +943,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -949,6 +961,8 @@ public LongMultiset toLongMultiset(Supplier @Override public > M toMap(ShortFunction keyExtractor, ShortFunction valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); short element = 0; @@ -967,6 +981,8 @@ public > M toMap(ShortFunction keyExtract @Override public > M toMap(final ShortFunction classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -1006,6 +1022,8 @@ public A apply(K k, A v) { @Override public short reduce(short identity, ShortBinaryOperator op) { + assertNotClosed(); + try { short result = identity; @@ -1021,6 +1039,8 @@ public short reduce(short identity, ShortBinaryOperator op) { @Override public OptionalShort reduce(ShortBinaryOperator op) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalShort.empty(); @@ -1040,6 +1060,8 @@ public OptionalShort reduce(ShortBinaryOperator op) { @Override public R collect(Supplier supplier, ObjShortConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -1097,6 +1119,8 @@ public R collect(Supplier supplier, ObjShortConsumer accumulator, BiCo @Override public OptionalShort min() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalShort.empty(); @@ -1123,6 +1147,8 @@ public OptionalShort min() { @Override public OptionalShort max() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalShort.empty(); @@ -1156,6 +1182,7 @@ public OptionalShort max() { @Override public OptionalShort kthLargest(int k) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -1172,6 +1199,8 @@ public OptionalShort kthLargest(int k) { @Override public int sum() { + assertNotClosed(); + try { long result = 0; @@ -1187,6 +1216,8 @@ public int sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalDouble.empty(); @@ -1208,6 +1239,8 @@ public OptionalDouble average() { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -1217,6 +1250,8 @@ public long count() { @Override public ShortSummaryStatistics summarize() { + assertNotClosed(); + try { final ShortSummaryStatistics result = new ShortSummaryStatistics(); @@ -1232,6 +1267,8 @@ public ShortSummaryStatistics summarize() { @Override public boolean anyMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextShort())) { @@ -1247,6 +1284,8 @@ public boolean anyMatch(final Try.ShortPredicate predic @Override public boolean allMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextShort()) == false) { @@ -1262,6 +1301,8 @@ public boolean allMatch(final Try.ShortPredicate predic @Override public boolean noneMatch(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.nextShort())) { @@ -1277,6 +1318,8 @@ public boolean noneMatch(final Try.ShortPredicate predi @Override public OptionalShort findFirst(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { short e = elements.nextShort(); @@ -1294,6 +1337,8 @@ public OptionalShort findFirst(final Try.ShortPredicate @Override public OptionalShort findLast(final Try.ShortPredicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return OptionalShort.empty(); diff --git a/src/com/landawn/abacus/util/stream/IteratorStream.java b/src/com/landawn/abacus/util/stream/IteratorStream.java index 5db7caa4..e3da0dfc 100644 --- a/src/com/landawn/abacus/util/stream/IteratorStream.java +++ b/src/com/landawn/abacus/util/stream/IteratorStream.java @@ -1760,6 +1760,8 @@ public A[] toArray(A[] a) { @Override public void forEach(Try.Consumer action) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { action.accept(elements.next()); @@ -1773,6 +1775,7 @@ public void forEach(Try.Consumer action) thr public void forEachPair(final Try.BiConsumer action, final int increment) throws E { final int windowSize = 2; N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + assertNotClosed(); try { T prev = (T) NONE; @@ -1807,6 +1810,7 @@ public void forEachPair(final Try.BiConsumer void forEachTriple(final Try.TriConsumer action, final int increment) throws E { final int windowSize = 3; N.checkArgument(increment > 0, "'increment'=%s must not be less than 1", increment); + assertNotClosed(); try { T prev = (T) NONE; @@ -1850,6 +1854,8 @@ public Object[] toArray() { } A[] toArray(A[] a) { + assertNotClosed(); + try { return elements.toArray(a); } finally { @@ -1859,6 +1865,8 @@ A[] toArray(A[] a) { @Override public List toList() { + assertNotClosed(); + try { final List result = new ArrayList<>(); @@ -1874,6 +1882,8 @@ public List toList() { @Override public Set toSet() { + assertNotClosed(); + try { final Set result = new HashSet<>(); @@ -1889,6 +1899,8 @@ public Set toSet() { @Override public > C toCollection(Supplier supplier) { + assertNotClosed(); + try { final C result = supplier.get(); @@ -1904,6 +1916,8 @@ public > C toCollection(Supplier supplier) @Override public Multiset toMultiset() { + assertNotClosed(); + try { final Multiset result = new Multiset<>(); @@ -1919,6 +1933,8 @@ public Multiset toMultiset() { @Override public Multiset toMultiset(Supplier> supplier) { + assertNotClosed(); + try { final Multiset result = supplier.get(); @@ -1934,6 +1950,8 @@ public Multiset toMultiset(Supplier> supplier) { @Override public LongMultiset toLongMultiset() { + assertNotClosed(); + try { final LongMultiset result = new LongMultiset<>(); @@ -1949,6 +1967,8 @@ public LongMultiset toLongMultiset() { @Override public LongMultiset toLongMultiset(Supplier> supplier) { + assertNotClosed(); + try { final LongMultiset result = supplier.get(); @@ -1965,6 +1985,8 @@ public LongMultiset toLongMultiset(Supplier> suppli @Override public > M toMap(Function keyExtractor, Function valueMapper, BinaryOperator mergeFunction, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); T element = null; @@ -1983,6 +2005,8 @@ public > M toMap(Function keyE @Override public > M toMap(final Function classifier, final Collector downstream, final Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); final Supplier downstreamSupplier = downstream.supplier(); @@ -2023,6 +2047,8 @@ public A apply(K k, A v) { @Override public , M extends Multimap> M toMultimap(Function keyExtractor, Function valueMapper, Supplier mapFactory) { + assertNotClosed(); + try { final M result = mapFactory.get(); T element = null; @@ -2040,6 +2066,8 @@ public , M extends Multimap> M toMultimap @Override public T reduce(T identity, BinaryOperator accumulator) { + assertNotClosed(); + try { T result = identity; @@ -2055,6 +2083,8 @@ public T reduce(T identity, BinaryOperator accumulator) { @Override public Optional reduce(BinaryOperator accumulator) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -2074,6 +2104,8 @@ public Optional reduce(BinaryOperator accumulator) { @Override public R collect(Supplier supplier, BiConsumer accumulator, BiConsumer combiner) { + assertNotClosed(); + try { final R result = supplier.get(); @@ -2089,6 +2121,8 @@ public R collect(Supplier supplier, BiConsumer accumulator, @Override public R collect(Collector collector) { + assertNotClosed(); + try { final A container = collector.supplier().get(); final BiConsumer accumulator = collector.accumulator(); @@ -2224,6 +2258,8 @@ public T next() { @Override public Optional min(Comparator comparator) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -2250,6 +2286,8 @@ public Optional min(Comparator comparator) { @Override public Optional max(Comparator comparator) { + assertNotClosed(); + try { if (elements.hasNext() == false) { return Optional.empty(); @@ -2283,6 +2321,7 @@ public Optional max(Comparator comparator) { @Override public Optional kthLargest(int k, Comparator comparator) { N.checkArgPositive(k, "k"); + assertNotClosed(); try { if (elements.hasNext() == false) { @@ -2326,6 +2365,8 @@ public Optional kthLargest(int k, Comparator comparator) { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { @@ -2335,6 +2376,8 @@ public long count() { @Override public boolean anyMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.next())) { @@ -2350,6 +2393,8 @@ public boolean anyMatch(final Try.Predicate @Override public boolean allMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.next()) == false) { @@ -2365,6 +2410,8 @@ public boolean allMatch(final Try.Predicate @Override public boolean noneMatch(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { if (predicate.test(elements.next())) { @@ -2380,6 +2427,8 @@ public boolean noneMatch(final Try.Predicate @Override public Optional findFirst(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { while (elements.hasNext()) { T e = elements.next(); @@ -2397,6 +2446,8 @@ public Optional findFirst(final Try.Predicate Optional findLast(final Try.Predicate predicate) throws E { + assertNotClosed(); + try { if (elements.hasNext() == false) { return (Optional) Optional.empty(); diff --git a/src/com/landawn/abacus/util/stream/ParallelArrayDoubleStream.java b/src/com/landawn/abacus/util/stream/ParallelArrayDoubleStream.java index 504b5934..73f41b0a 100644 --- a/src/com/landawn/abacus/util/stream/ParallelArrayDoubleStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelArrayDoubleStream.java @@ -817,6 +817,8 @@ public Double call() { @Override public double sum() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return 0d; @@ -832,6 +834,8 @@ public double sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); diff --git a/src/com/landawn/abacus/util/stream/ParallelArrayFloatStream.java b/src/com/landawn/abacus/util/stream/ParallelArrayFloatStream.java index c4b3c463..6b3d4168 100644 --- a/src/com/landawn/abacus/util/stream/ParallelArrayFloatStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelArrayFloatStream.java @@ -818,6 +818,8 @@ public Float call() { @Override public double sum() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return 0d; @@ -833,6 +835,8 @@ public double sum() { @Override public OptionalDouble average() { + assertNotClosed(); + try { if (fromIndex == toIndex) { return OptionalDouble.empty(); diff --git a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java index 54131483..a05111ba 100644 --- a/src/com/landawn/abacus/util/stream/ParallelArrayStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelArrayStream.java @@ -2634,6 +2634,8 @@ public void run() { @Override A[] toArray(A[] a) { + assertNotClosed(); + try { if (a.length < (toIndex - fromIndex)) { a = N.newArray(a.getClass().getComponentType(), toIndex - fromIndex); diff --git a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java index 6f8a15e8..24c9d8e6 100644 --- a/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java +++ b/src/com/landawn/abacus/util/stream/ParallelIteratorStream.java @@ -1846,6 +1846,8 @@ public void run() { @Override A[] toArray(A[] a) { + assertNotClosed(); + try { return elements.toArray(a); } finally { @@ -2440,6 +2442,8 @@ public Optional max(Comparator comparator) { @Override public long count() { + assertNotClosed(); + try { return elements.count(); } finally { diff --git a/src/com/landawn/abacus/util/stream/StreamBase.java b/src/com/landawn/abacus/util/stream/StreamBase.java index 8198b25f..9614cf22 100644 --- a/src/com/landawn/abacus/util/stream/StreamBase.java +++ b/src/com/landawn/abacus/util/stream/StreamBase.java @@ -795,6 +795,12 @@ static void close(final Collection> iters) { } } + void assertNotClosed() { + if (isClosed) { + throw new IllegalStateException("This stream has been closed"); + } + } + protected static Splitor checkSplitor(final Splitor splitor) { N.checkArgNotNull(splitor, "splitor");