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 2020/06/14 13:44:12 UTC

[commons-lang] branch master updated: [LANG-1565] change removeLastFieldSeparator to use endsWith (#550)

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


The following commit(s) were added to refs/heads/master by this push:
     new 1406f67  [LANG-1565] change removeLastFieldSeparator to use endsWith (#550)
1406f67 is described below

commit 1406f67252c3ef919c1045ab2183fb03d2bd5464
Author: XenoAmess <xe...@gmail.com>
AuthorDate: Sun Jun 14 21:43:59 2020 +0800

    [LANG-1565] change removeLastFieldSeparator to use endsWith (#550)
    
    * change_removeLastFieldSeparator_to_use_endsWith
    
    * stylecheck
    
    * revert mis-changes about orders of imports.
---
 .../org/apache/commons/lang3/builder/ToStringStyle.java   | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
index aa83496..9b11573 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java
@@ -437,19 +437,8 @@ public abstract class ToStringStyle implements Serializable {
      * @since 2.0
      */
     protected void removeLastFieldSeparator(final StringBuffer buffer) {
-        final int len = buffer.length();
-        final int sepLen = fieldSeparator.length();
-        if (sepLen > 0 && len >= sepLen) {
-            boolean match = true;
-            for (int i = 0; i < sepLen; i++) {
-                if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) {
-                    match = false;
-                    break;
-                }
-            }
-            if (match) {
-                buffer.setLength(len - sepLen);
-            }
+        if (StringUtils.endsWith(buffer, fieldSeparator)) {
+            buffer.setLength(buffer.length() - fieldSeparator.length());
         }
     }