You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/01/19 19:17:03 UTC

(commons-lang) branch master updated (1e94c922c -> 784e262c8)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


    from 1e94c922c chmod -x
     new dd6aea671 Javadoc
     new 73c5a884d Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-lang.git
     new 25f7d8517 Add IterableStringTokenizer
     new 784e262c8 Javadoc and comment

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |   1 +
 .../commons/lang3/exception/ExceptionUtils.java    |  18 +--
 .../org/apache/commons/lang3/stream/Streams.java   |   4 +-
 .../lang3/util/IterableStringTokenizer.java        | 114 ++++++++++++++
 .../lang3/util/IterableStringTokenizerTest.java    | 170 +++++++++++++++++++++
 5 files changed, 293 insertions(+), 14 deletions(-)
 create mode 100644 src/main/java/org/apache/commons/lang3/util/IterableStringTokenizer.java
 create mode 100644 src/test/java/org/apache/commons/lang3/util/IterableStringTokenizerTest.java


(commons-lang) 01/04: Javadoc

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit dd6aea67130e12b26ebefa32a2ea98fdeafb094d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 19 11:38:33 2025 -0500

    Javadoc
---
 src/main/java/org/apache/commons/lang3/stream/Streams.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/stream/Streams.java b/src/main/java/org/apache/commons/lang3/stream/Streams.java
index 857043dcb..3520a3b38 100644
--- a/src/main/java/org/apache/commons/lang3/stream/Streams.java
+++ b/src/main/java/org/apache/commons/lang3/stream/Streams.java
@@ -689,7 +689,7 @@ public static <E> Stream<E> of(final Enumeration<E> enumeration) {
     }
 
     /**
-     * Creates a stream on the given Iterable.
+     * Creates a sequential stream on the given Iterable.
      *
      * @param <E> the type of elements in the Iterable.
      * @param iterable the Iterable to stream or null.
@@ -701,7 +701,7 @@ public static <E> Stream<E> of(final Iterable<E> iterable) {
     }
 
     /**
-     * Creates a stream on the given Iterator.
+     * Creates a sequential stream on the given Iterator.
      *
      * @param <E> the type of elements in the Iterator.
      * @param iterator the Iterator to stream or null.


(commons-lang) 04/04: Javadoc and comment

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 784e262c89d80d691ee4ccb770b5568b162d42d4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 19 14:16:57 2025 -0500

    Javadoc and comment
---
 .../java/org/apache/commons/lang3/exception/ExceptionUtils.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
index 474c6fe9a..d446dcc11 100644
--- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
+++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
@@ -386,13 +386,12 @@ public static List<String> getRootCauseStackTraceList(final Throwable throwable)
     }
 
     /**
-     * Gets a {@link List} of stack frames - the message
+     * Gets a {@link List} of stack frames, the message
      * is not included. Only the trace of the specified exception is
      * returned, any caused by trace is stripped.
      *
-     * <p>This works in most cases - it will only fail if the exception
-     * message contains a line that starts with:
-     * {@code &quot;&nbsp;&nbsp;&nbsp;at&quot;.}</p>
+     * <p>This works in most cases and will only fail if the exception
+     * message contains a line that starts with: {@code "<whitespace>at"}.</p>
      *
      * @param throwable is any throwable
      * @return List of stack frames
@@ -405,7 +404,7 @@ static List<String> getStackFrameList(final Throwable throwable) {
         boolean traceStarted = false;
         while (frames.hasMoreTokens()) {
             final String token = frames.nextToken();
-            // Determine if the line starts with <whitespace>at
+            // Determine if the line starts with "<whitespace>at"
             final int at = token.indexOf("at");
             if (at != NOT_FOUND && token.substring(0, at).trim().isEmpty()) {
                 traceStarted = true;


(commons-lang) 03/04: Add IterableStringTokenizer

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 25f7d85174d93ed6e084c02753a007d8eed56bc9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 19 14:15:29 2025 -0500

    Add IterableStringTokenizer
---
 src/changes/changes.xml                            |   1 +
 .../commons/lang3/exception/ExceptionUtils.java    |   9 +-
 .../lang3/util/IterableStringTokenizer.java        | 114 ++++++++++++++
 .../lang3/util/IterableStringTokenizerTest.java    | 170 +++++++++++++++++++++
 4 files changed, 287 insertions(+), 7 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9ad14108b..33d931172 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -94,6 +94,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add ArrayUtils.startsWith.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add Predicates.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add RegExUtils methods typed to CharSequence input and deprecate old versions typed to String.</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add IterableStringTokenizer.</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 79 #1267, #1277, #1283, #1288, #1302.</action>
     <action                   type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">[site] Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #1300.</action>
diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
index a832f0448..474c6fe9a 100644
--- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
+++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
@@ -33,6 +33,7 @@
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.reflect.MethodUtils;
+import org.apache.commons.lang3.util.IterableStringTokenizer;
 
 /**
  * Provides utilities for manipulating and examining
@@ -425,13 +426,7 @@ static List<String> getStackFrameList(final Throwable throwable) {
      * @return an array where each element is a line from the argument
      */
     static String[] getStackFrames(final String stackTrace) {
-        final String linebreak = System.lineSeparator();
-        final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
-        final List<String> list = new ArrayList<>();
-        while (frames.hasMoreTokens()) {
-            list.add(frames.nextToken());
-        }
-        return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
+        return new IterableStringTokenizer(stackTrace, System.lineSeparator()).toArray();
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/lang3/util/IterableStringTokenizer.java b/src/main/java/org/apache/commons/lang3/util/IterableStringTokenizer.java
new file mode 100644
index 000000000..7735cf244
--- /dev/null
+++ b/src/main/java/org/apache/commons/lang3/util/IterableStringTokenizer.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import java.util.StringTokenizer;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * A {@link StringTokenizer} that implements {@link Iterable}{@code <String>} and conversion methods {@link #toList()} and {@link #toStream()}.
+ *
+ * @since 3.18.0
+ */
+public class IterableStringTokenizer extends StringTokenizer implements Iterable<String> {
+
+    /**
+     * Constructs a new instance like {@link StringTokenizer#StringTokenizer(String, String, boolean)}.
+     *
+     * @param str a string to be parsed.
+     * @exception NullPointerException if str is {@code null}.
+     */
+    public IterableStringTokenizer(final String str) {
+        super(str);
+    }
+
+    /**
+     * Constructs a new instance like {@link StringTokenizer#StringTokenizer(String, String, boolean)}.
+     *
+     * @param str   a string to be parsed.
+     * @param delim the delimiters.
+     * @exception NullPointerException if str is {@code null}.
+     */
+    public IterableStringTokenizer(final String str, final String delim) {
+        super(str, delim);
+    }
+
+    /**
+     * Constructs a new instance like {@link StringTokenizer#StringTokenizer(String, String, boolean)}.
+     *
+     * @param str          a string to be parsed.
+     * @param delim        the delimiters.
+     * @param returnDelims flag indicating whether to return the delimiters as tokens.
+     * @exception NullPointerException if str is {@code null}.
+     */
+    public IterableStringTokenizer(final String str, final String delim, final boolean returnDelims) {
+        super(str, delim, returnDelims);
+    }
+
+    @Override
+    public Iterator<String> iterator() {
+        return new Iterator<String>() {
+
+            @Override
+            public boolean hasNext() {
+                return hasMoreElements();
+            }
+
+            @Override
+            public String next() {
+                return Objects.toString(nextElement(), null);
+            }
+        };
+    }
+
+    /**
+     * Returns a new {@code String[]} containing the tokenizer elements.
+     *
+     * @return a new {@code String[]}.
+     */
+    public String[] toArray() {
+        return toList().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
+    }
+
+    /**
+     * Returns a new {@link List} containing the tokenizer elements.
+     *
+     * @return a new {@link List}.
+     */
+    public List<String> toList() {
+        final List<String> list = new ArrayList<>();
+        forEach(list::add);
+        return list;
+    }
+
+    /**
+     * Returns a sequential stream on this Iterable instance.
+     *
+     * @return a sequential stream on this Iterable instance.
+     */
+    public Stream<String> toStream() {
+        return StreamSupport.stream(spliterator(), false);
+    }
+}
diff --git a/src/test/java/org/apache/commons/lang3/util/IterableStringTokenizerTest.java b/src/test/java/org/apache/commons/lang3/util/IterableStringTokenizerTest.java
new file mode 100644
index 000000000..68a0ee26a
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/util/IterableStringTokenizerTest.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.lang3.util;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests {@link IterableStringTokenizer}.
+ */
+public class IterableStringTokenizerTest {
+
+    /**
+     * Delimiters from {@link StringTokenizer}.
+     */
+    private static final String[] DELIMITERS_ARRAY = { " ", "\t", "\n", "\r", "\f" };
+
+    private static final String DELIMITERS_STRING = String.join("", DELIMITERS_ARRAY);
+
+    private static final String[] DATA = { "a", "b", "c" };
+
+    public static String[] delimiters() {
+        return DELIMITERS_ARRAY;
+    }
+
+    @Test
+    public void testConstructorArguments1ForEach() {
+        final List<String> list = new ArrayList<>();
+        new IterableStringTokenizer("a,b,c").forEach(list::add);
+        assertEquals(Arrays.asList("a,b,c"), list);
+    }
+
+    @Test
+    public void testConstructorArguments1ToList() {
+        assertEquals(Arrays.asList("a,b,c"), new IterableStringTokenizer("a,b,c").toList());
+    }
+
+    public void testConstructorArguments2AllDelimsToList(final String singleDelim) {
+        final String data = String.join(singleDelim, DATA);
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer(data, DELIMITERS_STRING).toList());
+    }
+
+    @ParameterizedTest
+    @MethodSource("delimiters")
+    public void testConstructorArguments2ForEach(final String singleDelim) {
+        final List<String> list = new ArrayList<>();
+        new IterableStringTokenizer(String.join(singleDelim, DATA), singleDelim).forEach(list::add);
+        assertEquals(Arrays.asList(DATA), list);
+    }
+
+    @ParameterizedTest
+    @MethodSource("delimiters")
+    public void testConstructorArguments2ToList(final String singleDelim) {
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer(String.join(singleDelim, DATA), singleDelim).toList());
+    }
+
+    @ParameterizedTest
+    @MethodSource("delimiters")
+    public void testConstructorArguments3AllDelimsToList(final String singleDelim) {
+        final String data = String.join(singleDelim, DATA);
+        assertEquals(Arrays.asList("a", singleDelim, "b", singleDelim, "c"), new IterableStringTokenizer(data, DELIMITERS_STRING, true).toList());
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer(data, DELIMITERS_STRING, false).toList());
+    }
+
+    @ParameterizedTest
+    @MethodSource("delimiters")
+    public void testConstructorArguments3ToList(final String singleDelim) {
+        final String data = String.join(singleDelim, DATA);
+        assertEquals(Arrays.asList("a", singleDelim, "b", singleDelim, "c"), new IterableStringTokenizer(data, singleDelim, true).toList());
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer(data, singleDelim, false).toList());
+    }
+
+    @Test
+    void testEmptyString() {
+        assertTrue(new IterableStringTokenizer(StringUtils.EMPTY).toList().isEmpty());
+    }
+
+    @Test
+    void testIterator() {
+        final IterableStringTokenizer tokenizer = new IterableStringTokenizer("a,b,c", ",");
+        final Iterator<String> iterator = tokenizer.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals("a", iterator.next());
+        assertTrue(iterator.hasNext());
+        assertEquals("b", iterator.next());
+        assertTrue(iterator.hasNext());
+        assertEquals("c", iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
+    @Test
+    void testNonDefaultDelimiterToArray() {
+        assertArrayEquals(new String[] {}, new IterableStringTokenizer("", "|").toArray());
+        assertArrayEquals(new String[] { "a" }, new IterableStringTokenizer("a", "|").toArray());
+        assertArrayEquals(new String[] { "a", "b" }, new IterableStringTokenizer("a|b", "|").toArray());
+        assertArrayEquals(new String[] { "a", "b", "c" }, new IterableStringTokenizer("a|b|c", "|").toArray());
+    }
+
+    @Test
+    void testNonDefaultDelimiterToList() {
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer("a|b|c", "|").toList());
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer("a!b!c", "!").toList());
+        assertEquals(Arrays.asList(DATA), new IterableStringTokenizer("a^!b^!c", "^!").toList());
+    }
+
+    @Test
+    public void testToArray() {
+        // 0 tokens
+        assertArrayEquals(new String[] {}, new IterableStringTokenizer("").toArray());
+        // 1 token
+        assertArrayEquals(new String[] { "a" }, new IterableStringTokenizer("a").toArray());
+        assertArrayEquals(new String[] { "a,b" }, new IterableStringTokenizer("a,b").toArray());
+        assertArrayEquals(new String[] { "a,b,c" }, new IterableStringTokenizer("a,b,c").toArray());
+        // > 1 token
+        assertArrayEquals(new String[] { "a", "b" }, new IterableStringTokenizer("a b").toArray());
+    }
+
+    @Test
+    public void testToList() {
+        // 0 tokens
+        assertEquals(Arrays.asList(), new IterableStringTokenizer("").toList());
+        // 1 token
+        assertEquals(Arrays.asList("a"), new IterableStringTokenizer("a").toList());
+        assertEquals(Arrays.asList("a,b"), new IterableStringTokenizer("a,b").toList());
+        assertEquals(Arrays.asList("a,b,c"), new IterableStringTokenizer("a,b,c").toList());
+        // > 1 token
+        assertEquals(Arrays.asList("a", "b"), new IterableStringTokenizer("a b").toList());
+    }
+
+    @Test
+    public void testToStream() {
+        // 0 tokens
+        assertEquals(Arrays.asList(), new IterableStringTokenizer("").toList());
+        // 1 token
+        assertEquals(Arrays.asList("a"), new IterableStringTokenizer("a").toList());
+        assertEquals(Arrays.asList("a,b"), new IterableStringTokenizer("a,b").toStream().collect(Collectors.toList()));
+        assertEquals(Arrays.asList("a,b,c"), new IterableStringTokenizer("a,b,c").toStream().collect(Collectors.toList()));
+        // > 1 token
+        assertEquals(Arrays.asList("a", "b"), new IterableStringTokenizer("a b").toStream().collect(Collectors.toList()));
+    }
+}


(commons-lang) 02/04: Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-lang.git

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git

commit 73c5a884da70bc40e7a17a7b9ebf5cc5223d7caa
Merge: dd6aea671 1e94c922c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 19 11:46:16 2025 -0500

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-lang.git

 .github/workflows/codeql-analysis.yml              |  6 +-
 .github/workflows/scorecards-analysis.yml          |  2 +-
 RELEASE-NOTES.txt                                  | 38 ++++++------
 pom.xml                                            |  6 --
 src/changes/release-notes.vm                       |  2 +-
 .../apache/commons/lang3/builder/DiffExclude.java  |  0
 .../commons/lang3/builder/EqualsExclude.java       |  0
 .../commons/lang3/builder/HashCodeExclude.java     |  0
 .../commons/lang3/builder/ToStringExclude.java     |  0
 .../commons/lang3/RandomStringUtilsTest.java       | 62 ++++++++++---------
 .../org/apache/commons/lang3/RandomUtilsTest.java  | 70 +++++++++++++---------
 .../java/org/apache/commons/lang3/StreamsTest.java | 26 +++-----
 .../lang3/StringUtilsEqualsIndexOfTest.java        |  7 +--
 .../org/apache/commons/lang3/StringUtilsTest.java  |  6 +-
 .../org/apache/commons/lang3/ThreadUtilsTest.java  |  8 +--
 .../commons/lang3/builder/DiffBuilderTest.java     | 18 ++----
 ...onToStringBuilderExcludeWithAnnotationTest.java | 14 ++---
 ...oncurrentInitializerCloseAndExceptionsTest.java |  7 +--
 .../BackgroundInitializerSupplierTest.java         |  5 +-
 .../MultiBackgroundInitializerSupplierTest.java    |  7 +--
 .../org/apache/commons/lang3/function/Objects.java |  0
 .../apache/commons/lang3/function/ObjectsTest.java |  0
 .../commons/lang3/reflect/MethodUtilsTest.java     | 13 ++--
 .../apache/commons/lang3/stream/StreamsTest.java   | 20 +++----
 .../apache/commons/lang3/time/StopWatchTest.java   | 24 ++++----
 25 files changed, 158 insertions(+), 183 deletions(-)