You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2016/09/19 11:56:21 UTC

[2/2] [lang] PMD: Remove useless parentheses

PMD: Remove useless parentheses


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/9c5b6cdc
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/9c5b6cdc
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/9c5b6cdc

Branch: refs/heads/master
Commit: 9c5b6cdc7108eb071785b0c4edd205650cdf1ca4
Parents: 3421e6a
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Sep 19 13:56:11 2016 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Sep 19 13:56:11 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/CharSetUtils.java  |  4 +--
 .../org/apache/commons/lang3/LocaleUtils.java   |  2 +-
 .../commons/lang3/builder/CompareToBuilder.java | 32 ++++++++++----------
 .../commons/lang3/builder/EqualsBuilder.java    |  4 +--
 .../commons/lang3/builder/HashCodeBuilder.java  |  4 +--
 .../apache/commons/lang3/math/NumberUtils.java  | 21 ++++++-------
 .../commons/lang3/reflect/MemberUtils.java      |  2 +-
 7 files changed, 33 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/CharSetUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharSetUtils.java b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
index 67d6fea..6284e38 100644
--- a/src/main/java/org/apache/commons/lang3/CharSetUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
@@ -76,10 +76,10 @@ public class CharSetUtils {
         for (int i = 1; i < sz; i++) {
             ch = chrs[i];
             if (ch == lastChar) {
-                if ((inChars != null) && (ch == inChars)) {
+                if (inChars != null && ch == inChars) {
                     continue;
                 } else {
-                    if ((notInChars == null) || (ch != notInChars)) {
+                    if (notInChars == null || ch != notInChars) {
                         if (chars.contains(ch)) {
                             inChars = ch;
                             continue;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/LocaleUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
index 18e98bb..4185373 100644
--- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java
+++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java
@@ -142,7 +142,7 @@ public class LocaleUtils {
             case 2:
                 if (StringUtils.isAllLowerCase(split[0]) && 
                     (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) {
                     return new Locale(split[0], split[1], split[2]);
                 }

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
index e79a1c9..875b088 100644
--- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
@@ -322,9 +322,9 @@ public class CompareToBuilder implements Builder<Integer> {
         for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
             final Field f = fields[i];
             if (!ArrayUtils.contains(excludeFields, f.getName())
-                && (!f.getName().contains("$"))
+                && !f.getName().contains("$")
                 && (useTransients || !Modifier.isTransient(f.getModifiers()))
-                && (!Modifier.isStatic(f.getModifiers()))) {
+                && !Modifier.isStatic(f.getModifiers())) {
                 try {
                     builder.append(f.get(lhs), f.get(rhs));
                 } catch (final IllegalAccessException e) {
@@ -475,7 +475,7 @@ public class CompareToBuilder implements Builder<Integer> {
         if (comparison != 0) {
             return this;
         }
-        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
         return this;
     }
 
@@ -491,7 +491,7 @@ public class CompareToBuilder implements Builder<Integer> {
         if (comparison != 0) {
             return this;
         }
-        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
         return this;
     }
 
@@ -507,7 +507,7 @@ public class CompareToBuilder implements Builder<Integer> {
         if (comparison != 0) {
             return this;
         }
-        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
         return this;
     }
 
@@ -523,7 +523,7 @@ public class CompareToBuilder implements Builder<Integer> {
         if (comparison != 0) {
             return this;
         }
-        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
         return this;
     }
 
@@ -539,7 +539,7 @@ public class CompareToBuilder implements Builder<Integer> {
         if (comparison != 0) {
             return this;
         }
-        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        comparison = lhs < rhs ? -1 : lhs > rhs ? 1 : 0;
         return this;
     }
 
@@ -672,7 +672,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -712,7 +712,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -752,7 +752,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -792,7 +792,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -832,7 +832,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -872,7 +872,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -912,7 +912,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -952,7 +952,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {
@@ -992,7 +992,7 @@ public class CompareToBuilder implements Builder<Integer> {
             return this;
         }
         if (lhs.length != rhs.length) {
-            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            comparison = lhs.length < rhs.length ? -1 : +1;
             return this;
         }
         for (int i = 0; i < lhs.length && comparison == 0; i++) {

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
index 6a1b5df..502f055 100644
--- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
@@ -415,8 +415,8 @@ public class EqualsBuilder implements Builder<Boolean> {
                 if (!ArrayUtils.contains(excludeFields, f.getName())
                     && !f.getName().contains("$")
                     && (useTransients || !Modifier.isTransient(f.getModifiers()))
-                    && (!Modifier.isStatic(f.getModifiers()))
-                    && (!f.isAnnotationPresent(EqualsExclude.class))) {
+                    && !Modifier.isStatic(f.getModifiers())
+                    && !f.isAnnotationPresent(EqualsExclude.class)) {
                     try {
                         builder.append(f.get(lhs), f.get(rhs));
                     } catch (final IllegalAccessException e) {

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
----------------------------------------------------------------------
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 beab5fc..6dbc8e6 100644
--- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
@@ -194,8 +194,8 @@ public class HashCodeBuilder implements Builder<Integer> {
                 if (!ArrayUtils.contains(excludeFields, field.getName())
                     && !field.getName().contains("$")
                     && (useTransients || !Modifier.isTransient(field.getModifiers()))
-                    && (!Modifier.isStatic(field.getModifiers()))
-                    && (!field.isAnnotationPresent(HashCodeExclude.class))) {
+                    && !Modifier.isStatic(field.getModifiers())
+                    && !field.isAnnotationPresent(HashCodeExclude.class)) {
                     try {
                         final Object fieldValue = field.get(object);
                         builder.append(fieldValue);

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index 7d582de..749c4a0 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -475,10 +475,10 @@ public class NumberUtils {
                 }
             }
             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);
             }
-            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 createInteger(str);
@@ -541,7 +541,7 @@ public class NumberUtils {
                 case 'F' :
                     try {
                         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
                             //has non-zeros in it, then float does not have the precision we want
                             return f;
@@ -555,7 +555,7 @@ public class NumberUtils {
                 case 'D' :
                     try {
                         final Double d = NumberUtils.createDouble(str);
-                        if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) {
+                        if (!(d.isInfinite() || d.floatValue() == 0.0D && !allZeros)) {
                             return d;
                         }
                     } catch (final NumberFormatException nfe) { // NOPMD
@@ -640,7 +640,7 @@ public class NumberUtils {
      */
     private static String getMantissa(final String str, final int stopPos) {
         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);
     }
@@ -1409,13 +1409,10 @@ public class NumberUtils {
         boolean allowSigns = false;
         boolean foundDigit = false;
         // deal with any possible sign up front
-        final int start = (chars[0] == '-' || chars[0] == '+') ? 1 : 0;
-        final boolean hasLeadingPlusSign = (start == 1 && chars[0] == '+');
+        final int start = chars[0] == '-' || chars[0] == '+' ? 1 : 0;
+        final boolean hasLeadingPlusSign = start == 1 && chars[0] == '+';
         if (sz > start + 1 && chars[start] == '0') { // leading 0
-            if (
-                 (chars[start + 1] == 'x') || 
-                 (chars[start + 1] == 'X') 
-            ) { // leading 0x/0X
+            if (chars[start + 1] == 'x' || chars[start + 1] == 'X') { // leading 0x/0X
                 int i = start + 2;
                 if (i == sz) {
                     return false; // str == "0x"
@@ -1445,7 +1442,7 @@ public class NumberUtils {
         int i = start;
         // 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")
-        while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) {
+        while (i < sz || i < sz + 1 && allowSigns && !foundDigit) {
             if (chars[i] >= '0' && chars[i] <= '9') {
                 foundDigit = true;
                 allowSigns = false;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/9c5b6cdc/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
index 41605cf..0131e03 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
@@ -163,7 +163,7 @@ abstract class MemberUtils {
             // When isVarArgs is true, srcArgs and dstArgs may differ in length.
             // There are two special cases to consider:
             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;
             Class<?> destClass = destArgs[destArgs.length-1].getComponentType();