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 2022/08/26 19:09:00 UTC

[commons-lang] branch master updated (e505c0866 -> 161c08bac)

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 e505c0866 Bump maven-pmd-plugin from 3.17.0 to 3.18.0
     new dafea7572 PMD: Remove useless parens
     new 7cb81aa26 PMD: Remove extra parens
     new dec5675c2 Remove obsolete comment
     new ad849fa8a Remove obsolete comment
     new 7d8701ebf Sort members
     new ce40e5bdf Sort members
     new 49ef6b530 PMD: Implement equals()
     new 9b0e54e09 PMD: Implement equals()
     new b6739ab92 PMD: Avoid using a branching statement as the last in a loop.
     new 161c08bac Enable PMD check with 2 exclusions (for now)

The 10 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:
 pom.xml                                            |   3 +-
 src/changes/changes.xml                            |   1 +
 .gitattributes => src/conf/exclude-pmd.properties  |  15 +-
 .../java/org/apache/commons/lang3/ArrayUtils.java  |   4 +-
 .../java/org/apache/commons/lang3/StringUtils.java |   8 +-
 .../commons/lang3/builder/HashCodeBuilder.java     |  94 ++--
 .../lang3/builder/StandardToStringStyle.java       |  80 +--
 .../commons/lang3/exception/ExceptionUtils.java    |   4 +-
 .../apache/commons/lang3/reflect/MethodUtils.java  |   2 +-
 .../apache/commons/lang3/reflect/TypeUtils.java    |   6 +-
 .../org/apache/commons/lang3/text/StrBuilder.java  |  94 +---
 .../commons/lang3/builder/HashCodeBuilderTest.java | 585 +++++++++++----------
 12 files changed, 436 insertions(+), 460 deletions(-)
 copy .gitattributes => src/conf/exclude-pmd.properties (63%)


[commons-lang] 01/10: PMD: Remove useless parens

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 dafea7572280809f4bd19f33feedbdf2666bd526
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:19:40 2022 -0400

    PMD: Remove useless parens
---
 .../org/apache/commons/lang3/text/StrBuilder.java  | 46 +++++++++++-----------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
index 3d2a76bd8..e58c9e6f9 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
@@ -608,7 +608,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (startIndex < 0 || startIndex > str.length()) {
             throw new StringIndexOutOfBoundsException("startIndex must be valid");
         }
-        if (length < 0 || (startIndex + length) > str.length()) {
+        if (length < 0 || startIndex + length > str.length()) {
             throw new StringIndexOutOfBoundsException("length must be valid");
         }
         if (length > 0) {
@@ -676,7 +676,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
             if (startIndex < 0 || startIndex > totalLength) {
                 throw new StringIndexOutOfBoundsException("startIndex must be valid");
             }
-            if (length < 0 || (startIndex + length) > totalLength) {
+            if (length < 0 || startIndex + length > totalLength) {
                 throw new StringIndexOutOfBoundsException("length must be valid");
             }
             final int len = length();
@@ -726,7 +726,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (startIndex < 0 || startIndex > str.length()) {
             throw new StringIndexOutOfBoundsException("startIndex must be valid");
         }
-        if (length < 0 || (startIndex + length) > str.length()) {
+        if (length < 0 || startIndex + length > str.length()) {
             throw new StringIndexOutOfBoundsException("length must be valid");
         }
         if (length > 0) {
@@ -777,7 +777,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (startIndex < 0 || startIndex > str.length()) {
             throw new StringIndexOutOfBoundsException("startIndex must be valid");
         }
-        if (length < 0 || (startIndex + length) > str.length()) {
+        if (length < 0 || startIndex + length > str.length()) {
             throw new StringIndexOutOfBoundsException("length must be valid");
         }
         if (length > 0) {
@@ -826,7 +826,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (startIndex < 0 || startIndex > str.length()) {
             throw new StringIndexOutOfBoundsException("startIndex must be valid");
         }
-        if (length < 0 || (startIndex + length) > str.length()) {
+        if (length < 0 || startIndex + length > str.length()) {
             throw new StringIndexOutOfBoundsException("length must be valid");
         }
         if (length > 0) {
@@ -875,7 +875,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (startIndex < 0 || startIndex > chars.length) {
             throw new StringIndexOutOfBoundsException("Invalid startIndex: " + length);
         }
-        if (length < 0 || (startIndex + length) > chars.length) {
+        if (length < 0 || startIndex + length > chars.length) {
             throw new StringIndexOutOfBoundsException("Invalid length: " + length);
         }
         if (length > 0) {
@@ -1509,7 +1509,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
     public StrBuilder appendFixedWidthPadLeft(final Object obj, final int width, final char padChar) {
         if (width > 0) {
             ensureCapacity(size + width);
-            String str = (obj == null ? getNullText() : obj.toString());
+            String str = obj == null ? getNullText() : obj.toString();
             if (str == null) {
                 str = StringUtils.EMPTY;
             }
@@ -1556,7 +1556,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
     public StrBuilder appendFixedWidthPadRight(final Object obj, final int width, final char padChar) {
         if (width > 0) {
             ensureCapacity(size + width);
-            String str = (obj == null ? getNullText() : obj.toString());
+            String str = obj == null ? getNullText() : obj.toString();
             if (str == null) {
                 str = StringUtils.EMPTY;
             }
@@ -1860,7 +1860,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return this, to enable chaining
      */
     public StrBuilder deleteAll(final String str) {
-        final int len = (str == null ? 0 : str.length());
+        final int len = str == null ? 0 : str.length();
         if (len > 0) {
             int index = indexOf(str, 0);
             while (index >= 0) {
@@ -1878,7 +1878,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return this, to enable chaining
      */
     public StrBuilder deleteFirst(final String str) {
-        final int len = (str == null ? 0 : str.length());
+        final int len = str == null ? 0 : str.length();
         if (len > 0) {
             final int index = indexOf(str, 0);
             if (index >= 0) {
@@ -1953,7 +1953,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      */
     public StrBuilder replace(final int startIndex, int endIndex, final String replaceStr) {
         endIndex = validateRange(startIndex, endIndex);
-        final int insertLen = (replaceStr == null ? 0 : replaceStr.length());
+        final int insertLen = replaceStr == null ? 0 : replaceStr.length();
         replaceImpl(startIndex, endIndex, endIndex - startIndex, replaceStr, insertLen);
         return this;
     }
@@ -2005,9 +2005,9 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return this, to enable chaining
      */
     public StrBuilder replaceAll(final String searchStr, final String replaceStr) {
-        final int searchLen = (searchStr == null ? 0 : searchStr.length());
+        final int searchLen = searchStr == null ? 0 : searchStr.length();
         if (searchLen > 0) {
-            final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
+            final int replaceLen = replaceStr == null ? 0 : replaceStr.length();
             int index = indexOf(searchStr, 0);
             while (index >= 0) {
                 replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen);
@@ -2025,11 +2025,11 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return this, to enable chaining
      */
     public StrBuilder replaceFirst(final String searchStr, final String replaceStr) {
-        final int searchLen = (searchStr == null ? 0 : searchStr.length());
+        final int searchLen = searchStr == null ? 0 : searchStr.length();
         if (searchLen > 0) {
             final int index = indexOf(searchStr, 0);
             if (index >= 0) {
-                final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
+                final int replaceLen = replaceStr == null ? 0 : replaceStr.length();
                 replaceImpl(index, index + searchLen, searchLen, replaceStr, replaceLen);
             }
         }
@@ -2114,7 +2114,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         if (matcher == null || size == 0) {
             return this;
         }
-        final int replaceLen = (replaceStr == null ? 0 : replaceStr.length());
+        final int replaceLen = replaceStr == null ? 0 : replaceStr.length();
         for (int i = from; i < to && replaceCount != 0; i++) {
             final char[] buf = buffer;
             final int removeLen = matcher.isMatch(buf, i, from, to);
@@ -2419,7 +2419,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the first index of the character, or -1 if not found
      */
     public int indexOf(final char ch, int startIndex) {
-        startIndex = (Math.max(startIndex, 0));
+        startIndex = Math.max(startIndex, 0);
         if (startIndex >= size) {
             return -1;
         }
@@ -2457,7 +2457,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the first index of the string, or -1 if not found
      */
     public int indexOf(final String str, int startIndex) {
-        startIndex = (Math.max(startIndex, 0));
+        startIndex = Math.max(startIndex, 0);
         if (str == null || startIndex >= size) {
             return -1;
         }
@@ -2514,7 +2514,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the first index matched, or -1 if not found
      */
     public int indexOf(final StrMatcher matcher, int startIndex) {
-        startIndex = (Math.max(startIndex, 0));
+        startIndex = Math.max(startIndex, 0);
         if (matcher == null || startIndex >= size) {
             return -1;
         }
@@ -2546,7 +2546,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the last index of the character, or -1 if not found
      */
     public int lastIndexOf(final char ch, int startIndex) {
-        startIndex = (startIndex >= size ? size - 1 : startIndex);
+        startIndex = startIndex >= size ? size - 1 : startIndex;
         if (startIndex < 0) {
             return -1;
         }
@@ -2583,7 +2583,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the last index of the string, or -1 if not found
      */
     public int lastIndexOf(final String str, int startIndex) {
-        startIndex = (startIndex >= size ? size - 1 : startIndex);
+        startIndex = startIndex >= size ? size - 1 : startIndex;
         if (str == null || startIndex < 0) {
             return -1;
         }
@@ -2638,7 +2638,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the last index matched, or -1 if not found
      */
     public int lastIndexOf(final StrMatcher matcher, int startIndex) {
-        startIndex = (startIndex >= size ? size - 1 : startIndex);
+        startIndex = startIndex >= size ? size - 1 : startIndex;
         if (matcher == null || startIndex < 0) {
             return -1;
         }
@@ -3001,7 +3001,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
         @Override
         public int read(final char[] b, final int off, int len) {
             if (off < 0 || len < 0 || off > b.length ||
-                    (off + len) > b.length || (off + len) < 0) {
+                    off + len > b.length || off + len < 0) {
                 throw new IndexOutOfBoundsException();
             }
             if (len == 0) {


[commons-lang] 10/10: Enable PMD check with 2 exclusions (for now)

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 161c08bacd37d15243ab869f29d43125fb559511
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 15:07:27 2022 -0400

    Enable PMD check with 2 exclusions (for now)
---
 pom.xml                         |  3 ++-
 src/conf/exclude-pmd.properties | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 3332789fe..054e7310f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -668,7 +668,7 @@
   </properties>
 
   <build>
-   <defaultGoal>clean verify apache-rat:check checkstyle:check japicmp:cmp spotbugs:check javadoc:javadoc</defaultGoal>
+   <defaultGoal>clean verify apache-rat:check checkstyle:check japicmp:cmp spotbugs:check pmd:check javadoc:javadoc</defaultGoal>
    <pluginManagement>
       <plugins>
         <plugin>
@@ -699,6 +699,7 @@
           </dependencies>
           <configuration>
             <targetJdk>${maven.compiler.target}</targetJdk>
+            <excludeFromFailureFile>src/conf/exclude-pmd.properties</excludeFromFailureFile>
           </configuration>
         </plugin>
         <plugin>
diff --git a/src/conf/exclude-pmd.properties b/src/conf/exclude-pmd.properties
new file mode 100644
index 000000000..955182b35
--- /dev/null
+++ b/src/conf/exclude-pmd.properties
@@ -0,0 +1,21 @@
+# 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.
+
+# We have ThreadGroup utilities
+org.apache.commons.lang3.ThreadUtils=AvoidThreadGroup
+
+# TODO?
+# violation beginline="2900" endline="2900" begincolumn="13" endcolumn="21" rule="AvoidBranchingStatementAsLastInLoop" ruleset="Error Prone" package="org.apache.commons.lang3" class="StringUtils" method="indexOfAnyBut"
+org.apache.commons.lang3.StringUtils=AvoidBranchingStatementAsLastInLoop


[commons-lang] 08/10: PMD: Implement equals()

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 9b0e54e096e4ad467fb6673fed70fba731b672f6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 15:00:38 2022 -0400

    PMD: Implement equals()
---
 src/changes/changes.xml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index eab05fef5..e6516eb95 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -174,6 +174,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action issue="LANG-1689" type="add" dev="ggregory" due-to="Joseph Hendrix, Gary Gregory">Simple support for Optional in ObjectUtils#isEmpty() #933.</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add Processor.Type.getLabel().</action>
     <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add Processor.toString().</action>
+    <action                   type="add" dev="ggregory" due-to="Gary Gregory">Add HashCodeBuilder.equals(Object).</action>
     <!-- UPDATE -->
     <action                   type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.8 #742, #752, #764, #833, #867.</action>
     <action                   type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>


[commons-lang] 07/10: PMD: Implement equals()

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 49ef6b530c89c5f7181aa3fbdb957155a6802b05
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:57:21 2022 -0400

    PMD: Implement equals()
---
 .../org/apache/commons/lang3/builder/HashCodeBuilder.java  | 14 +++++++++++++-
 .../apache/commons/lang3/builder/HashCodeBuilderTest.java  | 13 +++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
index e8e603998..cc67e86aa 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -746,7 +746,7 @@ public class HashCodeBuilder implements Builder<Integer> {
     //       some stage. There are backwards compat issues, so
     //       that will have to wait for the time being. cf LANG-342.
     public HashCodeBuilder append(final long value) {
-        iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+        iTotal = iTotal * iConstant + (int) (value ^ value >> 32);
         return this;
     }
 
@@ -893,6 +893,18 @@ public class HashCodeBuilder implements Builder<Integer> {
         return Integer.valueOf(toHashCode());
     }
 
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof HashCodeBuilder)) {
+            return false;
+        }
+        final HashCodeBuilder other = (HashCodeBuilder) obj;
+        return iTotal == other.iTotal;
+    }
+
     /**
      * The computed {@code hashCode} from toHashCode() is returned due to the likelihood
      * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
diff --git a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
index 8741f2104..cf045e946 100644
--- a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
@@ -18,6 +18,7 @@
 package org.apache.commons.lang3.builder;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
@@ -331,6 +332,18 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
     }
 
+    @Test
+    public void testEquals() {
+        final HashCodeBuilder hcb1 = new HashCodeBuilder(17, 37).append(1).append('a');
+        final HashCodeBuilder hcb2 = new HashCodeBuilder(17, 37).append(1).append('a');
+        final HashCodeBuilder hcb3 = new HashCodeBuilder(17, 37).append(2).append('c');
+        assertEquals(hcb1, hcb1);
+        assertEquals(hcb1, hcb2);
+        assertEquals(hcb2, hcb1);
+        assertNotEquals(hcb1, hcb3);
+        assertNotEquals(hcb2, hcb3);
+    }
+
     @Test
     public void testFloat() {
         assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0f).toHashCode());


[commons-lang] 02/10: PMD: Remove extra parens

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 7cb81aa26f1afcfa7b2babd7b3e7ff9a4e8b5733
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:29:24 2022 -0400

    PMD: Remove extra parens
---
 src/main/java/org/apache/commons/lang3/ArrayUtils.java          | 4 ++--
 src/main/java/org/apache/commons/lang3/StringUtils.java         | 8 ++++----
 src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java | 2 +-
 src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java   | 6 +++---
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index fb90edc6d..eef29dc7b 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -2478,7 +2478,7 @@ public class ArrayUtils {
         final boolean searchNaN = Double.isNaN(valueToFind);
         for (int i = startIndex; i < array.length; i++) {
             final double element = array[i];
-            if (valueToFind == element || (searchNaN && Double.isNaN(element))) {
+            if (valueToFind == element || searchNaN && Double.isNaN(element)) {
                 return i;
             }
         }
@@ -2562,7 +2562,7 @@ public class ArrayUtils {
         final boolean searchNaN = Float.isNaN(valueToFind);
         for (int i = startIndex; i < array.length; i++) {
             final float element = array[i];
-            if (valueToFind == element || (searchNaN && Float.isNaN(element))) {
+            if (valueToFind == element || searchNaN && Float.isNaN(element)) {
                 return i;
             }
         }
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index b242191a3..eddebf700 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -2756,7 +2756,7 @@ public class StringUtils {
             final char ch = cs.charAt(i);
             for (int j = 0; j < searchLen; j++) {
                 if (searchChars[j] == ch) {
-                    if ((i >= csLast) || (j >= searchLast) || !Character.isHighSurrogate(ch)) {
+                    if (i >= csLast || j >= searchLast || !Character.isHighSurrogate(ch)) {
                         return i;
                     }
                     // ch is a supplementary character
@@ -2889,7 +2889,7 @@ public class StringUtils {
             final char ch = cs.charAt(i);
             for (int j = 0; j < searchLen; j++) {
                 if (searchChars[j] == ch) {
-                    if ((i >= csLast) || (j >= searchLast) || !Character.isHighSurrogate(ch)) {
+                    if (i >= csLast || j >= searchLast || !Character.isHighSurrogate(ch)) {
                         continue outer;
                     }
                     if (searchChars[j + 1] == cs.charAt(i + 1)) {
@@ -5486,7 +5486,7 @@ public class StringUtils {
                 whitespacesCount++;
             } else {
                 startWhitespaces = false;
-                newChars[count++] = (actualChar == 160 ? 32 : actualChar);
+                newChars[count++] = actualChar == 160 ? 32 : actualChar;
                 whitespacesCount = 0;
             }
         }
@@ -6636,7 +6636,7 @@ public class StringUtils {
             }
         }
 
-        if (isEmpty(text) || ArrayUtils.isEmpty(searchList) || ArrayUtils.isEmpty(replacementList) || (ArrayUtils.isNotEmpty(searchList) && timeToLive == -1)) {
+        if (isEmpty(text) || ArrayUtils.isEmpty(searchList) || ArrayUtils.isEmpty(replacementList) || ArrayUtils.isNotEmpty(searchList) && timeToLive == -1) {
             return text;
         }
 
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 5e1ba2ce4..ce904f562 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -993,7 +993,7 @@ public class MethodUtils {
             final Class<?> acls;
             if (interfaceIndex >= allInterfaces.size()) {
                 acls = allSuperclasses.get(superClassIndex++);
-            } else if ((superClassIndex >= allSuperclasses.size()) || !(superClassIndex < interfaceIndex)) {
+            } else if (superClassIndex >= allSuperclasses.size() || !(superClassIndex < interfaceIndex)) {
                 acls = allInterfaces.get(interfaceIndex++);
             } else {
                 acls = allSuperclasses.get(superClassIndex++);
diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
index c8ead80a3..68de4ccab 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java
@@ -124,7 +124,7 @@ public class TypeUtils {
          */
         @Override
         public boolean equals(final Object obj) {
-            return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, ((ParameterizedType) obj));
+            return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, (ParameterizedType) obj);
         }
 
         /**
@@ -566,8 +566,8 @@ public class TypeUtils {
             parameterizedType.getActualTypeArguments().length);
         int[] indexesToRemove = {};
         for (int i = 0; i < filteredArgumentTypes.length; i++) {
-            if ((filteredArgumentTypes[i] instanceof TypeVariable<?>) && containsVariableTypeSameParametrizedTypeBound(
-                ((TypeVariable<?>) filteredArgumentTypes[i]), parameterizedType)) {
+            if (filteredArgumentTypes[i] instanceof TypeVariable<?> && containsVariableTypeSameParametrizedTypeBound(
+                (TypeVariable<?>) filteredArgumentTypes[i], parameterizedType)) {
                 indexesToRemove = ArrayUtils.add(indexesToRemove, i);
             }
         }


[commons-lang] 05/10: Sort members

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 7d8701ebf46755b9a8639aa4dc392f06ed10d57c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:43:02 2022 -0400

    Sort members
---
 .../commons/lang3/builder/HashCodeBuilder.java     | 80 +++++++++++-----------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
index bf33b850e..e8e603998 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -789,37 +789,6 @@ public class HashCodeBuilder implements Builder<Integer> {
         return this;
     }
 
-    /**
-     * Append a {@code hashCode} for an array.
-     *
-     * @param object
-     *            the array to add to the {@code hashCode}
-     */
-    private void appendArray(final Object object) {
-        // 'Switch' on type of array, to dispatch to the correct handler
-        // This handles multidimensional arrays
-        if (object instanceof long[]) {
-            append((long[]) object);
-        } else if (object instanceof int[]) {
-            append((int[]) object);
-        } else if (object instanceof short[]) {
-            append((short[]) object);
-        } else if (object instanceof char[]) {
-            append((char[]) object);
-        } else if (object instanceof byte[]) {
-            append((byte[]) object);
-        } else if (object instanceof double[]) {
-            append((double[]) object);
-        } else if (object instanceof float[]) {
-            append((float[]) object);
-        } else if (object instanceof boolean[]) {
-            append((boolean[]) object);
-        } else {
-            // Not an array of primitives
-            append((Object[]) object);
-        }
-    }
-
     /**
      * Append a {@code hashCode} for an {@link Object} array.
      *
@@ -868,6 +837,37 @@ public class HashCodeBuilder implements Builder<Integer> {
         return this;
     }
 
+    /**
+     * Append a {@code hashCode} for an array.
+     *
+     * @param object
+     *            the array to add to the {@code hashCode}
+     */
+    private void appendArray(final Object object) {
+        // 'Switch' on type of array, to dispatch to the correct handler
+        // This handles multidimensional arrays
+        if (object instanceof long[]) {
+            append((long[]) object);
+        } else if (object instanceof int[]) {
+            append((int[]) object);
+        } else if (object instanceof short[]) {
+            append((short[]) object);
+        } else if (object instanceof char[]) {
+            append((char[]) object);
+        } else if (object instanceof byte[]) {
+            append((byte[]) object);
+        } else if (object instanceof double[]) {
+            append((double[]) object);
+        } else if (object instanceof float[]) {
+            append((float[]) object);
+        } else if (object instanceof boolean[]) {
+            append((boolean[]) object);
+        } else {
+            // Not an array of primitives
+            append((Object[]) object);
+        }
+    }
+
     /**
      * Adds the result of super.hashCode() to this builder.
      *
@@ -881,15 +881,6 @@ public class HashCodeBuilder implements Builder<Integer> {
         return this;
     }
 
-    /**
-     * Returns the computed {@code hashCode}.
-     *
-     * @return {@code hashCode} based on the fields appended
-     */
-    public int toHashCode() {
-        return iTotal;
-    }
-
     /**
      * Returns the computed {@code hashCode}.
      *
@@ -915,4 +906,13 @@ public class HashCodeBuilder implements Builder<Integer> {
         return toHashCode();
     }
 
+    /**
+     * Returns the computed {@code hashCode}.
+     *
+     * @return {@code hashCode} based on the fields appended
+     */
+    public int toHashCode() {
+        return iTotal;
+    }
+
 }


[commons-lang] 03/10: Remove obsolete 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 dec5675c224f9064420793335ee25abd03876f81
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:33:34 2022 -0400

    Remove obsolete comment
---
 src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java | 4 ++--
 1 file changed, 2 insertions(+), 2 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 46c0e2d7f..218fab913 100644
--- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
+++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java
@@ -156,14 +156,14 @@ public class ExceptionUtils {
             Method method = null;
             try {
                 method = throwable.getClass().getMethod(methodName);
-            } catch (final NoSuchMethodException | SecurityException ignored) { // NOPMD
+            } catch (final NoSuchMethodException | SecurityException ignored) {
                 // exception ignored
             }
 
             if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
                 try {
                     return (Throwable) method.invoke(throwable);
-                } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) { // NOPMD
+                } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
                     // exception ignored
                 }
             }


[commons-lang] 06/10: Sort members

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 ce40e5bdf29138c17b934b84206b31ece5ebd3e3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:48:19 2022 -0400

    Sort members
---
 .../commons/lang3/builder/HashCodeBuilderTest.java | 572 ++++++++++-----------
 1 file changed, 286 insertions(+), 286 deletions(-)

diff --git a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
index d2ae2f207..8741f2104 100644
--- a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
+++ b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java
@@ -53,26 +53,6 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         }
     }
 
-    @Test
-    public void testConstructorExZero() {
-        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(0, 0));
-    }
-
-    @Test
-    public void testConstructorExEvenFirst() {
-        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(2, 3));
-    }
-
-    @Test
-    public void testConstructorExEvenSecond() {
-        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(3, 2));
-    }
-
-    @Test
-    public void testConstructorExEvenNegative() {
-        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(-2, -2));
-    }
-
     static class TestObject {
         private int a;
 
@@ -92,6 +72,10 @@ public class HashCodeBuilderTest extends AbstractLangTest {
             return a == rhs.a;
         }
 
+        public int getA() {
+            return a;
+        }
+
         @Override
         public int hashCode() {
             return a;
@@ -100,10 +84,62 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         public void setA(final int a) {
             this.a = a;
         }
+    }
+
+    static class TestObjectHashCodeExclude {
+        @HashCodeExclude
+        private final int a;
+        private final int b;
+
+        TestObjectHashCodeExclude(final int a, final int b) {
+            this.a = a;
+            this.b = b;
+        }
 
         public int getA() {
             return a;
         }
+
+        public int getB() {
+            return b;
+        }
+    }
+
+    static class TestObjectHashCodeExclude2 {
+        @HashCodeExclude
+        private final int a;
+        @HashCodeExclude
+        private final int b;
+
+        TestObjectHashCodeExclude2(final int a, final int b) {
+            this.a = a;
+            this.b = b;
+        }
+
+        public int getA() {
+            return a;
+        }
+
+        public int getB() {
+            return b;
+        }
+    }
+
+    static class TestObjectWithMultipleFields {
+        @SuppressWarnings("unused")
+        private int one = 0;
+
+        @SuppressWarnings("unused")
+        private int two = 0;
+
+        @SuppressWarnings("unused")
+        private int three = 0;
+
+        TestObjectWithMultipleFields(final int one, final int two, final int three) {
+            this.one = one;
+            this.two = two;
+            this.three = three;
+        }
     }
 
     static class TestSubObject extends TestObject {
@@ -141,117 +177,6 @@ public class HashCodeBuilderTest extends AbstractLangTest {
 
     }
 
-    @Test
-    public void testReflectionHashCode() {
-        assertEquals(17 * 37, HashCodeBuilder.reflectionHashCode(new TestObject(0)));
-        assertEquals(17 * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestObject(123456)));
-    }
-
-    @Test
-    public void testReflectionHierarchyHashCode() {
-        assertEquals(17 * 37 * 37, HashCodeBuilder.reflectionHashCode(new TestSubObject(0, 0, 0)));
-        assertEquals(17 * 37 * 37 * 37, HashCodeBuilder.reflectionHashCode(new TestSubObject(0, 0, 0), true));
-        assertEquals((17 * 37 + 7890) * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestSubObject(123456, 7890,
-                0)));
-        assertEquals(((17 * 37 + 7890) * 37 + 0) * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestSubObject(
-                123456, 7890, 0), true));
-    }
-
-    @Test
-    public void testReflectionHierarchyHashCodeEx1() {
-        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(0, 0, new TestSubObject(0, 0, 0), true));
-    }
-
-    @Test
-    public void testReflectionHierarchyHashCodeEx2() {
-        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(2, 2, new TestSubObject(0, 0, 0), true));
-    }
-
-    @Test
-    public void testReflectionHashCodeEx1() {
-        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(0, 0, new TestObject(0), true));
-    }
-
-    @Test
-    public void testReflectionHashCodeEx2() {
-        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(2, 2, new TestObject(0), true));
-    }
-
-    @Test
-    public void testReflectionHashCodeEx3() {
-        assertThrows(NullPointerException.class, () -> HashCodeBuilder.reflectionHashCode(13, 19, null, true));
-    }
-
-    @Test
-    public void testSuper() {
-        final Object obj = new Object();
-        assertEquals(17 * 37 + 19 * 41 + obj.hashCode(), new HashCodeBuilder(17, 37).appendSuper(
-                new HashCodeBuilder(19, 41).append(obj).toHashCode()).toHashCode());
-    }
-
-    @Test
-    public void testObject() {
-        Object obj = null;
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj = new Object();
-        assertEquals(17 * 37 + obj.hashCode(), new HashCodeBuilder(17, 37).append(obj).toHashCode());
-    }
-
-    @Test
-    public void testObjectBuild() {
-        Object obj = null;
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).build().intValue());
-        obj = new Object();
-        assertEquals(17 * 37 + obj.hashCode(), new HashCodeBuilder(17, 37).append(obj).build().intValue());
-    }
-
-    @Test
-    public void testLong() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0L).toHashCode());
-        assertEquals(17 * 37 + (int) (123456789L ^ 123456789L >> 32), new HashCodeBuilder(17, 37).append(
-                123456789L).toHashCode());
-    }
-
-    @Test
-    public void testInt() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0).toHashCode());
-        assertEquals(17 * 37 + 123456, new HashCodeBuilder(17, 37).append(123456).toHashCode());
-    }
-
-    @Test
-    public void testShort() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short) 0).toHashCode());
-        assertEquals(17 * 37 + 12345, new HashCodeBuilder(17, 37).append((short) 12345).toHashCode());
-    }
-
-    @Test
-    public void testChar() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((char) 0).toHashCode());
-        assertEquals(17 * 37 + 1234, new HashCodeBuilder(17, 37).append((char) 1234).toHashCode());
-    }
-
-    @Test
-    public void testByte() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte) 0).toHashCode());
-        assertEquals(17 * 37 + 123, new HashCodeBuilder(17, 37).append((byte) 123).toHashCode());
-    }
-
-    @Test
-    public void testDouble() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0d).toHashCode());
-        final double d = 1234567.89;
-        final long l = Double.doubleToLongBits(d);
-        assertEquals(17 * 37 + (int) (l ^ l >> 32), new HashCodeBuilder(17, 37).append(d).toHashCode());
-    }
-
-    @Test
-    public void testFloat() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0f).toHashCode());
-        final float f = 1234.89f;
-        final int i = Float.floatToIntBits(f);
-        assertEquals(17 * 37 + i, new HashCodeBuilder(17, 37).append(f).toHashCode());
-    }
-
     @Test
     public void testBoolean() {
         assertEquals(17 * 37 + 0, new HashCodeBuilder(17, 37).append(true).toHashCode());
@@ -259,93 +184,73 @@ public class HashCodeBuilderTest extends AbstractLangTest {
     }
 
     @Test
-    public void testObjectArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((Object[]) null).toHashCode());
-        final Object[] obj = new Object[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = new Object();
-        assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = new Object();
-        assertEquals((17 * 37 + obj[0].hashCode()) * 37 + obj[1].hashCode(), new HashCodeBuilder(17, 37).append(obj)
-                .toHashCode());
+    public void testBooleanArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((boolean[]) null).toHashCode());
+        final boolean[] obj = new boolean[2];
+        assertEquals((17 * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = true;
+        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = false;
+        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
     }
 
     @Test
-    public void testObjectArrayAsObject() {
-        final Object[] obj = new Object[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = new Object();
-        assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = new Object();
-        assertEquals((17 * 37 + obj[0].hashCode()) * 37 + obj[1].hashCode(), new HashCodeBuilder(17, 37).append(
-                (Object) obj).toHashCode());
+    public void testBooleanArrayAsObject() {
+        final boolean[] obj = new boolean[2];
+        assertEquals((17 * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[0] = true;
+        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[1] = false;
+        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
     }
 
     @Test
-    public void testLongArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long[]) null).toHashCode());
-        final long[] obj = new long[2];
+    public void testBooleanMultiArray() {
+        final boolean[][] obj = new boolean[2][];
         assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = 5L;
-        final int h1 = (int) (5L ^ 5L >> 32);
-        assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = 6L;
-        final int h2 = (int) (6L ^ 6L >> 32);
-        assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = new boolean[0];
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = new boolean[1];
+        assertEquals((17 * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = new boolean[2];
+        assertEquals(((17 * 37 + 1) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0][0] = true;
+        assertEquals(((17 * 37 + 0) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = new boolean[1];
+        assertEquals(((17 * 37 + 0) * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
     }
 
     @Test
-    public void testLongArrayAsObject() {
-        final long[] obj = new long[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = 5L;
-        final int h1 = (int) (5L ^ 5L >> 32);
-        assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = 6L;
-        final int h2 = (int) (6L ^ 6L >> 32);
-        assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    public void testByte() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte) 0).toHashCode());
+        assertEquals(17 * 37 + 123, new HashCodeBuilder(17, 37).append((byte) 123).toHashCode());
     }
 
     @Test
-    public void testIntArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((int[]) null).toHashCode());
-        final int[] obj = new int[2];
+    public void testByteArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte[]) null).toHashCode());
+        final byte[] obj = new byte[2];
         assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = 5;
+        obj[0] = (byte) 5;
         assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = 6;
+        obj[1] = (byte) 6;
         assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append(obj).toHashCode());
     }
 
     @Test
-    public void testIntArrayAsObject() {
-        final int[] obj = new int[2];
+    public void testByteArrayAsObject() {
+        final byte[] obj = new byte[2];
         assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = 5;
+        obj[0] = (byte) 5;
         assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = 6;
+        obj[1] = (byte) 6;
         assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
     }
 
     @Test
-    public void testShortArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short[]) null).toHashCode());
-        final short[] obj = new short[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = (short) 5;
-        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = (short) 6;
-        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-    }
-
-    @Test
-    public void testShortArrayAsObject() {
-        final short[] obj = new short[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = (short) 5;
-        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = (short) 6;
-        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    public void testChar() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((char) 0).toHashCode());
+        assertEquals(17 * 37 + 1234, new HashCodeBuilder(17, 37).append((char) 1234).toHashCode());
     }
 
     @Test
@@ -370,24 +275,31 @@ public class HashCodeBuilderTest extends AbstractLangTest {
     }
 
     @Test
-    public void testByteArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte[]) null).toHashCode());
-        final byte[] obj = new byte[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = (byte) 5;
-        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = (byte) 6;
-        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+    public void testConstructorExEvenFirst() {
+        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(2, 3));
+    }
+
+    @Test
+    public void testConstructorExEvenNegative() {
+        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(-2, -2));
+    }
+
+    @Test
+    public void testConstructorExEvenSecond() {
+        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(3, 2));
+    }
+
+    @Test
+    public void testConstructorExZero() {
+        assertThrows(IllegalArgumentException.class, () -> new HashCodeBuilder(0, 0));
     }
 
     @Test
-    public void testByteArrayAsObject() {
-        final byte[] obj = new byte[2];
-        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = (byte) 5;
-        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = (byte) 6;
-        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    public void testDouble() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0d).toHashCode());
+        final double d = 1234567.89;
+        final long l = Double.doubleToLongBits(d);
+        assertEquals(17 * 37 + (int) (l ^ l >> 32), new HashCodeBuilder(17, 37).append(d).toHashCode());
     }
 
     @Test
@@ -419,6 +331,14 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
     }
 
+    @Test
+    public void testFloat() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0f).toHashCode());
+        final float f = 1234.89f;
+        final int i = Float.floatToIntBits(f);
+        assertEquals(17 * 37 + i, new HashCodeBuilder(17, 37).append(f).toHashCode());
+    }
+
     @Test
     public void testFloatArray() {
         assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((float[]) null).toHashCode());
@@ -445,40 +365,122 @@ public class HashCodeBuilderTest extends AbstractLangTest {
     }
 
     @Test
-    public void testBooleanArray() {
-        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((boolean[]) null).toHashCode());
-        final boolean[] obj = new boolean[2];
-        assertEquals((17 * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = true;
-        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = false;
-        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+    public void testInt() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0).toHashCode());
+        assertEquals(17 * 37 + 123456, new HashCodeBuilder(17, 37).append(123456).toHashCode());
     }
 
     @Test
-    public void testBooleanArrayAsObject() {
-        final boolean[] obj = new boolean[2];
-        assertEquals((17 * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[0] = true;
-        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
-        obj[1] = false;
-        assertEquals((17 * 37 + 0) * 37 + 1, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    public void testIntArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((int[]) null).toHashCode());
+        final int[] obj = new int[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = 5;
+        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = 6;
+        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append(obj).toHashCode());
     }
 
     @Test
-    public void testBooleanMultiArray() {
-        final boolean[][] obj = new boolean[2][];
+    public void testIntArrayAsObject() {
+        final int[] obj = new int[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[0] = 5;
+        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[1] = 6;
+        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    }
+
+    @Test
+    public void testLong() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(0L).toHashCode());
+        assertEquals(17 * 37 + (int) (123456789L ^ 123456789L >> 32), new HashCodeBuilder(17, 37).append(
+                123456789L).toHashCode());
+    }
+
+    @Test
+    public void testLongArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long[]) null).toHashCode());
+        final long[] obj = new long[2];
         assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = new boolean[0];
+        obj[0] = 5L;
+        final int h1 = (int) (5L ^ 5L >> 32);
+        assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = 6L;
+        final int h2 = (int) (6L ^ 6L >> 32);
+        assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+    }
+
+    @Test
+    public void testLongArrayAsObject() {
+        final long[] obj = new long[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[0] = 5L;
+        final int h1 = (int) (5L ^ 5L >> 32);
+        assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[1] = 6L;
+        final int h2 = (int) (6L ^ 6L >> 32);
+        assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    }
+
+    @Test
+    public void testObject() {
+        Object obj = null;
         assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = new boolean[1];
-        assertEquals((17 * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0] = new boolean[2];
-        assertEquals(((17 * 37 + 1) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[0][0] = true;
-        assertEquals(((17 * 37 + 0) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
-        obj[1] = new boolean[1];
-        assertEquals(((17 * 37 + 0) * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj = new Object();
+        assertEquals(17 * 37 + obj.hashCode(), new HashCodeBuilder(17, 37).append(obj).toHashCode());
+    }
+
+    @Test
+    public void testObjectArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((Object[]) null).toHashCode());
+        final Object[] obj = new Object[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = new Object();
+        assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = new Object();
+        assertEquals((17 * 37 + obj[0].hashCode()) * 37 + obj[1].hashCode(), new HashCodeBuilder(17, 37).append(obj)
+                .toHashCode());
+    }
+
+    @Test
+    public void testObjectArrayAsObject() {
+        final Object[] obj = new Object[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[0] = new Object();
+        assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[1] = new Object();
+        assertEquals((17 * 37 + obj[0].hashCode()) * 37 + obj[1].hashCode(), new HashCodeBuilder(17, 37).append(
+                (Object) obj).toHashCode());
+    }
+
+    @Test
+    public void testObjectBuild() {
+        Object obj = null;
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).build().intValue());
+        obj = new Object();
+        assertEquals(17 * 37 + obj.hashCode(), new HashCodeBuilder(17, 37).append(obj).build().intValue());
+    }
+
+    @Test
+    public void testReflectionHashCode() {
+        assertEquals(17 * 37, HashCodeBuilder.reflectionHashCode(new TestObject(0)));
+        assertEquals(17 * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestObject(123456)));
+    }
+
+    @Test
+    public void testReflectionHashCodeEx1() {
+        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(0, 0, new TestObject(0), true));
+    }
+
+    @Test
+    public void testReflectionHashCodeEx2() {
+        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(2, 2, new TestObject(0), true));
+    }
+
+    @Test
+    public void testReflectionHashCodeEx3() {
+        assertThrows(NullPointerException.class, () -> HashCodeBuilder.reflectionHashCode(13, 19, null, true));
     }
 
     @Test
@@ -500,21 +502,24 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         assertEquals(17, HashCodeBuilder.reflectionHashCode(x, "one", "two", "three", "xxx"));
     }
 
-    static class TestObjectWithMultipleFields {
-        @SuppressWarnings("unused")
-        private int one = 0;
-
-        @SuppressWarnings("unused")
-        private int two = 0;
+    @Test
+    public void testReflectionHierarchyHashCode() {
+        assertEquals(17 * 37 * 37, HashCodeBuilder.reflectionHashCode(new TestSubObject(0, 0, 0)));
+        assertEquals(17 * 37 * 37 * 37, HashCodeBuilder.reflectionHashCode(new TestSubObject(0, 0, 0), true));
+        assertEquals((17 * 37 + 7890) * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestSubObject(123456, 7890,
+                0)));
+        assertEquals(((17 * 37 + 7890) * 37 + 0) * 37 + 123456, HashCodeBuilder.reflectionHashCode(new TestSubObject(
+                123456, 7890, 0), true));
+    }
 
-        @SuppressWarnings("unused")
-        private int three = 0;
+    @Test
+    public void testReflectionHierarchyHashCodeEx1() {
+        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(0, 0, new TestSubObject(0, 0, 0), true));
+    }
 
-        TestObjectWithMultipleFields(final int one, final int two, final int three) {
-            this.one = one;
-            this.two = two;
-            this.three = three;
-        }
+    @Test
+    public void testReflectionHierarchyHashCodeEx2() {
+        assertThrows(IllegalArgumentException.class, () -> HashCodeBuilder.reflectionHashCode(2, 2, new TestSubObject(0, 0, 0), true));
     }
 
     /**
@@ -550,6 +555,40 @@ public class HashCodeBuilderTest extends AbstractLangTest {
         assertNull(HashCodeBuilder.getRegistry());
     }
 
+    @Test
+    public void testShort() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short) 0).toHashCode());
+        assertEquals(17 * 37 + 12345, new HashCodeBuilder(17, 37).append((short) 12345).toHashCode());
+    }
+
+    @Test
+    public void testShortArray() {
+        assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short[]) null).toHashCode());
+        final short[] obj = new short[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[0] = (short) 5;
+        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+        obj[1] = (short) 6;
+        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append(obj).toHashCode());
+    }
+
+    @Test
+    public void testShortArrayAsObject() {
+        final short[] obj = new short[2];
+        assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[0] = (short) 5;
+        assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+        obj[1] = (short) 6;
+        assertEquals((17 * 37 + 5) * 37 + 6, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
+    }
+
+    @Test
+    public void testSuper() {
+        final Object obj = new Object();
+        assertEquals(17 * 37 + 19 * 41 + obj.hashCode(), new HashCodeBuilder(17, 37).appendSuper(
+                new HashCodeBuilder(19, 41).append(obj).toHashCode()).toHashCode());
+    }
+
     /**
      * Ensures LANG-520 remains true
      */
@@ -560,45 +599,6 @@ public class HashCodeBuilderTest extends AbstractLangTest {
             "hashCode() is no longer returning the same value as toHashCode() - see LANG-520");
     }
 
-    static class TestObjectHashCodeExclude {
-        @HashCodeExclude
-        private final int a;
-        private final int b;
-
-        TestObjectHashCodeExclude(final int a, final int b) {
-            this.a = a;
-            this.b = b;
-        }
-
-        public int getA() {
-            return a;
-        }
-
-        public int getB() {
-            return b;
-        }
-    }
-
-    static class TestObjectHashCodeExclude2 {
-        @HashCodeExclude
-        private final int a;
-        @HashCodeExclude
-        private final int b;
-
-        TestObjectHashCodeExclude2(final int a, final int b) {
-            this.a = a;
-            this.b = b;
-        }
-
-        public int getA() {
-            return a;
-        }
-
-        public int getB() {
-            return b;
-        }
-    }
-
     @Test
     public void testToHashCodeExclude() {
         final TestObjectHashCodeExclude one = new TestObjectHashCodeExclude(1, 2);


[commons-lang] 04/10: Remove obsolete 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 ad849fa8a37ce23290e32b77244098df954c7b63
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 14:37:51 2022 -0400

    Remove obsolete comment
---
 .../lang3/builder/StandardToStringStyle.java       | 80 +++++++++++-----------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/builder/StandardToStringStyle.java b/src/main/java/org/apache/commons/lang3/builder/StandardToStringStyle.java
index 085e61943..ba49f0b47 100644
--- a/src/main/java/org/apache/commons/lang3/builder/StandardToStringStyle.java
+++ b/src/main/java/org/apache/commons/lang3/builder/StandardToStringStyle.java
@@ -52,7 +52,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current useClassName flag
      */
     @Override
-    public boolean isUseClassName() { // NOPMD as this is implementing the abstract class
+    public boolean isUseClassName() {
         return super.isUseClassName();
     }
 
@@ -62,7 +62,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param useClassName  the new useClassName flag
      */
     @Override
-    public void setUseClassName(final boolean useClassName) { // NOPMD as this is implementing the abstract class
+    public void setUseClassName(final boolean useClassName) {
         super.setUseClassName(useClassName);
     }
 
@@ -73,7 +73,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public boolean isUseShortClassName() { // NOPMD as this is implementing the abstract class
+    public boolean isUseShortClassName() {
         return super.isUseShortClassName();
     }
 
@@ -84,7 +84,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public void setUseShortClassName(final boolean useShortClassName) { // NOPMD as this is implementing the abstract class
+    public void setUseShortClassName(final boolean useShortClassName) {
         super.setUseShortClassName(useShortClassName);
     }
 
@@ -93,7 +93,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current useIdentityHashCode flag
      */
     @Override
-    public boolean isUseIdentityHashCode() { // NOPMD as this is implementing the abstract class
+    public boolean isUseIdentityHashCode() {
         return super.isUseIdentityHashCode();
     }
 
@@ -103,7 +103,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param useIdentityHashCode  the new useIdentityHashCode flag
      */
     @Override
-    public void setUseIdentityHashCode(final boolean useIdentityHashCode) { // NOPMD as this is implementing the abstract class
+    public void setUseIdentityHashCode(final boolean useIdentityHashCode) {
         super.setUseIdentityHashCode(useIdentityHashCode);
     }
 
@@ -113,7 +113,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current useFieldNames flag
      */
     @Override
-    public boolean isUseFieldNames() { // NOPMD as this is implementing the abstract class
+    public boolean isUseFieldNames() {
         return super.isUseFieldNames();
     }
 
@@ -123,7 +123,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param useFieldNames  the new useFieldNames flag
      */
     @Override
-    public void setUseFieldNames(final boolean useFieldNames) { // NOPMD as this is implementing the abstract class
+    public void setUseFieldNames(final boolean useFieldNames) {
         super.setUseFieldNames(useFieldNames);
     }
 
@@ -134,7 +134,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current defaultFullDetail flag
      */
     @Override
-    public boolean isDefaultFullDetail() { // NOPMD as this is implementing the abstract class
+    public boolean isDefaultFullDetail() {
         return super.isDefaultFullDetail();
     }
 
@@ -145,7 +145,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param defaultFullDetail  the new defaultFullDetail flag
      */
     @Override
-    public void setDefaultFullDetail(final boolean defaultFullDetail) { // NOPMD as this is implementing the abstract class
+    public void setDefaultFullDetail(final boolean defaultFullDetail) {
         super.setDefaultFullDetail(defaultFullDetail);
     }
 
@@ -155,7 +155,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current array content detail setting
      */
     @Override
-    public boolean isArrayContentDetail() { // NOPMD as this is implementing the abstract class
+    public boolean isArrayContentDetail() {
         return super.isArrayContentDetail();
     }
 
@@ -165,7 +165,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param arrayContentDetail  the new arrayContentDetail flag
      */
     @Override
-    public void setArrayContentDetail(final boolean arrayContentDetail) { // NOPMD as this is implementing the abstract class
+    public void setArrayContentDetail(final boolean arrayContentDetail) {
         super.setArrayContentDetail(arrayContentDetail);
     }
 
@@ -175,7 +175,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current array start text
      */
     @Override
-    public String getArrayStart() { // NOPMD as this is implementing the abstract class
+    public String getArrayStart() {
         return super.getArrayStart();
     }
 
@@ -188,7 +188,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param arrayStart  the new array start text
      */
     @Override
-    public void setArrayStart(final String arrayStart) { // NOPMD as this is implementing the abstract class
+    public void setArrayStart(final String arrayStart) {
         super.setArrayStart(arrayStart);
     }
 
@@ -198,7 +198,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current array end text
      */
     @Override
-    public String getArrayEnd() { // NOPMD as this is implementing the abstract class
+    public String getArrayEnd() {
         return super.getArrayEnd();
     }
 
@@ -211,7 +211,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param arrayEnd  the new array end text
      */
     @Override
-    public void setArrayEnd(final String arrayEnd) { // NOPMD as this is implementing the abstract class
+    public void setArrayEnd(final String arrayEnd) {
         super.setArrayEnd(arrayEnd);
     }
 
@@ -221,7 +221,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current array separator text
      */
     @Override
-    public String getArraySeparator() { // NOPMD as this is implementing the abstract class
+    public String getArraySeparator() {
         return super.getArraySeparator();
     }
 
@@ -234,7 +234,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param arraySeparator  the new array separator text
      */
     @Override
-    public void setArraySeparator(final String arraySeparator) { // NOPMD as this is implementing the abstract class
+    public void setArraySeparator(final String arraySeparator) {
         super.setArraySeparator(arraySeparator);
     }
 
@@ -244,7 +244,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current content start text
      */
     @Override
-    public String getContentStart() { // NOPMD as this is implementing the abstract class
+    public String getContentStart() {
         return super.getContentStart();
     }
 
@@ -257,7 +257,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param contentStart  the new content start text
      */
     @Override
-    public void setContentStart(final String contentStart) { // NOPMD as this is implementing the abstract class
+    public void setContentStart(final String contentStart) {
         super.setContentStart(contentStart);
     }
 
@@ -267,7 +267,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current content end text
      */
     @Override
-    public String getContentEnd() { // NOPMD as this is implementing the abstract class
+    public String getContentEnd() {
         return super.getContentEnd();
     }
 
@@ -280,7 +280,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param contentEnd  the new content end text
      */
     @Override
-    public void setContentEnd(final String contentEnd) { // NOPMD as this is implementing the abstract class
+    public void setContentEnd(final String contentEnd) {
         super.setContentEnd(contentEnd);
     }
 
@@ -290,7 +290,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current field name value separator text
      */
     @Override
-    public String getFieldNameValueSeparator() { // NOPMD as this is implementing the abstract class
+    public String getFieldNameValueSeparator() {
         return super.getFieldNameValueSeparator();
     }
 
@@ -303,7 +303,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param fieldNameValueSeparator  the new field name value separator text
      */
     @Override
-    public void setFieldNameValueSeparator(final String fieldNameValueSeparator) { // NOPMD as this is implementing the abstract class
+    public void setFieldNameValueSeparator(final String fieldNameValueSeparator) {
         super.setFieldNameValueSeparator(fieldNameValueSeparator);
     }
 
@@ -313,7 +313,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current field separator text
      */
     @Override
-    public String getFieldSeparator() { // NOPMD as this is implementing the abstract class
+    public String getFieldSeparator() {
         return super.getFieldSeparator();
     }
 
@@ -326,7 +326,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param fieldSeparator  the new field separator text
      */
     @Override
-    public void setFieldSeparator(final String fieldSeparator) { // NOPMD as this is implementing the abstract class
+    public void setFieldSeparator(final String fieldSeparator) {
         super.setFieldSeparator(fieldSeparator);
     }
 
@@ -338,7 +338,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public boolean isFieldSeparatorAtStart() { // NOPMD as this is implementing the abstract class
+    public boolean isFieldSeparatorAtStart() {
         return super.isFieldSeparatorAtStart();
     }
 
@@ -350,7 +350,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public void setFieldSeparatorAtStart(final boolean fieldSeparatorAtStart) { // NOPMD as this is implementing the abstract class
+    public void setFieldSeparatorAtStart(final boolean fieldSeparatorAtStart) {
         super.setFieldSeparatorAtStart(fieldSeparatorAtStart);
     }
 
@@ -362,7 +362,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public boolean isFieldSeparatorAtEnd() { // NOPMD as this is implementing the abstract class
+    public boolean isFieldSeparatorAtEnd() {
         return super.isFieldSeparatorAtEnd();
     }
 
@@ -374,7 +374,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @since 2.0
      */
     @Override
-    public void setFieldSeparatorAtEnd(final boolean fieldSeparatorAtEnd) { // NOPMD as this is implementing the abstract class
+    public void setFieldSeparatorAtEnd(final boolean fieldSeparatorAtEnd) {
         super.setFieldSeparatorAtEnd(fieldSeparatorAtEnd);
     }
 
@@ -384,7 +384,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current text to output when {@code null} found
      */
     @Override
-    public String getNullText() { // NOPMD as this is implementing the abstract class
+    public String getNullText() {
         return super.getNullText();
     }
 
@@ -397,7 +397,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param nullText  the new text to output when {@code null} found
      */
     @Override
-    public void setNullText(final String nullText) { // NOPMD as this is implementing the abstract class
+    public void setNullText(final String nullText) {
         super.setNullText(nullText);
     }
 
@@ -410,7 +410,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current start of size text
      */
     @Override
-    public String getSizeStartText() { // NOPMD as this is implementing the abstract class
+    public String getSizeStartText() {
         return super.getSizeStartText();
     }
 
@@ -426,7 +426,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param sizeStartText  the new start of size text
      */
     @Override
-    public void setSizeStartText(final String sizeStartText) { // NOPMD as this is implementing the abstract class
+    public void setSizeStartText(final String sizeStartText) {
         super.setSizeStartText(sizeStartText);
     }
 
@@ -439,7 +439,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current end of size text
      */
     @Override
-    public String getSizeEndText() { // NOPMD as this is implementing the abstract class
+    public String getSizeEndText() {
         return super.getSizeEndText();
     }
 
@@ -455,7 +455,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param sizeEndText  the new end of size text
      */
     @Override
-    public void setSizeEndText(final String sizeEndText) { // NOPMD as this is implementing the abstract class
+    public void setSizeEndText(final String sizeEndText) {
         super.setSizeEndText(sizeEndText);
     }
 
@@ -468,7 +468,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current start of summary text
      */
     @Override
-    public String getSummaryObjectStartText() { // NOPMD as this is implementing the abstract class
+    public String getSummaryObjectStartText() {
         return super.getSummaryObjectStartText();
     }
 
@@ -484,7 +484,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param summaryObjectStartText  the new start of summary text
      */
     @Override
-    public void setSummaryObjectStartText(final String summaryObjectStartText) { // NOPMD as this is implementing the abstract class
+    public void setSummaryObjectStartText(final String summaryObjectStartText) {
         super.setSummaryObjectStartText(summaryObjectStartText);
     }
 
@@ -497,7 +497,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @return the current end of summary text
      */
     @Override
-    public String getSummaryObjectEndText() { // NOPMD as this is implementing the abstract class
+    public String getSummaryObjectEndText() {
         return super.getSummaryObjectEndText();
     }
 
@@ -513,7 +513,7 @@ public class StandardToStringStyle extends ToStringStyle {
      * @param summaryObjectEndText  the new end of summary text
      */
     @Override
-    public void setSummaryObjectEndText(final String summaryObjectEndText) { // NOPMD as this is implementing the abstract class
+    public void setSummaryObjectEndText(final String summaryObjectEndText) {
         super.setSummaryObjectEndText(summaryObjectEndText);
     }
 


[commons-lang] 09/10: PMD: Avoid using a branching statement as the last in a loop.

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 b6739ab929018ab574946eb9f6f75db6ad30a3c2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Aug 26 15:05:43 2022 -0400

    PMD: Avoid using a branching statement as the last in a loop.
    
    Make deprecated code reuse main code
---
 .../org/apache/commons/lang3/text/StrBuilder.java  | 52 +---------------------
 1 file changed, 2 insertions(+), 50 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
index e58c9e6f9..0396d427d 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
@@ -2457,32 +2457,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the first index of the string, or -1 if not found
      */
     public int indexOf(final String str, int startIndex) {
-        startIndex = Math.max(startIndex, 0);
-        if (str == null || startIndex >= size) {
-            return -1;
-        }
-        final int strLen = str.length();
-        if (strLen == 1) {
-            return indexOf(str.charAt(0), startIndex);
-        }
-        if (strLen == 0) {
-            return startIndex;
-        }
-        if (strLen > size) {
-            return -1;
-        }
-        final char[] thisBuf = buffer;
-        final int len = size - strLen + 1;
-        outer:
-        for (int i = startIndex; i < len; i++) {
-            for (int j = 0; j < strLen; j++) {
-                if (str.charAt(j) != thisBuf[i + j]) {
-                    continue outer;
-                }
-            }
-            return i;
-        }
-        return -1;
+        return StringUtils.indexOf(this, str, startIndex);
     }
 
     /**
@@ -2583,30 +2558,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
      * @return the last index of the string, or -1 if not found
      */
     public int lastIndexOf(final String str, int startIndex) {
-        startIndex = startIndex >= size ? size - 1 : startIndex;
-        if (str == null || startIndex < 0) {
-            return -1;
-        }
-        final int strLen = str.length();
-        if (strLen > 0 && strLen <= size) {
-            if (strLen == 1) {
-                return lastIndexOf(str.charAt(0), startIndex);
-            }
-
-            outer:
-            for (int i = startIndex - strLen + 1; i >= 0; i--) {
-                for (int j = 0; j < strLen; j++) {
-                    if (str.charAt(j) != buffer[i + j]) {
-                        continue outer;
-                    }
-                }
-                return i;
-            }
-
-        } else if (strLen == 0) {
-            return startIndex;
-        }
-        return -1;
+        return StringUtils.lastIndexOf(this, str, startIndex);
     }
 
     /**