[LANG-1565] change removeLastFieldSeparator to use endsWith (#550)

* change_removeLastFieldSeparator_to_use_endsWith

* stylecheck

* revert mis-changes about orders of imports.
This commit is contained in:
XenoAmess 2020-06-14 21:43:59 +08:00 committed by GitHub
parent 9fcd9c86ed
commit 1406f67252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 13 deletions

View File

@ -437,19 +437,8 @@ public abstract class ToStringStyle implements Serializable {
* @since 2.0 * @since 2.0
*/ */
protected void removeLastFieldSeparator(final StringBuffer buffer) { protected void removeLastFieldSeparator(final StringBuffer buffer) {
final int len = buffer.length(); if (StringUtils.endsWith(buffer, fieldSeparator)) {
final int sepLen = fieldSeparator.length(); buffer.setLength(buffer.length() - 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);
}
} }
} }