diff --git a/CHANGES.md b/CHANGES.md index e347d568..b8d36834 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +### 5.6.9 + +* Improve javaDoc +* Improvements and bug fixes. + ### 5.6.8 * Improve javaDoc diff --git a/README.md b/README.md index c267263d..89578561 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # abacus-common [![Maven Central](https://img.shields.io/maven-central/v/com.landawn/abacus-common.svg)](https://maven-badges.herokuapp.com/maven-central/com.landawn/abacus-common/) -[![Javadocs](https://img.shields.io/badge/javadoc-5.6.8-brightgreen.svg)](https://www.javadoc.io/doc/com.landawn/abacus-common/5.6.8/index.html) +[![Javadocs](https://img.shields.io/badge/javadoc-5.6.9-brightgreen.svg)](https://www.javadoc.io/doc/com.landawn/abacus-common/5.6.9/index.html) A general programming library in Java. It's easy to learn and simple to use with concise and powerful APIs. @@ -132,7 +132,7 @@ more [Collectors](https://htmlpreview.github.io/?https://github.com/landawn/abac [HttpClient](https://htmlpreview.github.io/?https://github.com/landawn/abacus-common/master/docs/HttpClient_view.html), [HttpRequest](https://htmlpreview.github.io/?https://github.com/landawn/abacus-common/master/docs/HttpRequest_view.html), [OkHttpRequest](https://htmlpreview.github.io/?https://github.com/landawn/abacus-common/master/docs/OkHttpRequest_view.html), -and [More](https://www.javadoc.io/static/com.landawn/abacus-common/5.6.8/com/landawn/abacus/http/package-summary.html) ... +and [More](https://www.javadoc.io/static/com.landawn/abacus-common/5.6.9/com/landawn/abacus/http/package-summary.html) ... * Pool: [Pool](https://htmlpreview.github.io/?https://github.com/landawn/abacus-common/master/docs/Pool_view.html), @@ -142,36 +142,36 @@ and [More](https://www.javadoc.io/static/com.landawn/abacus-common/5.6.8/com/lan * More: -[CodeGenerationUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/CodeGenerationUtil.html), -[JsonMappers](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/JsonMappers.html), -[XmlMappers](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/XmlMappers.html), -[Charsets](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Charsets.html), -[Ascii](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Ascii.html), -[CalendarField](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/CalendarField.html), -[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/NamingPolicy.html), -[Properties](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Properties.html), -[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/PropertiesUtil.html), -[Configuration](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Configuration.html), -[XmlUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/XmlUtil.html), -[Wrapper](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Wrapper.html), -[ClassUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/ClassUtil.html), -[CSVUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/CSVUtil.html), -[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/EscapeUtil.html), -[RegExUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/RegExUtil.html), -[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/FilenameUtil.html), -[AddrUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/AddrUtil.html), -[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/WSSecurityUtil.html), -[EmailUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/EmailUtil.html), -[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/IEEE754rUtil.html), -[Timed](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Timed.html), -[IndexedKeyed](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/IndexedKeyed.html), -[Median](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Median.html), -[Stopwatch](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/Stopwatch.html), -[RateLimiter](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/RateLimiter.html), -[TypeReference](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/util/TypeReference.html), -[WebUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/http/WebUtil.html), -[Files](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/guava/Files.html), -[Traverser](https://static.javadoc.io/com.landawn/abacus-common/5.6.8/com/landawn/abacus/guava/Traverser.html)(copied from Apache commons, Google Guava...under Apache License v2) ... +[CodeGenerationUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/CodeGenerationUtil.html), +[JsonMappers](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/JsonMappers.html), +[XmlMappers](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/XmlMappers.html), +[Charsets](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Charsets.html), +[Ascii](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Ascii.html), +[CalendarField](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/CalendarField.html), +[NamingPolicy](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/NamingPolicy.html), +[Properties](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Properties.html), +[PropertiesUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/PropertiesUtil.html), +[Configuration](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Configuration.html), +[XmlUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/XmlUtil.html), +[Wrapper](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Wrapper.html), +[ClassUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/ClassUtil.html), +[CSVUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/CSVUtil.html), +[EscapeUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/EscapeUtil.html), +[RegExUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/RegExUtil.html), +[FilenameUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/FilenameUtil.html), +[AddrUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/AddrUtil.html), +[WSSecurityUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/WSSecurityUtil.html), +[EmailUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/EmailUtil.html), +[IEEE754rUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/IEEE754rUtil.html), +[Timed](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Timed.html), +[IndexedKeyed](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/IndexedKeyed.html), +[Median](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Median.html), +[Stopwatch](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/Stopwatch.html), +[RateLimiter](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/RateLimiter.html), +[TypeReference](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/util/TypeReference.html), +[WebUtil](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/http/WebUtil.html), +[Files](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/guava/Files.html), +[Traverser](https://static.javadoc.io/com.landawn/abacus-common/5.6.9/com/landawn/abacus/guava/Traverser.html)(copied from Apache commons, Google Guava...under Apache License v2) ... ## Download/Installation & [Changes](https://github.com/landawn/abacus-common/blob/master/CHANGES.md): @@ -182,7 +182,7 @@ and [More](https://www.javadoc.io/static/com.landawn/abacus-common/5.6.8/com/lan com.landawn abacus-common - 5.6.8 + 5.6.9 ``` @@ -190,7 +190,7 @@ and [More](https://www.javadoc.io/static/com.landawn/abacus-common/5.6.8/com/lan ```gradle // JDK 17 or above: -compile 'com.landawn:abacus-common:5.6.8' +compile 'com.landawn:abacus-common:5.6.9' ``` diff --git a/pom.xml b/pom.xml index 94faba0e..321a3b67 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.landawn abacus-common - 5.6.9 + 5.6.10 jar abacus-common @@ -33,7 +33,7 @@ com.landawn abacus-common - 5.6.8 + 5.6.9 provided diff --git a/src/main/java/com/landawn/abacus/util/BooleanList.java b/src/main/java/com/landawn/abacus/util/BooleanList.java index ff9f537d..66af7b13 100644 --- a/src/main/java/com/landawn/abacus/util/BooleanList.java +++ b/src/main/java/com/landawn/abacus/util/BooleanList.java @@ -30,6 +30,9 @@ import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; import com.landawn.abacus.util.u.OptionalBoolean; +import com.landawn.abacus.util.function.BooleanConsumer; +import com.landawn.abacus.util.function.BooleanPredicate; +import com.landawn.abacus.util.function.BooleanUnaryOperator; import com.landawn.abacus.util.stream.Stream; /** @@ -443,12 +446,10 @@ public boolean removeAll(final boolean[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.BooleanPredicate p) throws E { + public boolean removeIf(final BooleanPredicate p) { final BooleanList tmp = new BooleanList(size()); for (int i = 0; i < size; i++) { @@ -734,11 +735,9 @@ public int replaceAll(final boolean oldVal, final boolean newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.BooleanUnaryOperator operator) throws E { + public void replaceAll(final BooleanUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsBoolean(elementData[i]); } @@ -746,13 +745,11 @@ public void replaceAll(final Throwables.BooleanUnaryOperat /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.BooleanPredicate predicate, final boolean newValue) throws E { + public boolean replaceIf(final BooleanPredicate predicate, final boolean newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1134,25 +1131,20 @@ public int lastIndexOf(final boolean valueToFind, final int startIndexFromBack) /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.BooleanConsumer action) throws E { + public void forEach(final BooleanConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.BooleanConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final BooleanConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1168,41 +1160,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntBooleanConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntBooleanConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntBooleanConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntBooleanConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalBoolean first() { return size() == 0 ? OptionalBoolean.empty() : OptionalBoolean.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/ByteList.java b/src/main/java/com/landawn/abacus/util/ByteList.java index 0e6707ae..da224210 100644 --- a/src/main/java/com/landawn/abacus/util/ByteList.java +++ b/src/main/java/com/landawn/abacus/util/ByteList.java @@ -30,6 +30,9 @@ import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; import com.landawn.abacus.util.u.OptionalByte; +import com.landawn.abacus.util.function.ByteConsumer; +import com.landawn.abacus.util.function.BytePredicate; +import com.landawn.abacus.util.function.ByteUnaryOperator; import com.landawn.abacus.util.stream.ByteStream; /** @@ -492,12 +495,10 @@ public boolean removeAll(final byte[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.BytePredicate p) throws E { + public boolean removeIf(final BytePredicate p) { final ByteList tmp = new ByteList(size()); for (int i = 0; i < size; i++) { @@ -791,11 +792,9 @@ public int replaceAll(final byte oldVal, final byte newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.ByteUnaryOperator operator) throws E { + public void replaceAll(final ByteUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsByte(elementData[i]); } @@ -803,13 +802,11 @@ public void replaceAll(final Throwables.ByteUnaryOperator< /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.BytePredicate predicate, final byte newValue) throws E { + public boolean replaceIf(final BytePredicate predicate, final byte newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1242,25 +1239,20 @@ public OptionalByte median(final int fromIndex, final int toIndex) throws IndexO /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.ByteConsumer action) throws E { + public void forEach(final ByteConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.ByteConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final ByteConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1276,41 +1268,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntByteConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntByteConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntByteConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntByteConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalByte first() { return size() == 0 ? OptionalByte.empty() : OptionalByte.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/CharList.java b/src/main/java/com/landawn/abacus/util/CharList.java index a3aa9323..ff5e73f0 100644 --- a/src/main/java/com/landawn/abacus/util/CharList.java +++ b/src/main/java/com/landawn/abacus/util/CharList.java @@ -30,6 +30,9 @@ import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; import com.landawn.abacus.util.u.OptionalChar; +import com.landawn.abacus.util.function.CharConsumer; +import com.landawn.abacus.util.function.CharPredicate; +import com.landawn.abacus.util.function.CharUnaryOperator; import com.landawn.abacus.util.stream.CharStream; /** @@ -529,12 +532,10 @@ public boolean removeAll(final char[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.CharPredicate p) throws E { + public boolean removeIf(final CharPredicate p) { final CharList tmp = new CharList(size()); for (int i = 0; i < size; i++) { @@ -828,11 +829,9 @@ public int replaceAll(final char oldVal, final char newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.CharUnaryOperator operator) throws E { + public void replaceAll(final CharUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsChar(elementData[i]); } @@ -840,13 +839,11 @@ public void replaceAll(final Throwables.CharUnaryOperator< /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.CharPredicate predicate, final char newValue) throws E { + public boolean replaceIf(final CharPredicate predicate, final char newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1279,25 +1276,20 @@ public OptionalChar median(final int fromIndex, final int toIndex) throws IndexO /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.CharConsumer action) throws E { + public void forEach(final CharConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.CharConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final CharConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1313,41 +1305,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntCharConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntCharConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntCharConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntCharConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalChar first() { return size() == 0 ? OptionalChar.empty() : OptionalChar.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/DoubleList.java b/src/main/java/com/landawn/abacus/util/DoubleList.java index 5b71251b..9114ca8c 100644 --- a/src/main/java/com/landawn/abacus/util/DoubleList.java +++ b/src/main/java/com/landawn/abacus/util/DoubleList.java @@ -25,6 +25,9 @@ import java.util.NoSuchElementException; import java.util.Random; import java.util.Set; +import java.util.function.DoubleConsumer; +import java.util.function.DoublePredicate; +import java.util.function.DoubleUnaryOperator; import java.util.function.IntFunction; import com.landawn.abacus.annotation.Beta; @@ -443,12 +446,10 @@ public boolean removeAll(final double[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.DoublePredicate p) throws E { + public boolean removeIf(final DoublePredicate p) { final DoubleList tmp = new DoubleList(size()); for (int i = 0; i < size; i++) { @@ -742,11 +743,9 @@ public int replaceAll(final double oldVal, final double newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.DoubleUnaryOperator operator) throws E { + public void replaceAll(final DoubleUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsDouble(elementData[i]); } @@ -754,13 +753,11 @@ public void replaceAll(final Throwables.DoubleUnaryOperato /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.DoublePredicate predicate, final double newValue) throws E { + public boolean replaceIf(final DoublePredicate predicate, final double newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1193,25 +1190,20 @@ public OptionalDouble median(final int fromIndex, final int toIndex) throws Inde /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.DoubleConsumer action) throws E { + public void forEach(final DoubleConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.DoubleConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final DoubleConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1227,41 +1219,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntDoubleConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntDoubleConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntDoubleConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntDoubleConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalDouble first() { return size() == 0 ? OptionalDouble.empty() : OptionalDouble.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/FloatList.java b/src/main/java/com/landawn/abacus/util/FloatList.java index 322e3967..d35accb9 100644 --- a/src/main/java/com/landawn/abacus/util/FloatList.java +++ b/src/main/java/com/landawn/abacus/util/FloatList.java @@ -30,6 +30,9 @@ import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; import com.landawn.abacus.util.u.OptionalFloat; +import com.landawn.abacus.util.function.FloatConsumer; +import com.landawn.abacus.util.function.FloatPredicate; +import com.landawn.abacus.util.function.FloatUnaryOperator; import com.landawn.abacus.util.stream.FloatStream; /** @@ -443,12 +446,10 @@ public boolean removeAll(final float[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.FloatPredicate p) throws E { + public boolean removeIf(final FloatPredicate p) { final FloatList tmp = new FloatList(size()); for (int i = 0; i < size; i++) { @@ -743,11 +744,9 @@ public int replaceAll(final float oldVal, final float newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.FloatUnaryOperator operator) throws E { + public void replaceAll(final FloatUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsFloat(elementData[i]); } @@ -755,13 +754,11 @@ public void replaceAll(final Throwables.FloatUnaryOperator /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.FloatPredicate predicate, final float newValue) throws E { + public boolean replaceIf(final FloatPredicate predicate, final float newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1194,25 +1191,20 @@ public OptionalFloat median(final int fromIndex, final int toIndex) throws Index /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.FloatConsumer action) throws E { + public void forEach(final FloatConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.FloatConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final FloatConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1228,41 +1220,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntFloatConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntFloatConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntFloatConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntFloatConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalFloat first() { return size() == 0 ? OptionalFloat.empty() : OptionalFloat.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/IOUtil.java b/src/main/java/com/landawn/abacus/util/IOUtil.java index c5362343..7ea606f5 100644 --- a/src/main/java/com/landawn/abacus/util/IOUtil.java +++ b/src/main/java/com/landawn/abacus/util/IOUtil.java @@ -4129,7 +4129,7 @@ public static void appendLines(final Iterable lines, final File targetFile) t * @param charset The Charset to be used to open the specified file for writing. * @param targetFile The file to which the elements' string representations will be appended, not {@code null}. * @throws IOException if an I/O error occurs. - * @see #writeLines(Iterable, File) + * @see #writeLines(Iterable, File) * @see N#toString(Object) */ public static void appendLines(final Iterable lines, final Charset charset, final File targetFile) throws IOException { @@ -5849,7 +5849,7 @@ public static boolean deleteFiles(final File file, final T * * @param directory directory to clean * @return {@code false} if some of its sub files can't be deleted. - * @see #deleteFiles(File, com.landawn.abacus.util.Throwables.BiPredicate) + * @see #deleteFiles(File, Throwables.BiPredicate) */ public static boolean cleanDirectory(final File directory) { if (directory == null || !directory.isDirectory()) { @@ -7159,7 +7159,7 @@ public static boolean contentEqualsIgnoreEOL(final Reader input1, final Reader i * @throws UncheckedIOException If an I/O error occurs. * @throws E If the lineParser throws an exception. * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final Throwables.Consumer lineParser) throws UncheckedIOException, E { parse(source, lineParser, Fn.emptyAction()); @@ -7177,7 +7177,7 @@ public static void parse(final File source, final Throwabl * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7195,7 +7195,7 @@ public static void parse(final File * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7216,7 +7216,7 @@ public static void parse(final File source, final long lin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7236,7 +7236,7 @@ public static void parse(final File * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7259,7 +7259,7 @@ public static void parse(final File source, final long lin * @throws E If the lineParser throws an exception. * @throws E2 If the onComplete throws an exception. * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7277,7 +7277,7 @@ public static void parse(final File * @throws UncheckedIOException If an I/O error occurs. * @throws E If the lineParser throws an exception. * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7296,7 +7296,7 @@ public static void parse(final Collection files, fin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7314,7 +7314,7 @@ public static void parse(final Colle * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7335,7 +7335,7 @@ public static void parse(final Collection files, fin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7355,7 +7355,7 @@ public static void parse(final Colle * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7376,7 +7376,7 @@ public static void parse(final Collection files, fin * @throws E If the lineParser throws an exception. * @throws E2 If the onComplete throws an exception. * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7424,7 +7424,7 @@ public static void parse(final Colle * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7446,7 +7446,7 @@ public static void parse(final File source, final int read * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7468,7 +7468,7 @@ public static void parse(final File * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7492,7 +7492,7 @@ public static void parse(final File source, final long lin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final File source, final long lineOffset, final long count, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7513,7 +7513,7 @@ public static void parse(final File * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7535,7 +7535,7 @@ public static void parse(final Collection files, fin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7557,7 +7557,7 @@ public static void parse(final Colle * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7581,7 +7581,7 @@ public static void parse(final Collection files, fin * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Collection files, final long lineOffset, final long count, final int readThreadNum, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, @@ -7626,7 +7626,7 @@ public static void parse(final Colle * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7645,7 +7645,7 @@ public static void parse(final InputStream source, final T * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7663,7 +7663,7 @@ public static void parse(final Input * @throws UncheckedIOException if an I/O error occurs. * @throws E the * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final long lineOffset, final long count, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7684,7 +7684,7 @@ public static void parse(final InputStream source, final l * @throws E the e * @throws E2 the * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final long lineOffset, final long count, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7704,7 +7704,7 @@ public static void parse(final Input * @throws UncheckedIOException if an I/O error occurs. * @throws E the * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7727,7 +7727,7 @@ public static void parse(final InputStream source, final l * @throws E the e * @throws E2 the * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final InputStream source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) @@ -7750,7 +7750,7 @@ public static void parse(final Input * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7769,7 +7769,7 @@ public static void parse(final Reader source, final Throwa * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7787,7 +7787,7 @@ public static void parse(final Reade * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final long lineOffset, final long count, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7808,7 +7808,7 @@ public static void parse(final Reader source, final long l * @throws E the e * @throws E2 the e2 * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final long lineOffset, final long count, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) throws UncheckedIOException, E, E2 { @@ -7828,7 +7828,7 @@ public static void parse(final Reade * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @see #parse(Reader, long, long, int, int, Throwables.Consumer, Throwables.Runnable) - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser) throws UncheckedIOException, E { @@ -7850,7 +7850,7 @@ public static void parse(final Reader source, final long l * @throws UncheckedIOException if an I/O error occurs. * @throws E the e * @throws E2 the e2 - * @see Iterators#forEach(Iterator, long, long, int, int, com.landawn.abacus.util.Throwables.Consumer, com.landawn.abacus.util.Throwables.Runnable) + * @see Iterators#forEach(Iterator, long, long, int, int, Throwables.Consumer, Throwables.Runnable) */ public static void parse(final Reader source, final long lineOffset, final long count, final int processThreadNum, final int queueSize, final Throwables.Consumer lineParser, final Throwables.Runnable onComplete) diff --git a/src/main/java/com/landawn/abacus/util/IntList.java b/src/main/java/com/landawn/abacus/util/IntList.java index 3cc1ae99..6230f960 100644 --- a/src/main/java/com/landawn/abacus/util/IntList.java +++ b/src/main/java/com/landawn/abacus/util/IntList.java @@ -25,7 +25,10 @@ import java.util.NoSuchElementException; import java.util.Random; import java.util.Set; +import java.util.function.IntConsumer; import java.util.function.IntFunction; +import java.util.function.IntPredicate; +import java.util.function.IntUnaryOperator; import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; @@ -525,12 +528,10 @@ public boolean removeAll(final int[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.IntPredicate p) throws E { + public boolean removeIf(final IntPredicate p) { final IntList tmp = new IntList(size()); for (int i = 0; i < size; i++) { @@ -824,11 +825,9 @@ public int replaceAll(final int oldVal, final int newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.IntUnaryOperator operator) throws E { + public void replaceAll(final IntUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsInt(elementData[i]); } @@ -836,13 +835,11 @@ public void replaceAll(final Throwables.IntUnaryOperator * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.IntPredicate predicate, final int newValue) throws E { + public boolean replaceIf(final IntPredicate predicate, final int newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1303,25 +1300,20 @@ public OptionalInt median(final int fromIndex, final int toIndex) throws IndexOu /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.IntConsumer action) throws E { + public void forEach(final IntConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.IntConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final IntConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1337,41 +1329,39 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntIntConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntIntConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntIntConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntIntConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalInt first() { return size() == 0 ? OptionalInt.empty() : OptionalInt.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/LongList.java b/src/main/java/com/landawn/abacus/util/LongList.java index 554b0250..912c23f2 100644 --- a/src/main/java/com/landawn/abacus/util/LongList.java +++ b/src/main/java/com/landawn/abacus/util/LongList.java @@ -26,6 +26,9 @@ import java.util.Random; import java.util.Set; import java.util.function.IntFunction; +import java.util.function.LongConsumer; +import java.util.function.LongPredicate; +import java.util.function.LongUnaryOperator; import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; @@ -489,12 +492,10 @@ public boolean removeAll(final long[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.LongPredicate p) throws E { + public boolean removeIf(final LongPredicate p) { final LongList tmp = new LongList(size()); for (int i = 0; i < size; i++) { @@ -788,11 +789,9 @@ public int replaceAll(final long oldVal, final long newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.LongUnaryOperator operator) throws E { + public void replaceAll(final LongUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsLong(elementData[i]); } @@ -800,13 +799,11 @@ public void replaceAll(final Throwables.LongUnaryOperator< /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.LongPredicate predicate, final long newValue) throws E { + public boolean replaceIf(final LongPredicate predicate, final long newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1239,25 +1236,20 @@ public OptionalLong median(final int fromIndex, final int toIndex) throws IndexO /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.LongConsumer action) throws E { + public void forEach(final LongConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.LongConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final LongConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1273,41 +1265,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntLongConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntLongConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntLongConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntLongConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalLong first() { return size() == 0 ? OptionalLong.empty() : OptionalLong.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/N.java b/src/main/java/com/landawn/abacus/util/N.java index 3206f2e8..00a7f64d 100644 --- a/src/main/java/com/landawn/abacus/util/N.java +++ b/src/main/java/com/landawn/abacus/util/N.java @@ -5087,7 +5087,7 @@ public static void replaceAll(final double[] a, final DoubleUnaryOperator operat * @param a The array in which to replace values. * @param operator The UnaryOperator to apply to each element. The operator takes a value of type T and returns a value of type T. * @see #setAll(Object[], IntFunction) - * @see #setAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #setAll(Object[], Throwables.IntObjFunction) * @see Arrays#setAll(Object[], IntFunction) * @see Arrays#parallelSetAll(Object[], IntFunction) */ @@ -5109,7 +5109,7 @@ public static void replaceAll(final T[] a, final UnaryOperator operator) * @param list The list in which to replace values. * @param operator The UnaryOperator to apply to each element. The operator takes a value of type T and returns a value of type T. * @see #setAll(List, IntFunction) - * @see #setAll(List, com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #setAll(List, Throwables.IntObjFunction) */ public static void replaceAll(final List list, final UnaryOperator operator) { if (isEmpty(list)) { @@ -5131,6 +5131,66 @@ public static void replaceAll(final List list, final UnaryOperator ope } } + /** + * Replaces all elements in the given array using the specified {@code UnaryOperator}. + * If the input array is empty or {@code null}, no replacements are made. + * + * @param The type of elements in the array. + * @param The type of exception may thrown out. + * @param a The array in which to replace values. + * @param operator The UnaryOperator to apply to each element. The operator takes a value of type T and returns a value of type T. + * @throws E the exception may be thrown out. + * @see #replaceAll(Object[], UnaryOperator) + * @see #setAll(Object[], IntFunction) + * @see #setAll(Object[], Throwables.IntObjFunction) + * @see Arrays#setAll(Object[], IntFunction) + * @see Arrays#parallelSetAll(Object[], IntFunction) + */ + @Beta + public static void updateAll(final T[] a, final Throwables.UnaryOperator operator) throws E { + if (isEmpty(a)) { + return; + } + + for (int i = 0, n = a.length; i < n; i++) { + a[i] = operator.apply(a[i]); + } + } + + /** + * Replaces all elements in the given list using the specified {@code UnaryOperator}. + * If the input list is empty or {@code null}, no replacements are made. + * + * @param The type of elements in the list. + * @param The type of exception may thrown out. + * @param list The list in which to replace values. + * @param operator The UnaryOperator to apply to each element. The operator takes a value of type T and returns a value of type T. + * @throws E the exception may be thrown out. + * @see #replaceAll(List, UnaryOperator) + * @see #setAll(List, IntFunction) + * @see #setAll(List, Throwables.IntObjFunction) + */ + @Beta + public static void updateAll(final List list, final Throwables.UnaryOperator operator) throws E { + if (isEmpty(list)) { + return; + } + + final int size = list.size(); + + if (size < REPLACE_ALL_THRESHOLD || list instanceof RandomAccess) { + for (int i = 0; i < size; i++) { + list.set(i, operator.apply(list.get(i))); + } + } else { + final ListIterator itr = list.listIterator(); + + for (int i = 0; i < size; i++) { + itr.set(operator.apply(itr.next())); + } + } + } + /** * A fake/unsupported method defined to remind user to use {@code replaceAll} when {@code update/updateAll/updateIf} is searched. * @@ -5318,7 +5378,7 @@ public static void setAll(final double[] array, final IntToDoubleFunction genera * @param array the array to be modified * @param generator the function used to generate new values for the array elements * @see #replaceAll(Object[], UnaryOperator) - * @see #setAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #setAll(Object[], Throwables.IntObjFunction) * @see Arrays#setAll(Object[], IntFunction) * @see Arrays#parallelSetAll(Object[], IntFunction) */ @@ -5338,7 +5398,7 @@ public static void setAll(final T[] array, final IntFunction ge * @param list the list to be modified * @param generator the function used to generate new values for the list elements * @see #replaceAll(List, UnaryOperator) - * @see #setAll(List, com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #setAll(List, Throwables.IntObjFunction) */ public static void setAll(final List list, final IntFunction generator) { if (isEmpty(list)) { @@ -5429,7 +5489,7 @@ public static void setAll(final List list, final Thr * @param a the array to be copied and modified * @param generator the function used to generate new values for the array elements * @return a new array with elements copied from the specified array and modified by the generator function - * @see #copyThenSetAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #copyThenSetAll(Object[], Throwables.IntObjFunction) * @see #copyThenReplaceAll(Object[], UnaryOperator) */ @MayReturnNull @@ -5490,7 +5550,7 @@ public static T[] copyThenSetAll(final T[] a, final Thr * @param operator The UnaryOperator to apply to each element. The operator takes a value of type T and returns a value of type T. * @return a new array with elements copied from the specified array and modified by provided {@code UnaryOperator} * @see #copyThenSetAll(Object[], IntFunction) - * @see #copyThenSetAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + * @see #copyThenSetAll(Object[], Throwables.IntObjFunction) */ @MayReturnNull public static T[] copyThenReplaceAll(final T[] a, final UnaryOperator operator) { diff --git a/src/main/java/com/landawn/abacus/util/Seq.java b/src/main/java/com/landawn/abacus/util/Seq.java index 5055d683..eb3f24a2 100644 --- a/src/main/java/com/landawn/abacus/util/Seq.java +++ b/src/main/java/com/landawn/abacus/util/Seq.java @@ -14,9 +14,14 @@ package com.landawn.abacus.util; -import java.io.*; import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Serial; +import java.io.Writer; import java.nio.charset.Charset; import java.nio.file.Path; import java.security.SecureRandom; @@ -83,11 +88,11 @@ import com.landawn.abacus.util.Fn.Fnn; import com.landawn.abacus.util.Fn.Suppliers; import com.landawn.abacus.util.If.OrElse; -import com.landawn.abacus.util.function.IntBiFunction; import com.landawn.abacus.util.u.Optional; import com.landawn.abacus.util.u.OptionalDouble; import com.landawn.abacus.util.u.OptionalInt; import com.landawn.abacus.util.u.OptionalLong; +import com.landawn.abacus.util.function.IntBiFunction; import com.landawn.abacus.util.function.TriFunction; import com.landawn.abacus.util.stream.Collectors; import com.landawn.abacus.util.stream.IntStream; @@ -1585,7 +1590,7 @@ public static Seq splitByChunkCount(final int tot * @param mapper a function to map the chunk from and to index to an element in the resulting stream * @return a sequence of the mapped chunk values * @throws IllegalArgumentException if {@code totalSize} is negative or {@code maxChunkCount} is not positive. - * @see Stream#splitByChunkCount(int, int, boolean, IntBiFunction) + * @see Stream#splitByChunkCount(int, int, boolean, IntBiFunction) */ public static Seq splitByChunkCount(final int totalSize, final int maxChunkCount, final boolean sizeSmallerFirst, final Throwables.IntBiFunction mapper) { @@ -9570,227 +9575,819 @@ public Seq zipWith(final Seq b, final Seq c, fin // } // } + // /** + // * + // * @param + // * @param threadNum + // * @param action + // * @throws IllegalArgumentException + // * @throws E the e + // * @throws E2 the e2 + // */ // @Beta // @TerminalOp - // public void foreach(java.util.function.Consumer action) throws E { + // public void forEachInParallel(final int threadNum, final Throwables.Consumer action) + // throws IllegalArgumentException, E, E2 { // assertNotClosed(); + // checkArgNotNull(action, cs.action); // - // forEach(Fnn.from(action)); + // try { + // unchecked().parallel(threadNum).forEach(action); + // } catch (final Exception e) { + // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); + // } + // } + // + // /** + // * + // * @param + // * @param threadNum + // * @param action + // * @param executor + // * @throws IllegalArgumentException + // * @throws E the e + // * @throws E2 the e2 + // */ + // @Beta + // @TerminalOp + // public void forEachInParallel(final int threadNum, final Throwables.Consumer action, final Executor executor) + // throws IllegalArgumentException, E, E2 { + // assertNotClosed(); + // checkArgNotNull(action, cs.action); + // + // try { + // unchecked().parallel(threadNum, executor).forEach(action); + // } catch (final Exception e) { + // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); + // } // } - /** - * Performs the given action for each element of this sequence. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of exception that the action may throw - * @param action a {@code Throwables.Consumer} that will be applied to each element - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the action is null - * @throws E if an exception occurs during iteration - * @throws E2 if the action throws an exception - */ - @TerminalOp - public void forEach(final Throwables.Consumer action) throws IllegalStateException, IllegalArgumentException, E, E2 { - assertNotClosed(); - checkArgNotNull(action, cs.action); - - try { - while (elements.hasNext()) { - action.accept(elements.next()); - } - } finally { - close(); - } - } - - /** - * Performs the given action for each element of this sequence, providing the index of the element. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of exception that the action may throw - * @param action a {@code Throwables.IntObjConsumer} that will be applied to each element along with its index - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the action is null - * @throws E if an exception occurs during iteration - * @throws E2 if the action throws an exception - */ - @TerminalOp - public void forEachIndexed(final Throwables.IntObjConsumer action) - throws IllegalStateException, IllegalArgumentException, E, E2 { - assertNotClosed(); - checkArgNotNull(action, cs.action); - - final MutableInt idx = MutableInt.of(0); - - try { - while (elements.hasNext()) { - action.accept(idx.getAndIncrement(), elements.next()); - } - } finally { - close(); - } - } - - /** - * Iterate and execute the given action until the flag is set to {@code true}. - * The flag can only be set after at least one element is iterated and executed by the action. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of exception that the action may throw - * @param action a {@code Throwables.BiConsumer} that takes an element and a {@code MutableBoolean} flag. - * Set the flag to {@code true} to break the loop if you don't want to continue the action. - * Iteration on this sequence will also be stopped when this flag is set to {@code true}. - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the action is null - * @throws E if an exception occurs during iteration - * @throws E2 if the action throws an exception - * @see #forEachUntil(MutableBoolean, Throwables.Consumer) - */ - @Beta - @TerminalOp - public void forEachUntil(final Throwables.BiConsumer action) - throws IllegalStateException, IllegalArgumentException, E, E2 { - assertNotClosed(); - - final MutableBoolean flagToBreak = MutableBoolean.of(false); - final Throwables.Consumer tmp = t -> action.accept(t, flagToBreak); - - //noinspection resource - takeWhile(value -> flagToBreak.isFalse()).forEach(tmp); - } - - /** - * Iterate and execute {@code action} until {@code flagToBreak} is set {@code true}. - * If {@code flagToBreak} is set to {@code true} at the begin, there will be no element iterated from sequence. - * - *
- * This is a terminal operation and will close the sequence. - * - * @implNote it's equivalent to {@code takeWhile(value -> flagToBreak.isFalse()).forEach(action)}. - * - * @param the type of exception that the action may throw - * @param flagToBreak a {@code MutableBoolean} flag to break the for-each loop. - * Set it to {@code true} to break the loop if you don't want to continue the action. - * Iteration on this sequence will also be stopped when this flag is set to {@code true}. - * @param action a {@code Throwables.Consumer} that will be applied to each element. - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the action is null - * @throws E if an exception occurs during iteration - * @throws E2 if the action throws an exception - * @see #forEachUntil(Throwables.BiConsumer) - */ - @Beta - @TerminalOp - public void forEachUntil(final MutableBoolean flagToBreak, final Throwables.Consumer action) - throws IllegalStateException, IllegalArgumentException, E, E2 { - assertNotClosed(); - - //noinspection resource - takeWhile(value -> flagToBreak.isFalse()).forEach(action); - } - - /** - * Performs the given action for each element of this sequence, and then performs the provided {@code onComplete}. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of exception that the action may throw - * @param the type of exception that the onComplete action may throw - * @param action a {@code Throwables.Consumer} that will be applied to each element - * @param onComplete a {@code Throwables.Runnable} that will be applied after the action is applied to all elements - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the action or onComplete is null - * @throws E if an exception occurs during iteration - * @throws E2 if the action throws an exception - * @throws E3 if the onComplete action throws an exception - */ - @TerminalOp - public void forEach(final Throwables.Consumer action, final Throwables.Runnable onComplete) - throws IllegalStateException, IllegalArgumentException, E, E2, E3 { - assertNotClosed(); - checkArgNotNull(action, cs.action); - checkArgNotNull(onComplete, cs.onComplete); - - try { - while (elements.hasNext()) { - action.accept(elements.next()); - } - - onComplete.run(); - } finally { - close(); - } - } - - /** - * Iterates over the elements of this sequence, applying a flat-mapping function to each element - * and then executing the given action on each resulting element. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of elements in the iterable returned by the flat-mapper - * @param the type of exception that the flat-mapper may throw - * @param the type of exception that the action may throw - * @param flatMapper a {@code Throwables.Function} that takes an element of this sequence and returns an {@code Iterable} of elements - * @param action a {@code Throwables.BiConsumer} that takes an element of this sequence and an element of the iterable returned by the flat-mapper - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the flatMapper or action is null - * @throws E if an exception occurs during iteration - * @throws E2 if the flat-mapper throws an exception - * @throws E3 if the action throws an exception - */ - @TerminalOp - public void forEach(final Throwables.Function, E2> flatMapper, - final Throwables.BiConsumer action) throws IllegalStateException, IllegalArgumentException, E, E2, E3 { - assertNotClosed(); - checkArgNotNull(flatMapper, cs.flatMapper); - checkArgNotNull(action, cs.action); - - Iterable c = null; - T next = null; - - try { - while (elements.hasNext()) { - next = elements.next(); - c = flatMapper.apply(next); - - if (c != null) { - for (final U u : c) { - action.accept(next, u); - } - } - } - } finally { - close(); - } - } - - /** - * Iterates over the elements of this sequence, applying two flat-mapping functions to each element - * and then executing the given action on each resulting combination of elements. - * - *
- * This is a terminal operation and will close the sequence. - * - * @param the type of elements in the iterable returned by the first flat-mapper - * @param the type of elements in the iterable returned by the second flat-mapper - * @param the type of exception that the first flat-mapper may throw - * @param the type of exception that the second flat-mapper may throw - * @param the type of exception that the action may throw - * @param flatMapper a {@code Throwables.Function} that takes an element of this sequence and returns an {@code Iterable} of elements - * @param flatMapper2 a {@code Throwables.Function} that takes an element of the iterable returned by the first flat-mapper and returns an {@code Iterable} of elements - * @param action a {@code Throwables.TriConsumer} that takes an element of this sequence, an element of the iterable returned by the first flat-mapper, and an element of the iterable returned by the second flat-mapper - * @throws IllegalStateException if the sequence is already closed - * @throws IllegalArgumentException if the flatMapper, flatMapper2 or action is null - * @throws E if an exception occurs during iteration + // // TODO First of all, it only works in sequential Stream, not parallel stream (and maybe not work in some other scenarios as well). + // // Secondly, these onErrorXXX methods make it more difficult and complicated to use Stream. + // // So, remove them. + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param type + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Class type, + // final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (type.isAssignableFrom(e.getClass())) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorPredicate + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Predicate errorPredicate, + // final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (errorPredicate.test(e)) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorPredicate + // * @param errorConsumer + // * @param maxErrorCountToStop + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Predicate errorPredicate, + // final Throwables.Consumer errorConsumer, final int maxErrorCountToStop) { + // assertNotClosed(); + // checkArgNotNegative(maxErrorCountToStop, "maxErrorCountToStop"); + // + // return create(new Throwables.Iterator() { + // private final AtomicInteger errorCounter = new AtomicInteger(maxErrorCountToStop); + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (errorCounter.decrementAndGet() >= 0) { + // if (errorPredicate.test(e)) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } else { + // break; + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param fallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final T fallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } + // } + // + // return next != none; + // } + // + // // public T next() { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param type + // * @param fallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Class type, final T fallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (type.isAssignableFrom(e.getClass())) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param predicate + // * @param fallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, final T fallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param predicate + // * @param supplierForFallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, + // final Throwables.Supplier supplierForFallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = supplierForFallbackValue.get(); + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param predicate + // * @param mapperForFallbackValue + // * @param maxErrorCountToStop + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, + // final Throwables.Function mapperForFallbackValue, final int maxErrorCountToStop) { + // assertNotClosed(); + // checkArgNotNegative(maxErrorCountToStop, "maxErrorCountToStop"); + // + // return create(new Throwables.Iterator() { + // private final AtomicInteger errorCounter = new AtomicInteger(maxErrorCountToStop); + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (errorCounter.decrementAndGet() >= 0) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = mapperForFallbackValue.apply(e); + // } else { + // throwThrowable(e); + // } + // } else { + // // break; + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // @Beta + // @IntermediateOp + // public Seq onErrorStop() { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorStop", e); + // } + // } + // + // return next != none; + // } + // + // // public T next() { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // private void throwThrowable(Throwable e) throws E { + // if (e instanceof Error) { + // throw (Error) e; + // } else { + // throw (E) e; + // } + // } + + /** + * + * @param action + * @throws E + * @see #forEach(Throwables.Consumer) + */ + @Beta + @TerminalOp + public void foreach(final Consumer action) throws E { + assertNotClosed(); + checkArgNotNull(action, cs.action); + + try { + while (elements.hasNext()) { + action.accept(elements.next()); + } + } finally { + close(); + } + } + + /** + * Performs the given action for each element of this sequence. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of exception that the action may throw + * @param action a {@code Throwables.Consumer} that will be applied to each element + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the action is null + * @throws E if an exception occurs during iteration + * @throws E2 if the action throws an exception + */ + @TerminalOp + public void forEach(final Throwables.Consumer action) throws IllegalStateException, IllegalArgumentException, E, E2 { + assertNotClosed(); + checkArgNotNull(action, cs.action); + + try { + while (elements.hasNext()) { + action.accept(elements.next()); + } + } finally { + close(); + } + } + + /** + * Performs the given action for each element of this sequence, providing the index of the element. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of exception that the action may throw + * @param action a {@code Throwables.IntObjConsumer} that will be applied to each element along with its index + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the action is null + * @throws E if an exception occurs during iteration + * @throws E2 if the action throws an exception + */ + @TerminalOp + public void forEachIndexed(final Throwables.IntObjConsumer action) + throws IllegalStateException, IllegalArgumentException, E, E2 { + assertNotClosed(); + checkArgNotNull(action, cs.action); + + final MutableInt idx = MutableInt.of(0); + + try { + while (elements.hasNext()) { + action.accept(idx.getAndIncrement(), elements.next()); + } + } finally { + close(); + } + } + + /** + * Iterate and execute the given action until the flag is set to {@code true}. + * The flag can only be set after at least one element is iterated and executed by the action. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of exception that the action may throw + * @param action a {@code Throwables.BiConsumer} that takes an element and a {@code MutableBoolean} flag. + * Set the flag to {@code true} to break the loop if you don't want to continue the action. + * Iteration on this sequence will also be stopped when this flag is set to {@code true}. + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the action is null + * @throws E if an exception occurs during iteration + * @throws E2 if the action throws an exception + * @see #forEachUntil(MutableBoolean, Throwables.Consumer) + */ + @Beta + @TerminalOp + public void forEachUntil(final Throwables.BiConsumer action) + throws IllegalStateException, IllegalArgumentException, E, E2 { + assertNotClosed(); + + final MutableBoolean flagToBreak = MutableBoolean.of(false); + final Throwables.Consumer tmp = t -> action.accept(t, flagToBreak); + + //noinspection resource + takeWhile(value -> flagToBreak.isFalse()).forEach(tmp); + } + + /** + * Iterate and execute {@code action} until {@code flagToBreak} is set {@code true}. + * If {@code flagToBreak} is set to {@code true} at the begin, there will be no element iterated from sequence. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @implNote it's equivalent to {@code takeWhile(value -> flagToBreak.isFalse()).forEach(action)}. + * + * @param the type of exception that the action may throw + * @param flagToBreak a {@code MutableBoolean} flag to break the for-each loop. + * Set it to {@code true} to break the loop if you don't want to continue the action. + * Iteration on this sequence will also be stopped when this flag is set to {@code true}. + * @param action a {@code Throwables.Consumer} that will be applied to each element. + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the action is null + * @throws E if an exception occurs during iteration + * @throws E2 if the action throws an exception + * @see #forEachUntil(Throwables.BiConsumer) + */ + @Beta + @TerminalOp + public void forEachUntil(final MutableBoolean flagToBreak, final Throwables.Consumer action) + throws IllegalStateException, IllegalArgumentException, E, E2 { + assertNotClosed(); + + //noinspection resource + takeWhile(value -> flagToBreak.isFalse()).forEach(action); + } + + /** + * Performs the given action for each element of this sequence, and then performs the provided {@code onComplete}. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of exception that the action may throw + * @param the type of exception that the onComplete action may throw + * @param action a {@code Throwables.Consumer} that will be applied to each element + * @param onComplete a {@code Throwables.Runnable} that will be applied after the action is applied to all elements + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the action or onComplete is null + * @throws E if an exception occurs during iteration + * @throws E2 if the action throws an exception + * @throws E3 if the onComplete action throws an exception + */ + @TerminalOp + public void forEach(final Throwables.Consumer action, final Throwables.Runnable onComplete) + throws IllegalStateException, IllegalArgumentException, E, E2, E3 { + assertNotClosed(); + checkArgNotNull(action, cs.action); + checkArgNotNull(onComplete, cs.onComplete); + + try { + while (elements.hasNext()) { + action.accept(elements.next()); + } + + onComplete.run(); + } finally { + close(); + } + } + + /** + * Iterates over the elements of this sequence, applying a flat-mapping function to each element + * and then executing the given action on each resulting element. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of elements in the iterable returned by the flat-mapper + * @param the type of exception that the flat-mapper may throw + * @param the type of exception that the action may throw + * @param flatMapper a {@code Throwables.Function} that takes an element of this sequence and returns an {@code Iterable} of elements + * @param action a {@code Throwables.BiConsumer} that takes an element of this sequence and an element of the iterable returned by the flat-mapper + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the flatMapper or action is null + * @throws E if an exception occurs during iteration + * @throws E2 if the flat-mapper throws an exception + * @throws E3 if the action throws an exception + */ + @TerminalOp + public void forEach(final Throwables.Function, E2> flatMapper, + final Throwables.BiConsumer action) throws IllegalStateException, IllegalArgumentException, E, E2, E3 { + assertNotClosed(); + checkArgNotNull(flatMapper, cs.flatMapper); + checkArgNotNull(action, cs.action); + + Iterable c = null; + T next = null; + + try { + while (elements.hasNext()) { + next = elements.next(); + c = flatMapper.apply(next); + + if (c != null) { + for (final U u : c) { + action.accept(next, u); + } + } + } + } finally { + close(); + } + } + + /** + * Iterates over the elements of this sequence, applying two flat-mapping functions to each element + * and then executing the given action on each resulting combination of elements. + * + *
+ * This is a terminal operation and will close the sequence. + * + * @param the type of elements in the iterable returned by the first flat-mapper + * @param the type of elements in the iterable returned by the second flat-mapper + * @param the type of exception that the first flat-mapper may throw + * @param the type of exception that the second flat-mapper may throw + * @param the type of exception that the action may throw + * @param flatMapper a {@code Throwables.Function} that takes an element of this sequence and returns an {@code Iterable} of elements + * @param flatMapper2 a {@code Throwables.Function} that takes an element of the iterable returned by the first flat-mapper and returns an {@code Iterable} of elements + * @param action a {@code Throwables.TriConsumer} that takes an element of this sequence, an element of the iterable returned by the first flat-mapper, and an element of the iterable returned by the second flat-mapper + * @throws IllegalStateException if the sequence is already closed + * @throws IllegalArgumentException if the flatMapper, flatMapper2 or action is null + * @throws E if an exception occurs during iteration * @throws E2 if the first flat-mapper throws an exception * @throws E3 if the second flat-mapper throws an exception * @throws E4 if the action throws an exception @@ -9993,48 +10590,580 @@ public void forEachTriple(final int increment, final Thro // /** // * - // * @param - // * @param threadNum - // * @param action - // * @throws IllegalArgumentException - // * @throws E the e - // * @throws E2 the e2 + // * @param + // * @param threadNum + // * @param action + // * @throws IllegalArgumentException + // * @throws E the e + // * @throws E2 the e2 + // */ + // @Beta + // @TerminalOp + // public void forEachInParallel(final int threadNum, final Throwables.Consumer action) + // throws IllegalArgumentException, E, E2 { + // assertNotClosed(); + // checkArgNotNull(action, cs.action); + // + // try { + // unchecked().parallel(threadNum).forEach(action); + // } catch (final Exception e) { + // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); + // } + // } + // + // /** + // * + // * @param + // * @param threadNum + // * @param action + // * @param executor + // * @throws IllegalArgumentException + // * @throws E the e + // * @throws E2 the e2 + // */ + // @Beta + // @TerminalOp + // public void forEachInParallel(final int threadNum, final Throwables.Consumer action, final Executor executor) + // throws IllegalArgumentException, E, E2 { + // assertNotClosed(); + // checkArgNotNull(action, cs.action); + // + // try { + // unchecked().parallel(threadNum, executor).forEach(action); + // } catch (final Exception e) { + // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); + // } + // } + + // // TODO First of all, it only works in sequential Stream, not parallel stream (and maybe not work in some other scenarios as well). + // // Secondly, these onErrorXXX methods make it more difficult and complicated to use Stream. + // // So, remove them. + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param type + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Class type, + // final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (type.isAssignableFrom(e.getClass())) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorPredicate + // * @param errorConsumer + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Predicate errorPredicate, + // final Throwables.Consumer errorConsumer) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (errorPredicate.test(e)) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param errorPredicate + // * @param errorConsumer + // * @param maxErrorCountToStop + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorContinue(final Throwables.Predicate errorPredicate, + // final Throwables.Consumer errorConsumer, final int maxErrorCountToStop) { + // assertNotClosed(); + // checkArgNotNegative(maxErrorCountToStop, "maxErrorCountToStop"); + // + // return create(new Throwables.Iterator() { + // private final AtomicInteger errorCounter = new AtomicInteger(maxErrorCountToStop); + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // while (true) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // + // break; + // } catch (Throwable e) { + // if (errorCounter.decrementAndGet() >= 0) { + // if (errorPredicate.test(e)) { + // logger.warn("ignoring error in onErrorContinue", e); + // + // errorConsumer.accept(e); + // } else { + // throwThrowable(e); + // } + // } else { + // break; + // } + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param fallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final T fallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } + // } + // + // return next != none; + // } + // + // // public T next() { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param type + // * @param fallbackValue + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Class type, final T fallbackValue) { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (type.isAssignableFrom(e.getClass())) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param predicate + // * @param fallbackValue + // * @return // */ // @Beta - // @TerminalOp - // public void forEachInParallel(final int threadNum, final Throwables.Consumer action) - // throws IllegalArgumentException, E, E2 { + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, final T fallbackValue) { // assertNotClosed(); - // checkArgNotNull(action, cs.action); // - // try { - // unchecked().parallel(threadNum).forEach(action); - // } catch (final Exception e) { - // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); - // } + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = fallbackValue; + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); // } // // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. // * - // * @param - // * @param threadNum - // * @param action - // * @param executor - // * @throws IllegalArgumentException - // * @throws E the e - // * @throws E2 the e2 + // * @param predicate + // * @param supplierForFallbackValue + // * @return // */ // @Beta - // @TerminalOp - // public void forEachInParallel(final int threadNum, final Throwables.Consumer action, final Executor executor) - // throws IllegalArgumentException, E, E2 { + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, + // final Throwables.Supplier supplierForFallbackValue) { // assertNotClosed(); - // checkArgNotNull(action, cs.action); // - // try { - // unchecked().parallel(threadNum, executor).forEach(action); - // } catch (final Exception e) { - // throw (E) ExceptionUtil.tryToGetOriginalCheckedException(e); + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = supplierForFallbackValue.get(); + // } else { + // throwThrowable(e); + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // /** + // * This method should be only applied sequential {@code Stream} and whose up-streams are sequential {@code Streams} as well. + // * Because error happening in the operations executed by parallel stream will stop iteration on that {@Stream}, so the down-streams won't be able to continue. + // * + // * @param predicate + // * @param mapperForFallbackValue + // * @param maxErrorCountToStop + // * @return + // */ + // @Beta + // @IntermediateOp + // public Seq onErrorReturn(final Throwables.Predicate predicate, + // final Throwables.Function mapperForFallbackValue, final int maxErrorCountToStop) { + // assertNotClosed(); + // checkArgNotNegative(maxErrorCountToStop, "maxErrorCountToStop"); + // + // return create(new Throwables.Iterator() { + // private final AtomicInteger errorCounter = new AtomicInteger(maxErrorCountToStop); + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() throws E { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // if (errorCounter.decrementAndGet() >= 0) { + // if (predicate.test(e)) { + // logger.warn("ignoring error in onErrorReturn", e); + // + // next = mapperForFallbackValue.apply(e); + // } else { + // throwThrowable(e); + // } + // } else { + // // break; + // } + // } + // } + // + // return next != none; + // } + // + // // public T next() throws E { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, closeHandlers); + // } + // + // @Beta + // @IntermediateOp + // public Seq onErrorStop() { + // assertNotClosed(); + // + // return create(new Throwables.Iterator() { + // private final Throwables.Iterator iter = iteratorEx(); + // private final T none = (T) NONE; + // private T next = none; + // private T ret = null; + // + // // public boolean hasNext() { + // if (next == none) { + // try { + // if (iter.hasNext()) { + // next = iter.next(); + // } + // } catch (Throwable e) { + // logger.warn("ignoring error in onErrorStop", e); + // } + // } + // + // return next != none; + // } + // + // // public T next() { + // if (!hasNext()) { + // throw new NoSuchElementException(ERROR_MSG_FOR_NO_SUCH_EX); + // } + // + // ret = next; + // next = none; + // return ret; + // } + // }, sorted, cmp, closeHandlers); + // } + // + // private void throwThrowable(Throwable e) throws E { + // if (e instanceof Error) { + // throw (Error) e; + // } else { + // throw (E) e; // } // } @@ -10588,7 +11717,7 @@ public boolean test(final T t) { * @return {@code true} if this sequence contains all the elements in the specified collection, otherwise {@code false} * @throws IllegalStateException if the sequence is already closed * @throws E if an exception occurs during iteration - * @see N#containsAll(Collection, Collection) + * @see N#containsAll(Collection, Collection) */ @TerminalOp public boolean containsAll(final Collection c) throws IllegalStateException, E { @@ -12253,7 +13382,7 @@ public OptionalDouble averageDouble(final Throwables.ToDo * @throws IllegalArgumentException if the accumulator function is null * @throws E if an exception occurs during the reduction * @throws E2 if the accumulator function throws an exception - * @see Stream#reduce(BinaryOperator) + * @see Stream#reduce(BinaryOperator) */ @TerminalOp public Optional reduce(final Throwables.BinaryOperator accumulator) @@ -12291,7 +13420,7 @@ public Optional reduce(final Throwables.BinaryOperator * @throws IllegalArgumentException if the accumulator function is null * @throws E if an exception occurs during the reduction * @throws E2 if the accumulator function throws an exception - * @see Stream#reduce(Object, BinaryOperator) + * @see Stream#reduce(Object, BinaryOperator) */ @TerminalOp public U reduce(final U identity, final Throwables.BiFunction accumulator) diff --git a/src/main/java/com/landawn/abacus/util/ShortList.java b/src/main/java/com/landawn/abacus/util/ShortList.java index 93f80ee6..fc995bec 100644 --- a/src/main/java/com/landawn/abacus/util/ShortList.java +++ b/src/main/java/com/landawn/abacus/util/ShortList.java @@ -30,6 +30,9 @@ import com.landawn.abacus.annotation.Beta; import com.landawn.abacus.annotation.SuppressFBWarnings; import com.landawn.abacus.util.u.OptionalShort; +import com.landawn.abacus.util.function.ShortConsumer; +import com.landawn.abacus.util.function.ShortPredicate; +import com.landawn.abacus.util.function.ShortUnaryOperator; import com.landawn.abacus.util.stream.ShortStream; /** @@ -490,12 +493,10 @@ public boolean removeAll(final short[] a) { /** * Removes the elements which match the given predicate. * - * @param * @param p * @return - * @throws E the e */ - public boolean removeIf(final Throwables.ShortPredicate p) throws E { + public boolean removeIf(final ShortPredicate p) { final ShortList tmp = new ShortList(size()); for (int i = 0; i < size; i++) { @@ -789,11 +790,9 @@ public int replaceAll(final short oldVal, final short newVal) { /** * - * @param * @param operator - * @throws E the e */ - public void replaceAll(final Throwables.ShortUnaryOperator operator) throws E { + public void replaceAll(final ShortUnaryOperator operator) { for (int i = 0, len = size(); i < len; i++) { elementData[i] = operator.applyAsShort(elementData[i]); } @@ -801,13 +800,11 @@ public void replaceAll(final Throwables.ShortUnaryOperator /** * - * @param * @param predicate * @param newValue * @return - * @throws E the e */ - public boolean replaceIf(final Throwables.ShortPredicate predicate, final short newValue) throws E { + public boolean replaceIf(final ShortPredicate predicate, final short newValue) { boolean result = false; for (int i = 0, len = size(); i < len; i++) { @@ -1240,25 +1237,20 @@ public OptionalShort median(final int fromIndex, final int toIndex) throws Index /** * - * @param * @param action - * @throws E the e */ - public void forEach(final Throwables.ShortConsumer action) throws E { + public void forEach(final ShortConsumer action) { forEach(0, size, action); } /** * - * @param * @param fromIndex * @param toIndex * @param action * @throws IndexOutOfBoundsException - * @throws E the e */ - public void forEach(final int fromIndex, final int toIndex, final Throwables.ShortConsumer action) - throws IndexOutOfBoundsException, E { + public void forEach(final int fromIndex, final int toIndex, final ShortConsumer action) throws IndexOutOfBoundsException { N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); if (size > 0) { @@ -1274,41 +1266,41 @@ public void forEach(final int fromIndex, final int toIndex } } - /** - * - * @param - * @param action - * @throws E the e - */ - public void forEachIndexed(final Throwables.IntShortConsumer action) throws E { - forEachIndexed(0, size, action); - } - - /** - * - * @param - * @param fromIndex - * @param toIndex - * @param action - * @throws IndexOutOfBoundsException - * @throws E the e - */ - public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntShortConsumer action) - throws IndexOutOfBoundsException, E { - N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); - - if (size > 0) { - if (fromIndex <= toIndex) { - for (int i = fromIndex; i < toIndex; i++) { - action.accept(i, elementData[i]); - } - } else { - for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { - action.accept(i, elementData[i]); - } - } - } - } + // /** + // * + // * @param + // * @param action + // * @throws E the e + // */ + // public void forEachIndexed(final Throwables.IntShortConsumer action) throws E { + // forEachIndexed(0, size, action); + // } + // + // /** + // * + // * @param + // * @param fromIndex + // * @param toIndex + // * @param action + // * @throws IndexOutOfBoundsException + // * @throws E the e + // */ + // public void forEachIndexed(final int fromIndex, final int toIndex, final Throwables.IntShortConsumer action) + // throws IndexOutOfBoundsException, E { + // N.checkFromToIndex(fromIndex < toIndex ? fromIndex : (toIndex == -1 ? 0 : toIndex), Math.max(fromIndex, toIndex), size); + // + // if (size > 0) { + // if (fromIndex <= toIndex) { + // for (int i = fromIndex; i < toIndex; i++) { + // action.accept(i, elementData[i]); + // } + // } else { + // for (int i = N.min(size - 1, fromIndex); i > toIndex; i--) { + // action.accept(i, elementData[i]); + // } + // } + // } + // } public OptionalShort first() { return size() == 0 ? OptionalShort.empty() : OptionalShort.of(elementData[0]); diff --git a/src/main/java/com/landawn/abacus/util/Strings.java b/src/main/java/com/landawn/abacus/util/Strings.java index 44b1865f..cf85fac8 100644 --- a/src/main/java/com/landawn/abacus/util/Strings.java +++ b/src/main/java/com/landawn/abacus/util/Strings.java @@ -13355,7 +13355,7 @@ public static List findAllEmailAddresses(final CharSequence cs) { // * @see #copyThenStrip(String[]) // * @see #copyThenSetAll(CharSequence[], Function) // * @see N#setAll(Object[], java.util.function.IntFunction) - // * @see N#setAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + // * @see N#setAll(Object[], Throwables.IntObjFunction) // * @see N#replaceAll(Object[], java.util.function.UnaryOperator) // */ // @Beta @@ -13383,7 +13383,7 @@ public static List findAllEmailAddresses(final CharSequence cs) { // * @see #copyThenTrim(String[]) // * @see #copyThenStrip(String[]) // * @see N#copyThenSetAll(Object[], java.util.function.IntFunction) - // * @see N#copyThenSetAll(Object[], com.landawn.abacus.util.Throwables.IntObjFunction) + // * @see N#copyThenSetAll(Object[], Throwables.IntObjFunction) // */ // @Beta // @MayReturnNull