From 371e866442f46131cc38a9a5018e1703f52f9b60 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Wed, 9 Nov 2011 17:53:59 +0000 Subject: [PATCH] Remove superfluous parens like: return (foo + 1); int len = (foo + 1); if ((foo + 1 > 2)) ((String) foo) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1199894 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/lang3/BooleanUtils.java | 8 +- .../commons/lang3/CharSequenceUtils.java | 2 +- .../org/apache/commons/lang3/CharSet.java | 2 +- .../org/apache/commons/lang3/ClassUtils.java | 2 +- .../org/apache/commons/lang3/EnumUtils.java | 4 +- .../org/apache/commons/lang3/ObjectUtils.java | 8 +- .../commons/lang3/RandomStringUtils.java | 8 +- .../java/org/apache/commons/lang3/Range.java | 2 +- .../org/apache/commons/lang3/StringUtils.java | 54 ++++++------- .../lang3/concurrent/ConcurrentUtils.java | 4 +- .../lang3/concurrent/ConstantInitializer.java | 2 +- .../lang3/concurrent/TimedSemaphore.java | 2 +- .../lang3/exception/ExceptionUtils.java | 4 +- .../apache/commons/lang3/math/Fraction.java | 26 +++---- .../commons/lang3/mutable/MutableDouble.java | 6 +- .../commons/lang3/mutable/MutableFloat.java | 4 +- .../commons/lang3/text/StrSubstitutor.java | 6 +- .../commons/lang3/text/StrTokenizer.java | 6 +- .../apache/commons/lang3/text/WordUtils.java | 6 +- .../translate/NumericEntityUnescaper.java | 12 +-- .../text/translate/UnicodeUnescaper.java | 8 +- .../apache/commons/lang3/time/StopWatch.java | 2 +- .../commons/lang3/ArrayUtilsAddTest.java | 42 +++++----- .../apache/commons/lang3/BitFieldTest.java | 2 +- .../commons/lang3/CharUtilsPerfRun.java | 2 +- .../commons/lang3/RandomStringUtilsTest.java | 6 +- .../lang3/builder/CompareToBuilderTest.java | 26 +++---- .../lang3/builder/EqualsBuilderTest.java | 8 +- .../lang3/builder/HashCodeBuilderTest.java | 76 +++++++++---------- .../lang3/concurrent/TimedSemaphoreTest.java | 2 +- .../commons/lang3/text/StrTokenizerTest.java | 4 +- 31 files changed, 173 insertions(+), 173 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/BooleanUtils.java b/src/main/java/org/apache/commons/lang3/BooleanUtils.java index a5220419c..67e09c652 100644 --- a/src/main/java/org/apache/commons/lang3/BooleanUtils.java +++ b/src/main/java/org/apache/commons/lang3/BooleanUtils.java @@ -551,12 +551,12 @@ public class BooleanUtils { switch (str.length()) { case 1: { char ch0 = str.charAt(0); - if ((ch0 == 'y' || ch0 == 'Y') || - (ch0 == 't' || ch0 == 'T')) { + if (ch0 == 'y' || ch0 == 'Y' || + ch0 == 't' || ch0 == 'T') { return Boolean.TRUE; } - if ((ch0 == 'n' || ch0 == 'N') || - (ch0 == 'f' || ch0 == 'F')) { + if (ch0 == 'n' || ch0 == 'N' || + ch0 == 'f' || ch0 == 'F') { return Boolean.FALSE; } break; diff --git a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java index 22a7b62c1..c0c957017 100644 --- a/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java @@ -187,7 +187,7 @@ public class CharSequenceUtils { static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, CharSequence substring, int start, int length) { if (cs instanceof String && substring instanceof String) { - return ((String) cs).regionMatches(ignoreCase, thisStart, ((String) substring), start, length); + return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); } else { // TODO: Implement rather than convert to String return cs.toString().regionMatches(ignoreCase, thisStart, substring.toString(), start, length); diff --git a/src/main/java/org/apache/commons/lang3/CharSet.java b/src/main/java/org/apache/commons/lang3/CharSet.java index 3ace75338..9a1b3685f 100644 --- a/src/main/java/org/apache/commons/lang3/CharSet.java +++ b/src/main/java/org/apache/commons/lang3/CharSet.java @@ -178,7 +178,7 @@ public class CharSet implements Serializable { int len = str.length(); int pos = 0; while (pos < len) { - int remainder = (len - pos); + int remainder = len - pos; if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') { // negated range set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3))); diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 78dde9aaa..1659eab6d 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -622,7 +622,7 @@ public class ClassUtils { } // have to check for null, as isAssignableFrom doesn't if (cls == null) { - return !(toClass.isPrimitive()); + return !toClass.isPrimitive(); } //autoboxing: if (autoboxing) { diff --git a/src/main/java/org/apache/commons/lang3/EnumUtils.java b/src/main/java/org/apache/commons/lang3/EnumUtils.java index ca7953fb0..55a867ec7 100644 --- a/src/main/java/org/apache/commons/lang3/EnumUtils.java +++ b/src/main/java/org/apache/commons/lang3/EnumUtils.java @@ -136,7 +136,7 @@ public class EnumUtils { Validate.notNull(values); long total = 0; for (E constant : values) { - total |= (1 << constant.ordinal()); + total |= 1 << constant.ordinal(); } return total; } @@ -179,7 +179,7 @@ public class EnumUtils { final E[] constants = checkBitVectorable(enumClass).getEnumConstants(); final EnumSet results = EnumSet.noneOf(enumClass); for (E constant : constants) { - if ((value & (1 << constant.ordinal())) != 0) { + if ((value & 1 << constant.ordinal()) != 0) { results.add(constant); } } diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index 7a9065c98..c8b32854e 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -152,7 +152,7 @@ public class ObjectUtils { if (object1 == object2) { return true; } - if ((object1 == null) || (object2 == null)) { + if (object1 == null || object2 == null) { return false; } return object1.equals(object2); @@ -196,7 +196,7 @@ public class ObjectUtils { */ public static int hashCode(Object obj) { // hashCode(Object) retained for performance, as hash code is often critical - return (obj == null) ? 0 : obj.hashCode(); + return obj == null ? 0 : obj.hashCode(); } /** @@ -409,9 +409,9 @@ public class ObjectUtils { if (c1 == c2) { return 0; } else if (c1 == null) { - return (nullGreater ? 1 : -1); + return nullGreater ? 1 : -1; } else if (c2 == null) { - return (nullGreater ? -1 : 1); + return nullGreater ? -1 : 1; } return c1.compareTo(c2); } diff --git a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java index 979e3292b..bded1540f 100644 --- a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java +++ b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java @@ -227,7 +227,7 @@ public class RandomStringUtils { } else if (count < 0) { throw new IllegalArgumentException("Requested random string length " + count + " is less than 0."); } - if ((start == 0) && (end == 0)) { + if (start == 0 && end == 0) { end = 'z' + 1; start = ' '; if (!letters && !numbers) { @@ -246,9 +246,9 @@ public class RandomStringUtils { } else { ch = chars[random.nextInt(gap) + start]; } - if ((letters && Character.isLetter(ch)) - || (numbers && Character.isDigit(ch)) - || (!letters && !numbers)) { + if (letters && Character.isLetter(ch) + || numbers && Character.isDigit(ch) + || !letters && !numbers) { if(ch >= 56320 && ch <= 57343) { if(count == 0) { count++; diff --git a/src/main/java/org/apache/commons/lang3/Range.java b/src/main/java/org/apache/commons/lang3/Range.java index ae1570551..471024ebe 100644 --- a/src/main/java/org/apache/commons/lang3/Range.java +++ b/src/main/java/org/apache/commons/lang3/Range.java @@ -219,7 +219,7 @@ public final class Range implements Serializable { if (element == null) { return false; } - return (comparator.compare(element, minimum) > -1) && (comparator.compare(element, maximum) < 1); + return comparator.compare(element, minimum) > -1 && comparator.compare(element, maximum) < 1; } /** diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 0d5959452..3d81b0272 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -225,7 +225,7 @@ public class StringUtils { return true; } for (int i = 0; i < strLen; i++) { - if ((Character.isWhitespace(cs.charAt(i)) == false)) { + if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } @@ -484,13 +484,13 @@ public class StringUtils { } int start = 0; if (stripChars == null) { - while ((start != strLen) && Character.isWhitespace(str.charAt(start))) { + while (start != strLen && Character.isWhitespace(str.charAt(start))) { start++; } } else if (stripChars.length() == 0) { return str; } else { - while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND)) { + while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) { start++; } } @@ -529,13 +529,13 @@ public class StringUtils { } if (stripChars == null) { - while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { + while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) { end--; } } else if (stripChars.length() == 0) { return str; } else { - while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND)) { + while (end != 0 && stripChars.indexOf(str.charAt(end - 1)) != INDEX_NOT_FOUND) { end--; } } @@ -1087,7 +1087,7 @@ public class StringUtils { if (startPos < 0) { startPos = 0; } - int endLimit = (str.length() - searchStr.length()) + 1; + int endLimit = str.length() - searchStr.length() + 1; if (startPos > endLimit) { return INDEX_NOT_FOUND; } @@ -1333,7 +1333,7 @@ public class StringUtils { if (str == null || searchStr == null) { return INDEX_NOT_FOUND; } - if (startPos > (str.length() - searchStr.length())) { + if (startPos > str.length() - searchStr.length()) { startPos = str.length() - searchStr.length(); } if (startPos < 0) { @@ -1946,7 +1946,7 @@ public class StringUtils { } } - return (ret == Integer.MAX_VALUE) ? INDEX_NOT_FOUND : ret; + return ret == Integer.MAX_VALUE ? INDEX_NOT_FOUND : ret; } /** @@ -2212,7 +2212,7 @@ public class StringUtils { if (pos < 0) { pos = 0; } - if (str.length() <= (pos + len)) { + if (str.length() <= pos + len) { return str.substring(pos); } return str.substring(pos, pos + len); @@ -2378,7 +2378,7 @@ public class StringUtils { return EMPTY; } int pos = str.lastIndexOf(separator); - if (pos == INDEX_NOT_FOUND || pos == (str.length() - separator.length())) { + if (pos == INDEX_NOT_FOUND || pos == str.length() - separator.length()) { return EMPTY; } return str.substring(pos + separator.length()); @@ -2486,7 +2486,7 @@ public class StringUtils { int openLen = open.length(); List list = new ArrayList(); int pos = 0; - while (pos < (strLen - closeLen)) { + while (pos < strLen - closeLen) { int start = str.indexOf(open, pos); if (start < 0) { break; @@ -2773,7 +2773,7 @@ public class StringUtils { return ArrayUtils.EMPTY_STRING_ARRAY; } - if ((separator == null) || (EMPTY.equals(separator))) { + if (separator == null || EMPTY.equals(separator)) { // Split on whitespace. return splitWorker(str, null, max, preserveAllTokens); } @@ -2932,7 +2932,7 @@ public class StringUtils { match = true; i++; } - if (match || (preserveAllTokens && lastMatch)) { + if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } return list.toArray(new String[list.size()]); @@ -3108,7 +3108,7 @@ public class StringUtils { i++; } } - if (match || (preserveAllTokens && lastMatch)) { + if (match || preserveAllTokens && lastMatch) { list.add(str.substring(start, i)); } return list.toArray(new String[list.size()]); @@ -3299,7 +3299,7 @@ public class StringUtils { if (array == null) { return null; } - int noOfItems = (endIndex - startIndex); + int noOfItems = endIndex - startIndex; if (noOfItems <= 0) { return EMPTY; } @@ -3384,7 +3384,7 @@ public class StringUtils { // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) // (Assuming that all Strings are roughly equally long) - int noOfItems = (endIndex - startIndex); + int noOfItems = endIndex - startIndex; if (noOfItems <= 0) { return EMPTY; } @@ -3867,8 +3867,8 @@ public class StringUtils { } int replLength = searchString.length(); int increase = replacement.length() - replLength; - increase = (increase < 0 ? 0 : increase); - increase *= (max < 0 ? 16 : (max > 64 ? 64 : max)); + increase = increase < 0 ? 0 : increase; + increase *= max < 0 ? 16 : max > 64 ? 64 : max; StringBuilder buf = new StringBuilder(text.length() + increase); while (end != INDEX_NOT_FOUND) { buf.append(text.substring(start, end)).append(replacement); @@ -5214,7 +5214,7 @@ public class StringUtils { } int sz = cs.length(); for (int i = 0; i < sz; i++) { - if ((Character.isLetter(cs.charAt(i)) == false) && (cs.charAt(i) != ' ')) { + if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } @@ -5284,7 +5284,7 @@ public class StringUtils { } int sz = cs.length(); for (int i = 0; i < sz; i++) { - if ((Character.isLetterOrDigit(cs.charAt(i)) == false) && (cs.charAt(i) != ' ')) { + if (Character.isLetterOrDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } @@ -5396,7 +5396,7 @@ public class StringUtils { } int sz = cs.length(); for (int i = 0; i < sz; i++) { - if ((Character.isDigit(cs.charAt(i)) == false) && (cs.charAt(i) != ' ')) { + if (Character.isDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { return false; } } @@ -5429,7 +5429,7 @@ public class StringUtils { } int sz = cs.length(); for (int i = 0; i < sz; i++) { - if ((Character.isWhitespace(cs.charAt(i)) == false)) { + if (Character.isWhitespace(cs.charAt(i)) == false) { return false; } } @@ -5726,7 +5726,7 @@ public class StringUtils { if (offset > str.length()) { offset = str.length(); } - if ((str.length() - offset) < (maxWidth - 3)) { + if (str.length() - offset < maxWidth - 3) { offset = str.length() - (maxWidth - 3); } final String abrevMarker = "..."; @@ -5736,7 +5736,7 @@ public class StringUtils { if (maxWidth < 7) { throw new IllegalArgumentException("Minimum abbreviation width with offset is 7"); } - if ((offset + (maxWidth - 3)) < str.length()) { + if (offset + maxWidth - 3 < str.length()) { return abrevMarker + abbreviate(str.substring(offset), maxWidth - 3); } return abrevMarker + str.substring(str.length() - (maxWidth - 3)); @@ -5776,7 +5776,7 @@ public class StringUtils { return str; } - if (length >= str.length() || length < (middle.length()+2)) { + if (length >= str.length() || length < middle.length()+2) { return str; } @@ -5934,7 +5934,7 @@ public class StringUtils { } // handle lists containing all nulls or all empty strings - if (allStringsNull || (longestStrLen == 0 && !anyStringNull)) { + if (allStringsNull || longestStrLen == 0 && !anyStringNull) { return INDEX_NOT_FOUND; } @@ -6365,7 +6365,7 @@ public class StringUtils { */ private static boolean startsWith(CharSequence str, CharSequence prefix, boolean ignoreCase) { if (str == null || prefix == null) { - return (str == null && prefix == null); + return str == null && prefix == null; } if (prefix.length() > str.length()) { return false; diff --git a/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentUtils.java b/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentUtils.java index 7f43e90d6..131869c58 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentUtils.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/ConcurrentUtils.java @@ -181,7 +181,7 @@ public class ConcurrentUtils { */ public static T initialize(ConcurrentInitializer initializer) throws ConcurrentException { - return (initializer != null) ? initializer.get() : null; + return initializer != null ? initializer.get() : null; } /** @@ -244,7 +244,7 @@ public class ConcurrentUtils { } V result = map.putIfAbsent(key, value); - return (result != null) ? result : value; + return result != null ? result : value; } /** diff --git a/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java index d01be5a1b..e013b54ee 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/ConstantInitializer.java @@ -88,7 +88,7 @@ public class ConstantInitializer implements ConcurrentInitializer { */ @Override public int hashCode() { - return (getObject() != null) ? getObject().hashCode() : 0; + return getObject() != null ? getObject().hashCode() : 0; } /** diff --git a/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java b/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java index e80d6c081..d5cb0839d 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/TimedSemaphore.java @@ -358,7 +358,7 @@ public class TimedSemaphore { * unit */ public synchronized double getAverageCallsPerPeriod() { - return (periodCount == 0) ? 0 : (double) totalAcquireCount + return periodCount == 0 ? 0 : (double) totalAcquireCount / (double) periodCount; } diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index 03664d365..6acb4073e 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -178,7 +178,7 @@ public class ExceptionUtils { */ public static Throwable getRootCause(Throwable throwable) { List list = getThrowableList(throwable); - return (list.size() < 2 ? null : (Throwable)list.get(list.size() - 1)); + return list.size() < 2 ? null : (Throwable)list.get(list.size() - 1); } /** @@ -690,7 +690,7 @@ public class ExceptionUtils { */ public static String getRootCauseMessage(Throwable th) { Throwable root = ExceptionUtils.getRootCause(th); - root = (root == null ? th : root); + root = root == null ? th : root; return getMessage(root); } diff --git a/src/main/java/org/apache/commons/lang3/math/Fraction.java b/src/main/java/org/apache/commons/lang3/math/Fraction.java index 32dea9746..21bbf9d5b 100644 --- a/src/main/java/org/apache/commons/lang3/math/Fraction.java +++ b/src/main/java/org/apache/commons/lang3/math/Fraction.java @@ -247,7 +247,7 @@ public final class Fraction extends Number implements Comparable { * @throws ArithmeticException if the the algorithm does not converge */ public static Fraction getFraction(double value) { - int sign = (value < 0 ? -1 : 1); + int sign = value < 0 ? -1 : 1; value = Math.abs(value); if (value > Integer.MAX_VALUE || Double.isNaN(value)) { throw new ArithmeticException @@ -291,7 +291,7 @@ public final class Fraction extends Number implements Comparable { denom1 = denom2; i++; // System.out.println(">>" + delta1 +" "+ delta2+" "+(delta1 > delta2)+" "+i+" "+denom2); - } while ((delta1 > delta2) && (denom2 <= 10000) && (denom2 > 0) && (i < 25)); + } while (delta1 > delta2 && denom2 <= 10000 && denom2 > 0 && i < 25); if (i == 25) { throw new ArithmeticException("Unable to convert double to fraction"); } @@ -440,7 +440,7 @@ public final class Fraction extends Number implements Comparable { */ @Override public float floatValue() { - return ((float) numerator) / ((float) denominator); + return (float) numerator / (float) denominator; } /** @@ -451,7 +451,7 @@ public final class Fraction extends Number implements Comparable { */ @Override public double doubleValue() { - return ((double) numerator) / ((double) denominator); + return (double) numerator / (double) denominator; } // Calculations @@ -555,7 +555,7 @@ public final class Fraction extends Number implements Comparable { return this.invert().pow(-power); } else { Fraction f = this.multiplyBy(this); - if ((power % 2) == 0) { // if even... + if (power % 2 == 0) { // if even... return f.pow(power/2); } else { // if odd... return f.pow(power/2).multiplyBy(this); @@ -575,8 +575,8 @@ public final class Fraction extends Number implements Comparable { */ private static int greatestCommonDivisor(int u, int v) { // From Commons Math: - if ((u == 0) || (v == 0)) { - if ((u == Integer.MIN_VALUE) || (v == Integer.MIN_VALUE)) { + if (u == 0 || v == 0) { + if (u == Integer.MIN_VALUE || v == Integer.MIN_VALUE) { throw new ArithmeticException("overflow: gcd is 2^31"); } return Math.abs(u) + Math.abs(v); @@ -601,7 +601,7 @@ public final class Fraction extends Number implements Comparable { } // B2. Initialize: u and v have been divided by 2^k and at least // one is odd. - int t = ((u&1)==1) ? v : -(u/2)/*B3*/; + int t = (u&1)==1 ? v : -(u/2)/*B3*/; // t negative: u was odd, v may be even (t replaces v) // t positive: u was even, v is odd (t replaces u) do { @@ -637,7 +637,7 @@ public final class Fraction extends Number implements Comparable { * an int */ private static int mulAndCheck(int x, int y) { - long m = ((long)x)*((long)y); + long m = (long)x*(long)y; if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) { throw new ArithmeticException("overflow: mul"); @@ -656,7 +656,7 @@ public final class Fraction extends Number implements Comparable { */ private static int mulPosAndCheck(int x, int y) { /* assert x>=0 && y>=0; */ - long m = ((long)x)*((long)y); + long m = (long)x*(long)y; if (m > Integer.MAX_VALUE) { throw new ArithmeticException("overflow: mulPos"); } @@ -770,7 +770,7 @@ public final class Fraction extends Number implements Comparable { // but d2 doesn't need extra precision because // d2 = gcd(t,d1) = gcd(t mod d1, d1) int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue(); - int d2 = (tmodd1==0)?d1:greatestCommonDivisor(tmodd1, d1); + int d2 = tmodd1==0?d1:greatestCommonDivisor(tmodd1, d1); // result is (t/d2) / (u'/d1)(v'/d2) BigInteger w = t.divide(BigInteger.valueOf(d2)); @@ -849,8 +849,8 @@ public final class Fraction extends Number implements Comparable { return false; } Fraction other = (Fraction) obj; - return (getNumerator() == other.getNumerator() && - getDenominator() == other.getDenominator()); + return getNumerator() == other.getNumerator() && + getDenominator() == other.getDenominator(); } /** diff --git a/src/main/java/org/apache/commons/lang3/mutable/MutableDouble.java b/src/main/java/org/apache/commons/lang3/mutable/MutableDouble.java index d0a2124ff..b36abe29d 100644 --- a/src/main/java/org/apache/commons/lang3/mutable/MutableDouble.java +++ b/src/main/java/org/apache/commons/lang3/mutable/MutableDouble.java @@ -271,8 +271,8 @@ public class MutableDouble extends Number implements Comparable, */ @Override public boolean equals(Object obj) { - return (obj instanceof MutableDouble) - && (Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value)); + return obj instanceof MutableDouble + && Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value); } /** @@ -283,7 +283,7 @@ public class MutableDouble extends Number implements Comparable, @Override public int hashCode() { long bits = Double.doubleToLongBits(value); - return (int) (bits ^ (bits >>> 32)); + return (int) (bits ^ bits >>> 32); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/mutable/MutableFloat.java b/src/main/java/org/apache/commons/lang3/mutable/MutableFloat.java index 4a0512c67..ed871910e 100644 --- a/src/main/java/org/apache/commons/lang3/mutable/MutableFloat.java +++ b/src/main/java/org/apache/commons/lang3/mutable/MutableFloat.java @@ -273,8 +273,8 @@ public class MutableFloat extends Number implements Comparable, Mu */ @Override public boolean equals(Object obj) { - return (obj instanceof MutableFloat) - && (Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value)); + return obj instanceof MutableFloat + && Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value); } /** diff --git a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java index cf755d265..9bff480db 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java +++ b/src/main/java/org/apache/commons/lang3/text/StrSubstitutor.java @@ -580,7 +580,7 @@ public class StrSubstitutor { StrMatcher suffixMatcher = getVariableSuffixMatcher(); char escape = getEscapeChar(); - boolean top = (priorVariables == null); + boolean top = priorVariables == null; boolean altered = false; int lengthChange = 0; char[] chars = buf.buffer; @@ -656,7 +656,7 @@ public class StrSubstitutor { int change = substitute(buf, startPos, varLen, priorVariables); change = change - + (varLen - (endPos - startPos)); + + varLen - (endPos - startPos); pos += change; bufEnd += change; lengthChange += change; @@ -678,7 +678,7 @@ public class StrSubstitutor { } } if (top) { - return (altered ? 1 : 0); + return altered ? 1 : 0; } return lengthChange; } diff --git a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java index f1dc33298..c98463e87 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java +++ b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java @@ -728,7 +728,7 @@ public class StrTokenizer implements ListIterator, Cloneable { // string or the end of the input workArea.clear(); int pos = start; - boolean quoting = (quoteLen > 0); + boolean quoting = quoteLen > 0; int trimStart = 0; while (pos < len) { @@ -746,7 +746,7 @@ public class StrTokenizer implements ListIterator, Cloneable { if (isQuote(chars, pos + quoteLen, len, quoteStart, quoteLen)) { // matched pair of quotes, thus an escaped quote workArea.append(chars, pos, quoteLen); - pos += (quoteLen * 2); + pos += quoteLen * 2; trimStart = workArea.size(); continue; } @@ -820,7 +820,7 @@ public class StrTokenizer implements ListIterator, Cloneable { */ private boolean isQuote(char[] chars, int pos, int len, int quoteStart, int quoteLen) { for (int i = 0; i < quoteLen; i++) { - if ((pos + i) >= len || chars[pos + i] != chars[quoteStart + i]) { + if (pos + i >= len || chars[pos + i] != chars[quoteStart + i]) { return false; } } diff --git a/src/main/java/org/apache/commons/lang3/text/WordUtils.java b/src/main/java/org/apache/commons/lang3/text/WordUtils.java index 1cc90dca1..e5c0d4263 100644 --- a/src/main/java/org/apache/commons/lang3/text/WordUtils.java +++ b/src/main/java/org/apache/commons/lang3/text/WordUtils.java @@ -99,7 +99,7 @@ public class WordUtils { int offset = 0; StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); - while ((inputLineLength - offset) > wrapLength) { + while (inputLineLength - offset > wrapLength) { if (str.charAt(offset) == ' ') { offset++; continue; @@ -267,7 +267,7 @@ public class WordUtils { * @since 2.1 */ public static String capitalizeFully(String str, char... delimiters) { - int delimLen = (delimiters == null ? -1 : delimiters.length); + int delimLen = delimiters == null ? -1 : delimiters.length; if (StringUtils.isEmpty(str) || delimLen == 0) { return str; } @@ -323,7 +323,7 @@ public class WordUtils { * @since 2.1 */ public static String uncapitalize(String str, char... delimiters) { - int delimLen = (delimiters == null ? -1 : delimiters.length); + int delimLen = delimiters == null ? -1 : delimiters.length; if (StringUtils.isEmpty(str) || delimLen == 0) { return str; } diff --git a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java index 739db3227..4270df751 100644 --- a/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java +++ b/src/main/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaper.java @@ -68,7 +68,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator { * @return whether the option is set */ public boolean isSet(OPTION option) { - return (options == null) ? false : options.contains(option); + return options == null ? false : options.contains(option); } /** @@ -95,14 +95,14 @@ public class NumericEntityUnescaper extends CharSequenceTranslator { int end = start; // Note that this supports character codes without a ; on the end - while(end < seqEnd && ( (input.charAt(end) >= '0' && input.charAt(end) <= '9') || - (input.charAt(end) >= 'a' && input.charAt(end) <= 'f') || - (input.charAt(end) >= 'A' && input.charAt(end) <= 'F') ) ) + while(end < seqEnd && ( input.charAt(end) >= '0' && input.charAt(end) <= '9' || + input.charAt(end) >= 'a' && input.charAt(end) <= 'f' || + input.charAt(end) >= 'A' && input.charAt(end) <= 'F' ) ) { end++; } - boolean semiNext = (end != seqEnd) && (input.charAt(end) == ';'); + boolean semiNext = end != seqEnd && input.charAt(end) == ';'; if(!semiNext) { if(isSet(OPTION.semiColonRequired)) { @@ -132,7 +132,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator { out.write(entityValue); } - return 2 + (end - start) + (isHex ? 1 : 0) + (semiNext ? 1 : 0); + return 2 + end - start + (isHex ? 1 : 0) + (semiNext ? 1 : 0); } return 0; } diff --git a/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java b/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java index 545f8344b..b9edbb0c8 100644 --- a/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java +++ b/src/main/java/org/apache/commons/lang3/text/translate/UnicodeUnescaper.java @@ -34,18 +34,18 @@ public class UnicodeUnescaper extends CharSequenceTranslator { */ @Override public int translate(CharSequence input, int index, Writer out) throws IOException { - if (input.charAt(index) == '\\' && (index + 1 < input.length()) && input.charAt(index + 1) == 'u') { + if (input.charAt(index) == '\\' && index + 1 < input.length() && input.charAt(index + 1) == 'u') { // consume optional additional 'u' chars int i = 2; - while ((index + i < input.length()) && input.charAt(index + i) == 'u') { + while (index + i < input.length() && input.charAt(index + i) == 'u') { i++; } - if ((index + i < input.length()) && (input.charAt(index + i) == '+')) { + if (index + i < input.length() && input.charAt(index + i) == '+') { i++; } - if ((index + i + 4 <= input.length())) { + if (index + i + 4 <= input.length()) { // Get 4 hex digits CharSequence unicode = input.subSequence(index + i, index + i + 4); diff --git a/src/main/java/org/apache/commons/lang3/time/StopWatch.java b/src/main/java/org/apache/commons/lang3/time/StopWatch.java index 0b7dd7b6c..0c3dad1fa 100644 --- a/src/main/java/org/apache/commons/lang3/time/StopWatch.java +++ b/src/main/java/org/apache/commons/lang3/time/StopWatch.java @@ -248,7 +248,7 @@ public class StopWatch { if (this.runningState != STATE_SUSPENDED) { throw new IllegalStateException("Stopwatch must be suspended to resume. "); } - this.startTime += (System.nanoTime() - this.stopTime); + this.startTime += System.nanoTime() - this.stopTime; this.runningState = STATE_RUNNING; } diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java index 89b912df0..711b61013 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsAddTest.java @@ -197,33 +197,33 @@ public class ArrayUtilsAddTest { //show that not casting is okay newArray = ArrayUtils.add((Object[])null, "a"); - assertTrue(Arrays.equals((new String[]{"a"}), newArray)); - assertTrue(Arrays.equals((new Object[]{"a"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a"}, newArray)); + assertTrue(Arrays.equals(new Object[]{"a"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); //show that not casting to Object[] is okay and will assume String based on "a" String[] newStringArray = ArrayUtils.add(null, "a"); - assertTrue(Arrays.equals((new String[]{"a"}), newStringArray)); - assertTrue(Arrays.equals((new Object[]{"a"}), newStringArray)); + assertTrue(Arrays.equals(new String[]{"a"}, newStringArray)); + assertTrue(Arrays.equals(new Object[]{"a"}, newStringArray)); assertEquals(String.class, newStringArray.getClass().getComponentType()); String[] stringArray1 = new String[]{"a", "b", "c"}; newArray = ArrayUtils.add(stringArray1, null); - assertTrue(Arrays.equals((new String[]{"a", "b", "c", null}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c", null}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.add(stringArray1, "d"); - assertTrue(Arrays.equals((new String[]{"a", "b", "c", "d"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c", "d"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); Number[] numberArray1 = new Number[]{Integer.valueOf(1), Double.valueOf(2)}; newArray = ArrayUtils.add(numberArray1, Float.valueOf(3)); - assertTrue(Arrays.equals((new Number[]{Integer.valueOf(1), Double.valueOf(2), Float.valueOf(3)}), newArray)); + assertTrue(Arrays.equals(new Number[]{Integer.valueOf(1), Double.valueOf(2), Float.valueOf(3)}, newArray)); assertEquals(Number.class, newArray.getClass().getComponentType()); numberArray1 = null; newArray = ArrayUtils.add(numberArray1, Float.valueOf(3)); - assertTrue(Arrays.equals((new Float[]{Float.valueOf(3)}), newArray)); + assertTrue(Arrays.equals(new Float[]{Float.valueOf(3)}, newArray)); assertEquals(Float.class, newArray.getClass().getComponentType()); } @@ -256,31 +256,31 @@ public class ArrayUtilsAddTest { newArray = ArrayUtils.addAll(stringArray1, (String[]) null); assertNotSame(stringArray1, newArray); assertTrue(Arrays.equals(stringArray1, newArray)); - assertTrue(Arrays.equals((new String[]{"a", "b", "c"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.addAll(null, stringArray2); assertNotSame(stringArray2, newArray); assertTrue(Arrays.equals(stringArray2, newArray)); - assertTrue(Arrays.equals((new String[]{"1", "2", "3"}), newArray)); + assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.addAll(stringArray1, stringArray2); - assertTrue(Arrays.equals((new String[]{"a", "b", "c", "1", "2", "3"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c", "1", "2", "3"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, (String[]) null); assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); - assertTrue(Arrays.equals((new String[]{}), newArray)); + assertTrue(Arrays.equals(new String[]{}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.addAll(null, ArrayUtils.EMPTY_STRING_ARRAY); assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); - assertTrue(Arrays.equals((new String[]{}), newArray)); + assertTrue(Arrays.equals(new String[]{}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.EMPTY_STRING_ARRAY); assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); - assertTrue(Arrays.equals((new String[]{}), newArray)); + assertTrue(Arrays.equals(new String[]{}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); String[] stringArrayNull = new String []{null}; newArray = ArrayUtils.addAll(stringArrayNull, stringArrayNull); - assertTrue(Arrays.equals((new String[]{null, null}), newArray)); + assertTrue(Arrays.equals(new String[]{null, null}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); // boolean @@ -369,21 +369,21 @@ public class ArrayUtilsAddTest { public void testAddObjectAtIndex() { Object[] newArray; newArray = ArrayUtils.add((Object[])null, 0, "a"); - assertTrue(Arrays.equals((new String[]{"a"}), newArray)); - assertTrue(Arrays.equals((new Object[]{"a"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a"}, newArray)); + assertTrue(Arrays.equals(new Object[]{"a"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); String[] stringArray1 = new String[]{"a", "b", "c"}; newArray = ArrayUtils.add(stringArray1, 0, null); - assertTrue(Arrays.equals((new String[]{null, "a", "b", "c"}), newArray)); + assertTrue(Arrays.equals(new String[]{null, "a", "b", "c"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.add(stringArray1, 1, null); - assertTrue(Arrays.equals((new String[]{"a", null, "b", "c"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", null, "b", "c"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.add(stringArray1, 3, null); - assertTrue(Arrays.equals((new String[]{"a", "b", "c", null}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c", null}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); newArray = ArrayUtils.add(stringArray1, 3, "d"); - assertTrue(Arrays.equals((new String[]{"a", "b", "c", "d"}), newArray)); + assertTrue(Arrays.equals(new String[]{"a", "b", "c", "d"}, newArray)); assertEquals(String.class, newArray.getClass().getComponentType()); assertEquals(String.class, newArray.getClass().getComponentType()); diff --git a/src/test/java/org/apache/commons/lang3/BitFieldTest.java b/src/test/java/org/apache/commons/lang3/BitFieldTest.java index c41e20c7c..12778160c 100644 --- a/src/test/java/org/apache/commons/lang3/BitFieldTest.java +++ b/src/test/java/org/apache/commons/lang3/BitFieldTest.java @@ -149,7 +149,7 @@ public class BitFieldTest extends TestCase { } for (int j = 0; j < 128; j++) { assertEquals(bf_zero.getShortValue(bf_zero.setShortValue((short) 0, (short) j)), (short) 0); - assertEquals(bf_zero.setShortValue((short) 0, (short) j), (short) (0)); + assertEquals(bf_zero.setShortValue((short) 0, (short) j), (short) 0); } // verify that excess bits are stripped off diff --git a/src/test/java/org/apache/commons/lang3/CharUtilsPerfRun.java b/src/test/java/org/apache/commons/lang3/CharUtilsPerfRun.java index 5ae59d354..5655b047e 100644 --- a/src/test/java/org/apache/commons/lang3/CharUtilsPerfRun.java +++ b/src/test/java/org/apache/commons/lang3/CharUtilsPerfRun.java @@ -148,7 +148,7 @@ public class CharUtilsPerfRun { int t = 0; for (int i = 0; i < loopCount; i++) { for (char ch : CHAR_SAMPLES) { - boolean b = (ch >= '0' && ch <= '9'); + boolean b = ch >= '0' && ch <= '9'; t += b ? 1 : 0; } } diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index a01c62005..55ce99add 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -286,7 +286,7 @@ public class RandomStringUtilsTest extends junit.framework.TestCase { double sumSq = 0.0d; double dev = 0.0d; for (int i = 0; i < observed.length; i++) { - dev = (observed[i] - expected[i]); + dev = observed[i] - expected[i]; sumSq += dev * dev / expected[i]; } return sumSq; @@ -311,8 +311,8 @@ public class RandomStringUtilsTest extends junit.framework.TestCase { for (int i=0; i < orig.length() && i < copy.length(); i++) { char o = orig.charAt(i); char c = copy.charAt(i); - assertEquals("differs at " + i + "(" + Integer.toHexString((new Character(o)).hashCode()) + "," + - Integer.toHexString((new Character(c)).hashCode()) + ")", o, c); + assertEquals("differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," + + Integer.toHexString(new Character(c).hashCode()) + ")", o, c); } // compare length also assertEquals(orig.length(), copy.length()); diff --git a/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java index d0943c08b..a4b923d33 100644 --- a/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/CompareToBuilderTest.java @@ -46,7 +46,7 @@ public class CompareToBuilderTest { return false; } TestObject rhs = (TestObject) o; - return (a == rhs.a); + return a == rhs.a; } public void setA(int a) { @@ -57,7 +57,7 @@ public class CompareToBuilderTest { return a; } public int compareTo(TestObject rhs) { - return (a < rhs.a) ? -1 : (a > rhs.a) ? +1 : 0; + return a < rhs.a ? -1 : a > rhs.a ? +1 : 0; } } @@ -79,7 +79,7 @@ public class CompareToBuilderTest { return false; } TestSubObject rhs = (TestSubObject) o; - return super.equals(o) && (b == rhs.b); + return super.equals(o) && b == rhs.b; } } @@ -231,7 +231,7 @@ public class CompareToBuilderTest { } // strongly recommended but not strictly required - assertTrue((CompareToBuilder.reflectionCompare(x, y, testTransients) ==0 ) == EqualsBuilder.reflectionEquals(x, y, testTransients)); + assertTrue(CompareToBuilder.reflectionCompare(x, y, testTransients) ==0 == EqualsBuilder.reflectionEquals(x, y, testTransients)); } /** @@ -823,9 +823,9 @@ public class CompareToBuilderTest { float[][] array3 = new float[2][3]; for (int i = 0; i < array1.length; ++i) { for (int j = 0; j < array1[0].length; j++) { - array1[i][j] = ((i + 1) * (j + 1)); - array2[i][j] = ((i + 1) * (j + 1)); - array3[i][j] = ((i + 1) * (j + 1)); + array1[i][j] = (i + 1) * (j + 1); + array2[i][j] = (i + 1) * (j + 1); + array3[i][j] = (i + 1) * (j + 1); } } array3[1][2] = 100; @@ -847,9 +847,9 @@ public class CompareToBuilderTest { double[][] array3 = new double[2][3]; for (int i = 0; i < array1.length; ++i) { for (int j = 0; j < array1[0].length; j++) { - array1[i][j] = ((i + 1) * (j + 1)); - array2[i][j] = ((i + 1) * (j + 1)); - array3[i][j] = ((i + 1) * (j + 1)); + array1[i][j] = (i + 1) * (j + 1); + array2[i][j] = (i + 1) * (j + 1); + array3[i][j] = (i + 1) * (j + 1); } } array3[1][2] = 100; @@ -871,9 +871,9 @@ public class CompareToBuilderTest { boolean[][] array3 = new boolean[2][3]; for (int i = 0; i < array1.length; ++i) { for (int j = 0; j < array1[0].length; j++) { - array1[i][j] = ((i == 1) ^ (j == 1)); - array2[i][j] = ((i == 1) ^ (j == 1)); - array3[i][j] = ((i == 1) ^ (j == 1)); + array1[i][j] = i == 1 ^ j == 1; + array2[i][j] = i == 1 ^ j == 1; + array3[i][j] = i == 1 ^ j == 1; } } array3[1][2] = false; diff --git a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java index a4806f46a..14415b46f 100644 --- a/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java @@ -50,7 +50,7 @@ public class EqualsBuilderTest { } TestObject rhs = (TestObject) o; - return (a == rhs.a); + return a == rhs.a; } public void setA(int a) { @@ -80,7 +80,7 @@ public class EqualsBuilderTest { } TestSubObject rhs = (TestSubObject) o; - return super.equals(o) && (b == rhs.b); + return super.equals(o) && b == rhs.b; } public void setB(int b) { @@ -712,8 +712,8 @@ public class EqualsBuilderTest { boolean[][] array2 = new boolean[2][2]; for (int i = 0; i < array1.length; ++i) { for (int j = 0; j < array1[0].length; j++) { - array1[i][j] = (i == 1) || (j == 1); - array2[i][j] = (i == 1) || (j == 1); + array1[i][j] = i == 1 || j == 1; + array2[i][j] = i == 1 || j == 1; } } assertTrue(new EqualsBuilder().append(array1, array1).isEquals()); diff --git a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java index e2f84a76e..573128422 100644 --- a/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/HashCodeBuilderTest.java @@ -94,7 +94,7 @@ public class HashCodeBuilderTest { return false; } TestObject rhs = (TestObject) o; - return (a == rhs.a); + return a == rhs.a; } public void setA(int a) { @@ -131,7 +131,7 @@ public class HashCodeBuilderTest { return false; } TestSubObject rhs = (TestSubObject) o; - return super.equals(o) && (b == rhs.b); + return super.equals(o) && b == rhs.b; } } @@ -204,7 +204,7 @@ public class HashCodeBuilderTest { @Test public void testSuper() { Object obj = new Object(); - assertEquals(17 * 37 + (19 * 41 + obj.hashCode()), new HashCodeBuilder(17, 37).appendSuper( + assertEquals(17 * 37 + 19 * 41 + obj.hashCode(), new HashCodeBuilder(17, 37).appendSuper( new HashCodeBuilder(19, 41).append(obj).toHashCode()).toHashCode()); } @@ -228,7 +228,7 @@ public class HashCodeBuilderTest { @SuppressWarnings("cast") // cast is not really needed, keep for consistency public void testLong() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long) 0L).toHashCode()); - assertEquals(17 * 37 + (int) (123456789L ^ (123456789L >> 32)), new HashCodeBuilder(17, 37).append( + assertEquals(17 * 37 + (int) (123456789L ^ 123456789L >> 32), new HashCodeBuilder(17, 37).append( (long) 123456789L).toHashCode()); } @@ -263,7 +263,7 @@ public class HashCodeBuilderTest { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double) 0d).toHashCode()); double d = 1234567.89; long l = Double.doubleToLongBits(d); - assertEquals(17 * 37 + (int) (l ^ (l >> 32)), new HashCodeBuilder(17, 37).append(d).toHashCode()); + assertEquals(17 * 37 + (int) (l ^ l >> 32), new HashCodeBuilder(17, 37).append(d).toHashCode()); } @Test @@ -285,7 +285,7 @@ public class HashCodeBuilderTest { public void testObjectArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((Object[]) null).toHashCode()); Object[] obj = new Object[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = new Object(); assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = new Object(); @@ -296,7 +296,7 @@ public class HashCodeBuilderTest { @Test public void testObjectArrayAsObject() { Object[] obj = new Object[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = new Object(); assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = new Object(); @@ -308,24 +308,24 @@ public class HashCodeBuilderTest { public void testLongArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long[]) null).toHashCode()); long[] obj = new long[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = 5L; - int h1 = (int) (5L ^ (5L >> 32)); + int h1 = (int) (5L ^ 5L >> 32); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = 6L; - int h2 = (int) (6L ^ (6L >> 32)); + int h2 = (int) (6L ^ 6L >> 32); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode()); } @Test public void testLongArrayAsObject() { long[] obj = new long[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = 5L; - int h1 = (int) (5L ^ (5L >> 32)); + int h1 = (int) (5L ^ 5L >> 32); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = 6L; - int h2 = (int) (6L ^ (6L >> 32)); + int h2 = (int) (6L ^ 6L >> 32); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); } @@ -333,7 +333,7 @@ public class HashCodeBuilderTest { public void testIntArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((int[]) null).toHashCode()); int[] obj = new int[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = 6; @@ -343,7 +343,7 @@ public class HashCodeBuilderTest { @Test public void testIntArrayAsObject() { int[] obj = new int[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = 6; @@ -354,7 +354,7 @@ public class HashCodeBuilderTest { public void testShortArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short[]) null).toHashCode()); short[] obj = new short[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = (short) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = (short) 6; @@ -364,7 +364,7 @@ public class HashCodeBuilderTest { @Test public void testShortArrayAsObject() { short[] obj = new short[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = (short) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = (short) 6; @@ -375,7 +375,7 @@ public class HashCodeBuilderTest { public void testCharArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((char[]) null).toHashCode()); char[] obj = new char[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = (char) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = (char) 6; @@ -385,7 +385,7 @@ public class HashCodeBuilderTest { @Test public void testCharArrayAsObject() { char[] obj = new char[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = (char) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = (char) 6; @@ -396,7 +396,7 @@ public class HashCodeBuilderTest { public void testByteArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte[]) null).toHashCode()); byte[] obj = new byte[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = (byte) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = (byte) 6; @@ -406,7 +406,7 @@ public class HashCodeBuilderTest { @Test public void testByteArrayAsObject() { byte[] obj = new byte[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = (byte) 5; assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = (byte) 6; @@ -417,28 +417,28 @@ public class HashCodeBuilderTest { public void testDoubleArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double[]) null).toHashCode()); double[] obj = new double[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = 5.4d; long l1 = Double.doubleToLongBits(5.4d); - int h1 = (int) (l1 ^ (l1 >> 32)); + int h1 = (int) (l1 ^ l1 >> 32); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = 6.3d; long l2 = Double.doubleToLongBits(6.3d); - int h2 = (int) (l2 ^ (l2 >> 32)); + int h2 = (int) (l2 ^ l2 >> 32); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode()); } @Test public void testDoubleArrayAsObject() { double[] obj = new double[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = 5.4d; long l1 = Double.doubleToLongBits(5.4d); - int h1 = (int) (l1 ^ (l1 >> 32)); + int h1 = (int) (l1 ^ l1 >> 32); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[1] = 6.3d; long l2 = Double.doubleToLongBits(6.3d); - int h2 = (int) (l2 ^ (l2 >> 32)); + int h2 = (int) (l2 ^ l2 >> 32); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); } @@ -446,7 +446,7 @@ public class HashCodeBuilderTest { public void testFloatArray() { assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((float[]) null).toHashCode()); float[] obj = new float[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = 5.4f; int h1 = Float.floatToIntBits(5.4f); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); @@ -458,7 +458,7 @@ public class HashCodeBuilderTest { @Test public void testFloatArrayAsObject() { float[] obj = new float[2]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); obj[0] = 5.4f; int h1 = Float.floatToIntBits(5.4f); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); @@ -491,7 +491,7 @@ public class HashCodeBuilderTest { @Test public void testBooleanMultiArray() { boolean[][] obj = new boolean[2][]; - assertEquals((17 * 37) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(17 * 37 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = new boolean[0]; assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[0] = new boolean[1]; @@ -501,23 +501,23 @@ public class HashCodeBuilderTest { obj[0][0] = true; assertEquals(((17 * 37 + 0) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); obj[1] = new boolean[1]; - assertEquals((((17 * 37 + 0) * 37 + 1) * 37 + 1), new HashCodeBuilder(17, 37).append(obj).toHashCode()); + assertEquals(((17 * 37 + 0) * 37 + 1) * 37 + 1, new HashCodeBuilder(17, 37).append(obj).toHashCode()); } @Test public void testReflectionHashCodeExcludeFields() throws Exception { TestObjectWithMultipleFields x = new TestObjectWithMultipleFields(1, 2, 3); - assertEquals((((17 * 37 + 1) * 37 + 2) * 37 + 3), HashCodeBuilder.reflectionHashCode(x)); + assertEquals(((17 * 37 + 1) * 37 + 2) * 37 + 3, HashCodeBuilder.reflectionHashCode(x)); - assertEquals((((17 * 37 + 1) * 37 + 2) * 37 + 3), HashCodeBuilder.reflectionHashCode(x, (String[]) null)); - assertEquals((((17 * 37 + 1) * 37 + 2) * 37 + 3), HashCodeBuilder.reflectionHashCode(x, new String[]{})); - assertEquals((((17 * 37 + 1) * 37 + 2) * 37 + 3), HashCodeBuilder.reflectionHashCode(x, new String[]{"xxx"})); + assertEquals(((17 * 37 + 1) * 37 + 2) * 37 + 3, HashCodeBuilder.reflectionHashCode(x, (String[]) null)); + assertEquals(((17 * 37 + 1) * 37 + 2) * 37 + 3, HashCodeBuilder.reflectionHashCode(x, new String[]{})); + assertEquals(((17 * 37 + 1) * 37 + 2) * 37 + 3, HashCodeBuilder.reflectionHashCode(x, new String[]{"xxx"})); - assertEquals(((17 * 37 + 1) * 37 + 3), HashCodeBuilder.reflectionHashCode(x, new String[]{"two"})); - assertEquals(((17 * 37 + 1) * 37 + 2), HashCodeBuilder.reflectionHashCode(x, new String[]{"three"})); + assertEquals((17 * 37 + 1) * 37 + 3, HashCodeBuilder.reflectionHashCode(x, new String[]{"two"})); + assertEquals((17 * 37 + 1) * 37 + 2, HashCodeBuilder.reflectionHashCode(x, new String[]{"three"})); - assertEquals((17 * 37 + 1), HashCodeBuilder.reflectionHashCode(x, new String[]{"two", "three"})); + assertEquals(17 * 37 + 1, HashCodeBuilder.reflectionHashCode(x, new String[]{"two", "three"})); assertEquals(17, HashCodeBuilder.reflectionHashCode(x, new String[]{"one", "two", "three"})); assertEquals(17, HashCodeBuilder.reflectionHashCode(x, new String[]{"one", "two", "three", "xxx"})); diff --git a/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java b/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java index 3f6577144..1f7e28bd4 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/TimedSemaphoreTest.java @@ -428,7 +428,7 @@ public class TimedSemaphoreTest { */ @Override protected ScheduledFuture startTimer() { - return (schedFuture != null) ? schedFuture : super.startTimer(); + return schedFuture != null ? schedFuture : super.startTimer(); } } diff --git a/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java b/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java index 240d5c16d..ca3219757 100644 --- a/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java +++ b/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java @@ -551,12 +551,12 @@ public class StrTokenizerTest extends TestCase { * null. */ public void testCloneNotSupportedException() { - Object notCloned = (new StrTokenizer() { + Object notCloned = new StrTokenizer() { @Override Object cloneReset() throws CloneNotSupportedException { throw new CloneNotSupportedException("test"); } - }).clone(); + }.clone(); assertNull(notCloned); }