PMD: Remove useless parentheses

This commit is contained in:
Benedikt Ritter 2016-09-19 13:56:11 +02:00
parent 3421e6adb4
commit 9c5b6cdc71
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
7 changed files with 33 additions and 36 deletions

View File

@ -76,10 +76,10 @@ public static String squeeze(final String str, final String... set) {
for (int i = 1; i < sz; i++) { for (int i = 1; i < sz; i++) {
ch = chrs[i]; ch = chrs[i];
if (ch == lastChar) { if (ch == lastChar) {
if ((inChars != null) && (ch == inChars)) { if (inChars != null && ch == inChars) {
continue; continue;
} else { } else {
if ((notInChars == null) || (ch != notInChars)) { if (notInChars == null || ch != notInChars) {
if (chars.contains(ch)) { if (chars.contains(ch)) {
inChars = ch; inChars = ch;
continue; continue;

View File

@ -142,7 +142,7 @@ public static Locale toLocale(final String str) {
case 2: case 2:
if (StringUtils.isAllLowerCase(split[0]) && if (StringUtils.isAllLowerCase(split[0]) &&
(split[0].length() == 2 || split[0].length() == 3) && (split[0].length() == 2 || split[0].length() == 3) &&
(split[1].length() == 0 || (split[1].length() == 2 && StringUtils.isAllUpperCase(split[1]))) && (split[1].length() == 0 || split[1].length() == 2 && StringUtils.isAllUpperCase(split[1])) &&
split[2].length() > 0) { split[2].length() > 0) {
return new Locale(split[0], split[1], split[2]); return new Locale(split[0], split[1], split[2]);
} }

View File

@ -322,9 +322,9 @@ private static void reflectionAppend(
for (int i = 0; i < fields.length && builder.comparison == 0; i++) { for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
final Field f = fields[i]; final Field f = fields[i];
if (!ArrayUtils.contains(excludeFields, f.getName()) if (!ArrayUtils.contains(excludeFields, f.getName())
&& (!f.getName().contains("$")) && !f.getName().contains("$")
&& (useTransients || !Modifier.isTransient(f.getModifiers())) && (useTransients || !Modifier.isTransient(f.getModifiers()))
&& (!Modifier.isStatic(f.getModifiers()))) { && !Modifier.isStatic(f.getModifiers())) {
try { try {
builder.append(f.get(lhs), f.get(rhs)); builder.append(f.get(lhs), f.get(rhs));
} catch (final IllegalAccessException e) { } catch (final IllegalAccessException e) {
@ -475,7 +475,7 @@ public CompareToBuilder append(final long lhs, final long rhs) {
if (comparison != 0) { if (comparison != 0) {
return this; return this;
} }
comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0)); comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
return this; return this;
} }
@ -491,7 +491,7 @@ public CompareToBuilder append(final int lhs, final int rhs) {
if (comparison != 0) { if (comparison != 0) {
return this; return this;
} }
comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0)); comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
return this; return this;
} }
@ -507,7 +507,7 @@ public CompareToBuilder append(final short lhs, final short rhs) {
if (comparison != 0) { if (comparison != 0) {
return this; return this;
} }
comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0)); comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
return this; return this;
} }
@ -523,7 +523,7 @@ public CompareToBuilder append(final char lhs, final char rhs) {
if (comparison != 0) { if (comparison != 0) {
return this; return this;
} }
comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0)); comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
return this; return this;
} }
@ -539,7 +539,7 @@ public CompareToBuilder append(final byte lhs, final byte rhs) {
if (comparison != 0) { if (comparison != 0) {
return this; return this;
} }
comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0)); comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
return this; return this;
} }
@ -672,7 +672,7 @@ public CompareToBuilder append(final Object[] lhs, final Object[] rhs, final Com
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -712,7 +712,7 @@ public CompareToBuilder append(final long[] lhs, final long[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -752,7 +752,7 @@ public CompareToBuilder append(final int[] lhs, final int[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -792,7 +792,7 @@ public CompareToBuilder append(final short[] lhs, final short[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -832,7 +832,7 @@ public CompareToBuilder append(final char[] lhs, final char[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -872,7 +872,7 @@ public CompareToBuilder append(final byte[] lhs, final byte[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -912,7 +912,7 @@ public CompareToBuilder append(final double[] lhs, final double[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -952,7 +952,7 @@ public CompareToBuilder append(final float[] lhs, final float[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {
@ -992,7 +992,7 @@ public CompareToBuilder append(final boolean[] lhs, final boolean[] rhs) {
return this; return this;
} }
if (lhs.length != rhs.length) { if (lhs.length != rhs.length) {
comparison = (lhs.length < rhs.length) ? -1 : +1; comparison = lhs.length < rhs.length ? -1 : +1;
return this; return this;
} }
for (int i = 0; i < lhs.length && comparison == 0; i++) { for (int i = 0; i < lhs.length && comparison == 0; i++) {

View File

@ -415,8 +415,8 @@ private static void reflectionAppend(
if (!ArrayUtils.contains(excludeFields, f.getName()) if (!ArrayUtils.contains(excludeFields, f.getName())
&& !f.getName().contains("$") && !f.getName().contains("$")
&& (useTransients || !Modifier.isTransient(f.getModifiers())) && (useTransients || !Modifier.isTransient(f.getModifiers()))
&& (!Modifier.isStatic(f.getModifiers())) && !Modifier.isStatic(f.getModifiers())
&& (!f.isAnnotationPresent(EqualsExclude.class))) { && !f.isAnnotationPresent(EqualsExclude.class)) {
try { try {
builder.append(f.get(lhs), f.get(rhs)); builder.append(f.get(lhs), f.get(rhs));
} catch (final IllegalAccessException e) { } catch (final IllegalAccessException e) {

View File

@ -194,8 +194,8 @@ private static void reflectionAppend(final Object object, final Class<?> clazz,
if (!ArrayUtils.contains(excludeFields, field.getName()) if (!ArrayUtils.contains(excludeFields, field.getName())
&& !field.getName().contains("$") && !field.getName().contains("$")
&& (useTransients || !Modifier.isTransient(field.getModifiers())) && (useTransients || !Modifier.isTransient(field.getModifiers()))
&& (!Modifier.isStatic(field.getModifiers())) && !Modifier.isStatic(field.getModifiers())
&& (!field.isAnnotationPresent(HashCodeExclude.class))) { && !field.isAnnotationPresent(HashCodeExclude.class)) {
try { try {
final Object fieldValue = field.get(object); final Object fieldValue = field.get(object);
builder.append(fieldValue); builder.append(fieldValue);

View File

@ -475,10 +475,10 @@ public static Number createNumber(final String str) throws NumberFormatException
} }
} }
final int hexDigits = str.length() - pfxLen; final int hexDigits = str.length() - pfxLen;
if (hexDigits > 16 || (hexDigits == 16 && firstSigDigit > '7')) { // too many for Long if (hexDigits > 16 || hexDigits == 16 && firstSigDigit > '7') { // too many for Long
return createBigInteger(str); return createBigInteger(str);
} }
if (hexDigits > 8 || (hexDigits == 8 && firstSigDigit > '7')) { // too many for an int if (hexDigits > 8 || hexDigits == 8 && firstSigDigit > '7') { // too many for an int
return createLong(str); return createLong(str);
} }
return createInteger(str); return createInteger(str);
@ -541,7 +541,7 @@ public static Number createNumber(final String str) throws NumberFormatException
case 'F' : case 'F' :
try { try {
final Float f = NumberUtils.createFloat(str); final Float f = NumberUtils.createFloat(str);
if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) { if (!(f.isInfinite() || f.floatValue() == 0.0F && !allZeros)) {
//If it's too big for a float or the float value = 0 and the string //If it's too big for a float or the float value = 0 and the string
//has non-zeros in it, then float does not have the precision we want //has non-zeros in it, then float does not have the precision we want
return f; return f;
@ -555,7 +555,7 @@ public static Number createNumber(final String str) throws NumberFormatException
case 'D' : case 'D' :
try { try {
final Double d = NumberUtils.createDouble(str); final Double d = NumberUtils.createDouble(str);
if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) { if (!(d.isInfinite() || d.floatValue() == 0.0D && !allZeros)) {
return d; return d;
} }
} catch (final NumberFormatException nfe) { // NOPMD } catch (final NumberFormatException nfe) { // NOPMD
@ -640,7 +640,7 @@ private static String getMantissa(final String str) {
*/ */
private static String getMantissa(final String str, final int stopPos) { private static String getMantissa(final String str, final int stopPos) {
final char firstChar = str.charAt(0); final char firstChar = str.charAt(0);
final boolean hasSign = (firstChar == '-' || firstChar == '+'); final boolean hasSign = firstChar == '-' || firstChar == '+';
return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos); return hasSign ? str.substring(1, stopPos) : str.substring(0, stopPos);
} }
@ -1409,13 +1409,10 @@ public static boolean isCreatable(final String str) {
boolean allowSigns = false; boolean allowSigns = false;
boolean foundDigit = false; boolean foundDigit = false;
// deal with any possible sign up front // deal with any possible sign up front
final int start = (chars[0] == '-' || chars[0] == '+') ? 1 : 0; final int start = chars[0] == '-' || chars[0] == '+' ? 1 : 0;
final boolean hasLeadingPlusSign = (start == 1 && chars[0] == '+'); final boolean hasLeadingPlusSign = start == 1 && chars[0] == '+';
if (sz > start + 1 && chars[start] == '0') { // leading 0 if (sz > start + 1 && chars[start] == '0') { // leading 0
if ( if (chars[start + 1] == 'x' || chars[start + 1] == 'X') { // leading 0x/0X
(chars[start + 1] == 'x') ||
(chars[start + 1] == 'X')
) { // leading 0x/0X
int i = start + 2; int i = start + 2;
if (i == sz) { if (i == sz) {
return false; // str == "0x" return false; // str == "0x"
@ -1445,7 +1442,7 @@ public static boolean isCreatable(final String str) {
int i = start; int i = start;
// loop to the next to last char or to the last char if we need another digit to // loop to the next to last char or to the last char if we need another digit to
// make a valid number (e.g. chars[0..5] = "1234E") // make a valid number (e.g. chars[0..5] = "1234E")
while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) { while (i < sz || i < sz + 1 && allowSigns && !foundDigit) {
if (chars[i] >= '0' && chars[i] <= '9') { if (chars[i] >= '0' && chars[i] <= '9') {
foundDigit = true; foundDigit = true;
allowSigns = false; allowSigns = false;

View File

@ -163,7 +163,7 @@ private static float getTotalTransformationCost(final Class<?>[] srcArgs, final
// When isVarArgs is true, srcArgs and dstArgs may differ in length. // When isVarArgs is true, srcArgs and dstArgs may differ in length.
// There are two special cases to consider: // There are two special cases to consider:
final boolean noVarArgsPassed = srcArgs.length < destArgs.length; final boolean noVarArgsPassed = srcArgs.length < destArgs.length;
final boolean explicitArrayForVarags = (srcArgs.length == destArgs.length) && srcArgs[srcArgs.length-1].isArray(); final boolean explicitArrayForVarags = srcArgs.length == destArgs.length && srcArgs[srcArgs.length-1].isArray();
final float varArgsCost = 0.001f; final float varArgsCost = 0.001f;
Class<?> destClass = destArgs[destArgs.length-1].getComponentType(); Class<?> destClass = destArgs[destArgs.length-1].getComponentType();