PMD: Remove useless parens

This commit is contained in:
Gary Gregory 2022-08-26 14:19:40 -04:00
parent e505c08668
commit dafea75722
1 changed files with 23 additions and 23 deletions

View File

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