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
This commit is contained in:
Gary D. Gregory 2011-11-09 17:53:59 +00:00
parent 725ca33769
commit 371e866442
31 changed files with 173 additions and 173 deletions

View File

@ -551,12 +551,12 @@ public static Boolean toBooleanObject(String str) {
switch (str.length()) { switch (str.length()) {
case 1: { case 1: {
char ch0 = str.charAt(0); char ch0 = str.charAt(0);
if ((ch0 == 'y' || ch0 == 'Y') || if (ch0 == 'y' || ch0 == 'Y' ||
(ch0 == 't' || ch0 == 'T')) { ch0 == 't' || ch0 == 'T') {
return Boolean.TRUE; return Boolean.TRUE;
} }
if ((ch0 == 'n' || ch0 == 'N') || if (ch0 == 'n' || ch0 == 'N' ||
(ch0 == 'f' || ch0 == 'F')) { ch0 == 'f' || ch0 == 'F') {
return Boolean.FALSE; return Boolean.FALSE;
} }
break; break;

View File

@ -187,7 +187,7 @@ static char[] toCharArray(CharSequence cs) {
static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart, static boolean regionMatches(CharSequence cs, boolean ignoreCase, int thisStart,
CharSequence substring, int start, int length) { CharSequence substring, int start, int length) {
if (cs instanceof String && substring instanceof String) { 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 { } else {
// TODO: Implement rather than convert to String // TODO: Implement rather than convert to String
return cs.toString().regionMatches(ignoreCase, thisStart, substring.toString(), start, length); return cs.toString().regionMatches(ignoreCase, thisStart, substring.toString(), start, length);

View File

@ -178,7 +178,7 @@ protected void add(String str) {
int len = str.length(); int len = str.length();
int pos = 0; int pos = 0;
while (pos < len) { while (pos < len) {
int remainder = (len - pos); int remainder = len - pos;
if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') { if (remainder >= 4 && str.charAt(pos) == '^' && str.charAt(pos + 2) == '-') {
// negated range // negated range
set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3))); set.add(CharRange.isNotIn(str.charAt(pos + 1), str.charAt(pos + 3)));

View File

@ -622,7 +622,7 @@ public static boolean isAssignable(Class<?> cls, Class<?> toClass, boolean autob
} }
// have to check for null, as isAssignableFrom doesn't // have to check for null, as isAssignableFrom doesn't
if (cls == null) { if (cls == null) {
return !(toClass.isPrimitive()); return !toClass.isPrimitive();
} }
//autoboxing: //autoboxing:
if (autoboxing) { if (autoboxing) {

View File

@ -136,7 +136,7 @@ public static <E extends Enum<E>> long generateBitVector(Class<E> enumClass, Ite
Validate.notNull(values); Validate.notNull(values);
long total = 0; long total = 0;
for (E constant : values) { for (E constant : values) {
total |= (1 << constant.ordinal()); total |= 1 << constant.ordinal();
} }
return total; return total;
} }
@ -179,7 +179,7 @@ public static <E extends Enum<E>> EnumSet<E> processBitVector(Class<E> enumClass
final E[] constants = checkBitVectorable(enumClass).getEnumConstants(); final E[] constants = checkBitVectorable(enumClass).getEnumConstants();
final EnumSet<E> results = EnumSet.noneOf(enumClass); final EnumSet<E> results = EnumSet.noneOf(enumClass);
for (E constant : constants) { for (E constant : constants) {
if ((value & (1 << constant.ordinal())) != 0) { if ((value & 1 << constant.ordinal()) != 0) {
results.add(constant); results.add(constant);
} }
} }

View File

@ -152,7 +152,7 @@ public static boolean equals(Object object1, Object object2) {
if (object1 == object2) { if (object1 == object2) {
return true; return true;
} }
if ((object1 == null) || (object2 == null)) { if (object1 == null || object2 == null) {
return false; return false;
} }
return object1.equals(object2); return object1.equals(object2);
@ -196,7 +196,7 @@ public static boolean notEqual(Object object1, Object object2) {
*/ */
public static int hashCode(Object obj) { public static int hashCode(Object obj) {
// hashCode(Object) retained for performance, as hash code is often critical // 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 static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean
if (c1 == c2) { if (c1 == c2) {
return 0; return 0;
} else if (c1 == null) { } else if (c1 == null) {
return (nullGreater ? 1 : -1); return nullGreater ? 1 : -1;
} else if (c2 == null) { } else if (c2 == null) {
return (nullGreater ? -1 : 1); return nullGreater ? -1 : 1;
} }
return c1.compareTo(c2); return c1.compareTo(c2);
} }

View File

@ -227,7 +227,7 @@ public static String random(int count, int start, int end, boolean letters, bool
} else if (count < 0) { } else if (count < 0) {
throw new IllegalArgumentException("Requested random string length " + count + " is less than 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; end = 'z' + 1;
start = ' '; start = ' ';
if (!letters && !numbers) { if (!letters && !numbers) {
@ -246,9 +246,9 @@ public static String random(int count, int start, int end, boolean letters, bool
} else { } else {
ch = chars[random.nextInt(gap) + start]; ch = chars[random.nextInt(gap) + start];
} }
if ((letters && Character.isLetter(ch)) if (letters && Character.isLetter(ch)
|| (numbers && Character.isDigit(ch)) || numbers && Character.isDigit(ch)
|| (!letters && !numbers)) { || !letters && !numbers) {
if(ch >= 56320 && ch <= 57343) { if(ch >= 56320 && ch <= 57343) {
if(count == 0) { if(count == 0) {
count++; count++;

View File

@ -219,7 +219,7 @@ public boolean contains(T element) {
if (element == null) { if (element == null) {
return false; return false;
} }
return (comparator.compare(element, minimum) > -1) && (comparator.compare(element, maximum) < 1); return comparator.compare(element, minimum) > -1 && comparator.compare(element, maximum) < 1;
} }
/** /**

View File

@ -225,7 +225,7 @@ public static boolean isBlank(CharSequence cs) {
return true; return true;
} }
for (int i = 0; i < strLen; i++) { for (int i = 0; i < strLen; i++) {
if ((Character.isWhitespace(cs.charAt(i)) == false)) { if (Character.isWhitespace(cs.charAt(i)) == false) {
return false; return false;
} }
} }
@ -484,13 +484,13 @@ public static String stripStart(String str, String stripChars) {
} }
int start = 0; int start = 0;
if (stripChars == null) { if (stripChars == null) {
while ((start != strLen) && Character.isWhitespace(str.charAt(start))) { while (start != strLen && Character.isWhitespace(str.charAt(start))) {
start++; start++;
} }
} else if (stripChars.length() == 0) { } else if (stripChars.length() == 0) {
return str; return str;
} else { } else {
while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND)) { while (start != strLen && stripChars.indexOf(str.charAt(start)) != INDEX_NOT_FOUND) {
start++; start++;
} }
} }
@ -529,13 +529,13 @@ public static String stripEnd(String str, String stripChars) {
} }
if (stripChars == null) { if (stripChars == null) {
while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { while (end != 0 && Character.isWhitespace(str.charAt(end - 1))) {
end--; end--;
} }
} else if (stripChars.length() == 0) { } else if (stripChars.length() == 0) {
return str; return str;
} else { } 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--; end--;
} }
} }
@ -1087,7 +1087,7 @@ public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, in
if (startPos < 0) { if (startPos < 0) {
startPos = 0; startPos = 0;
} }
int endLimit = (str.length() - searchStr.length()) + 1; int endLimit = str.length() - searchStr.length() + 1;
if (startPos > endLimit) { if (startPos > endLimit) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
@ -1333,7 +1333,7 @@ public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr
if (str == null || searchStr == null) { if (str == null || searchStr == null) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
if (startPos > (str.length() - searchStr.length())) { if (startPos > str.length() - searchStr.length()) {
startPos = str.length() - searchStr.length(); startPos = str.length() - searchStr.length();
} }
if (startPos < 0) { if (startPos < 0) {
@ -1946,7 +1946,7 @@ public static int indexOfAny(CharSequence str, CharSequence... searchStrs) {
} }
} }
return (ret == Integer.MAX_VALUE) ? INDEX_NOT_FOUND : ret; return ret == Integer.MAX_VALUE ? INDEX_NOT_FOUND : ret;
} }
/** /**
@ -2212,7 +2212,7 @@ public static String mid(String str, int pos, int len) {
if (pos < 0) { if (pos < 0) {
pos = 0; pos = 0;
} }
if (str.length() <= (pos + len)) { if (str.length() <= pos + len) {
return str.substring(pos); return str.substring(pos);
} }
return str.substring(pos, pos + len); return str.substring(pos, pos + len);
@ -2378,7 +2378,7 @@ public static String substringAfterLast(String str, String separator) {
return EMPTY; return EMPTY;
} }
int pos = str.lastIndexOf(separator); 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 EMPTY;
} }
return str.substring(pos + separator.length()); return str.substring(pos + separator.length());
@ -2486,7 +2486,7 @@ public static String[] substringsBetween(String str, String open, String close)
int openLen = open.length(); int openLen = open.length();
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
int pos = 0; int pos = 0;
while (pos < (strLen - closeLen)) { while (pos < strLen - closeLen) {
int start = str.indexOf(open, pos); int start = str.indexOf(open, pos);
if (start < 0) { if (start < 0) {
break; break;
@ -2773,7 +2773,7 @@ private static String[] splitByWholeSeparatorWorker(
return ArrayUtils.EMPTY_STRING_ARRAY; return ArrayUtils.EMPTY_STRING_ARRAY;
} }
if ((separator == null) || (EMPTY.equals(separator))) { if (separator == null || EMPTY.equals(separator)) {
// Split on whitespace. // Split on whitespace.
return splitWorker(str, null, max, preserveAllTokens); return splitWorker(str, null, max, preserveAllTokens);
} }
@ -2932,7 +2932,7 @@ private static String[] splitWorker(String str, char separatorChar, boolean pres
match = true; match = true;
i++; i++;
} }
if (match || (preserveAllTokens && lastMatch)) { if (match || preserveAllTokens && lastMatch) {
list.add(str.substring(start, i)); list.add(str.substring(start, i));
} }
return list.toArray(new String[list.size()]); return list.toArray(new String[list.size()]);
@ -3108,7 +3108,7 @@ private static String[] splitWorker(String str, String separatorChars, int max,
i++; i++;
} }
} }
if (match || (preserveAllTokens && lastMatch)) { if (match || preserveAllTokens && lastMatch) {
list.add(str.substring(start, i)); list.add(str.substring(start, i));
} }
return list.toArray(new String[list.size()]); return list.toArray(new String[list.size()]);
@ -3299,7 +3299,7 @@ public static String join(Object[] array, char separator, int startIndex, int en
if (array == null) { if (array == null) {
return null; return null;
} }
int noOfItems = (endIndex - startIndex); int noOfItems = endIndex - startIndex;
if (noOfItems <= 0) { if (noOfItems <= 0) {
return EMPTY; return EMPTY;
} }
@ -3384,7 +3384,7 @@ public static String join(Object[] array, String separator, int startIndex, int
// endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator)) // endIndex - startIndex > 0: Len = NofStrings *(len(firstString) + len(separator))
// (Assuming that all Strings are roughly equally long) // (Assuming that all Strings are roughly equally long)
int noOfItems = (endIndex - startIndex); int noOfItems = endIndex - startIndex;
if (noOfItems <= 0) { if (noOfItems <= 0) {
return EMPTY; return EMPTY;
} }
@ -3867,8 +3867,8 @@ public static String replace(String text, String searchString, String replacemen
} }
int replLength = searchString.length(); int replLength = searchString.length();
int increase = replacement.length() - replLength; int increase = replacement.length() - replLength;
increase = (increase < 0 ? 0 : increase); increase = increase < 0 ? 0 : increase;
increase *= (max < 0 ? 16 : (max > 64 ? 64 : max)); increase *= max < 0 ? 16 : max > 64 ? 64 : max;
StringBuilder buf = new StringBuilder(text.length() + increase); StringBuilder buf = new StringBuilder(text.length() + increase);
while (end != INDEX_NOT_FOUND) { while (end != INDEX_NOT_FOUND) {
buf.append(text.substring(start, end)).append(replacement); buf.append(text.substring(start, end)).append(replacement);
@ -5214,7 +5214,7 @@ public static boolean isAlphaSpace(CharSequence cs) {
} }
int sz = cs.length(); int sz = cs.length();
for (int i = 0; i < sz; i++) { 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; return false;
} }
} }
@ -5284,7 +5284,7 @@ public static boolean isAlphanumericSpace(CharSequence cs) {
} }
int sz = cs.length(); int sz = cs.length();
for (int i = 0; i < sz; i++) { 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; return false;
} }
} }
@ -5396,7 +5396,7 @@ public static boolean isNumericSpace(CharSequence cs) {
} }
int sz = cs.length(); int sz = cs.length();
for (int i = 0; i < sz; i++) { 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; return false;
} }
} }
@ -5429,7 +5429,7 @@ public static boolean isWhitespace(CharSequence cs) {
} }
int sz = cs.length(); int sz = cs.length();
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
if ((Character.isWhitespace(cs.charAt(i)) == false)) { if (Character.isWhitespace(cs.charAt(i)) == false) {
return false; return false;
} }
} }
@ -5726,7 +5726,7 @@ public static String abbreviate(String str, int offset, int maxWidth) {
if (offset > str.length()) { if (offset > str.length()) {
offset = str.length(); offset = str.length();
} }
if ((str.length() - offset) < (maxWidth - 3)) { if (str.length() - offset < maxWidth - 3) {
offset = str.length() - (maxWidth - 3); offset = str.length() - (maxWidth - 3);
} }
final String abrevMarker = "..."; final String abrevMarker = "...";
@ -5736,7 +5736,7 @@ public static String abbreviate(String str, int offset, int maxWidth) {
if (maxWidth < 7) { if (maxWidth < 7) {
throw new IllegalArgumentException("Minimum abbreviation width with offset is 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 + abbreviate(str.substring(offset), maxWidth - 3);
} }
return abrevMarker + str.substring(str.length() - (maxWidth - 3)); return abrevMarker + str.substring(str.length() - (maxWidth - 3));
@ -5776,7 +5776,7 @@ public static String abbreviateMiddle(String str, String middle, int length) {
return str; return str;
} }
if (length >= str.length() || length < (middle.length()+2)) { if (length >= str.length() || length < middle.length()+2) {
return str; return str;
} }
@ -5934,7 +5934,7 @@ public static int indexOfDifference(CharSequence... css) {
} }
// handle lists containing all nulls or all empty strings // handle lists containing all nulls or all empty strings
if (allStringsNull || (longestStrLen == 0 && !anyStringNull)) { if (allStringsNull || longestStrLen == 0 && !anyStringNull) {
return INDEX_NOT_FOUND; return INDEX_NOT_FOUND;
} }
@ -6365,7 +6365,7 @@ public static boolean startsWithIgnoreCase(CharSequence str, CharSequence prefix
*/ */
private static boolean startsWith(CharSequence str, CharSequence prefix, boolean ignoreCase) { private static boolean startsWith(CharSequence str, CharSequence prefix, boolean ignoreCase) {
if (str == null || prefix == null) { if (str == null || prefix == null) {
return (str == null && prefix == null); return str == null && prefix == null;
} }
if (prefix.length() > str.length()) { if (prefix.length() > str.length()) {
return false; return false;

View File

@ -181,7 +181,7 @@ private static void throwCause(ExecutionException ex) {
*/ */
public static <T> T initialize(ConcurrentInitializer<T> initializer) public static <T> T initialize(ConcurrentInitializer<T> initializer)
throws ConcurrentException { throws ConcurrentException {
return (initializer != null) ? initializer.get() : null; return initializer != null ? initializer.get() : null;
} }
/** /**
@ -244,7 +244,7 @@ public static <K, V> V putIfAbsent(ConcurrentMap<K, V> map, K key, V value) {
} }
V result = map.putIfAbsent(key, value); V result = map.putIfAbsent(key, value);
return (result != null) ? result : value; return result != null ? result : value;
} }
/** /**

View File

@ -88,7 +88,7 @@ public T get() throws ConcurrentException {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return (getObject() != null) ? getObject().hashCode() : 0; return getObject() != null ? getObject().hashCode() : 0;
} }
/** /**

View File

@ -358,7 +358,7 @@ public synchronized int getAvailablePermits() {
* unit * unit
*/ */
public synchronized double getAverageCallsPerPeriod() { public synchronized double getAverageCallsPerPeriod() {
return (periodCount == 0) ? 0 : (double) totalAcquireCount return periodCount == 0 ? 0 : (double) totalAcquireCount
/ (double) periodCount; / (double) periodCount;
} }

View File

@ -178,7 +178,7 @@ public static Throwable getCause(Throwable throwable, String[] methodNames) {
*/ */
public static Throwable getRootCause(Throwable throwable) { public static Throwable getRootCause(Throwable throwable) {
List<Throwable> list = getThrowableList(throwable); List<Throwable> 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 static String getMessage(Throwable th) {
*/ */
public static String getRootCauseMessage(Throwable th) { public static String getRootCauseMessage(Throwable th) {
Throwable root = ExceptionUtils.getRootCause(th); Throwable root = ExceptionUtils.getRootCause(th);
root = (root == null ? th : root); root = root == null ? th : root;
return getMessage(root); return getMessage(root);
} }

View File

@ -247,7 +247,7 @@ public static Fraction getReducedFraction(int numerator, int denominator) {
* @throws ArithmeticException if the the algorithm does not converge * @throws ArithmeticException if the the algorithm does not converge
*/ */
public static Fraction getFraction(double value) { public static Fraction getFraction(double value) {
int sign = (value < 0 ? -1 : 1); int sign = value < 0 ? -1 : 1;
value = Math.abs(value); value = Math.abs(value);
if (value > Integer.MAX_VALUE || Double.isNaN(value)) { if (value > Integer.MAX_VALUE || Double.isNaN(value)) {
throw new ArithmeticException throw new ArithmeticException
@ -291,7 +291,7 @@ public static Fraction getFraction(double value) {
denom1 = denom2; denom1 = denom2;
i++; i++;
// System.out.println(">>" + delta1 +" "+ delta2+" "+(delta1 > delta2)+" "+i+" "+denom2); // 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) { if (i == 25) {
throw new ArithmeticException("Unable to convert double to fraction"); throw new ArithmeticException("Unable to convert double to fraction");
} }
@ -440,7 +440,7 @@ public long longValue() {
*/ */
@Override @Override
public float floatValue() { public float floatValue() {
return ((float) numerator) / ((float) denominator); return (float) numerator / (float) denominator;
} }
/** /**
@ -451,7 +451,7 @@ public float floatValue() {
*/ */
@Override @Override
public double doubleValue() { public double doubleValue() {
return ((double) numerator) / ((double) denominator); return (double) numerator / (double) denominator;
} }
// Calculations // Calculations
@ -555,7 +555,7 @@ public Fraction pow(int power) {
return this.invert().pow(-power); return this.invert().pow(-power);
} else { } else {
Fraction f = this.multiplyBy(this); Fraction f = this.multiplyBy(this);
if ((power % 2) == 0) { // if even... if (power % 2 == 0) { // if even...
return f.pow(power/2); return f.pow(power/2);
} else { // if odd... } else { // if odd...
return f.pow(power/2).multiplyBy(this); return f.pow(power/2).multiplyBy(this);
@ -575,8 +575,8 @@ public Fraction pow(int power) {
*/ */
private static int greatestCommonDivisor(int u, int v) { private static int greatestCommonDivisor(int u, int v) {
// From Commons Math: // From Commons Math:
if ((u == 0) || (v == 0)) { if (u == 0 || v == 0) {
if ((u == Integer.MIN_VALUE) || (v == Integer.MIN_VALUE)) { if (u == Integer.MIN_VALUE || v == Integer.MIN_VALUE) {
throw new ArithmeticException("overflow: gcd is 2^31"); throw new ArithmeticException("overflow: gcd is 2^31");
} }
return Math.abs(u) + Math.abs(v); return Math.abs(u) + Math.abs(v);
@ -601,7 +601,7 @@ private static int greatestCommonDivisor(int u, int v) {
} }
// B2. Initialize: u and v have been divided by 2^k and at least // B2. Initialize: u and v have been divided by 2^k and at least
// one is odd. // 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 negative: u was odd, v may be even (t replaces v)
// t positive: u was even, v is odd (t replaces u) // t positive: u was even, v is odd (t replaces u)
do { do {
@ -637,7 +637,7 @@ private static int greatestCommonDivisor(int u, int v) {
* an int * an int
*/ */
private static int mulAndCheck(int x, int y) { 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 || if (m < Integer.MIN_VALUE ||
m > Integer.MAX_VALUE) { m > Integer.MAX_VALUE) {
throw new ArithmeticException("overflow: mul"); throw new ArithmeticException("overflow: mul");
@ -656,7 +656,7 @@ private static int mulAndCheck(int x, int y) {
*/ */
private static int mulPosAndCheck(int x, int y) { private static int mulPosAndCheck(int x, int y) {
/* assert x>=0 && y>=0; */ /* assert x>=0 && y>=0; */
long m = ((long)x)*((long)y); long m = (long)x*(long)y;
if (m > Integer.MAX_VALUE) { if (m > Integer.MAX_VALUE) {
throw new ArithmeticException("overflow: mulPos"); throw new ArithmeticException("overflow: mulPos");
} }
@ -770,7 +770,7 @@ private Fraction addSub(Fraction fraction, boolean isAdd) {
// but d2 doesn't need extra precision because // but d2 doesn't need extra precision because
// d2 = gcd(t,d1) = gcd(t mod d1, d1) // d2 = gcd(t,d1) = gcd(t mod d1, d1)
int tmodd1 = t.mod(BigInteger.valueOf(d1)).intValue(); 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) // result is (t/d2) / (u'/d1)(v'/d2)
BigInteger w = t.divide(BigInteger.valueOf(d2)); BigInteger w = t.divide(BigInteger.valueOf(d2));
@ -849,8 +849,8 @@ public boolean equals(Object obj) {
return false; return false;
} }
Fraction other = (Fraction) obj; Fraction other = (Fraction) obj;
return (getNumerator() == other.getNumerator() && return getNumerator() == other.getNumerator() &&
getDenominator() == other.getDenominator()); getDenominator() == other.getDenominator();
} }
/** /**

View File

@ -271,8 +271,8 @@ public Double toDouble() {
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return (obj instanceof MutableDouble) return obj instanceof MutableDouble
&& (Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value)); && Double.doubleToLongBits(((MutableDouble) obj).value) == Double.doubleToLongBits(value);
} }
/** /**
@ -283,7 +283,7 @@ public boolean equals(Object obj) {
@Override @Override
public int hashCode() { public int hashCode() {
long bits = Double.doubleToLongBits(value); long bits = Double.doubleToLongBits(value);
return (int) (bits ^ (bits >>> 32)); return (int) (bits ^ bits >>> 32);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -273,8 +273,8 @@ public Float toFloat() {
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return (obj instanceof MutableFloat) return obj instanceof MutableFloat
&& (Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value)); && Float.floatToIntBits(((MutableFloat) obj).value) == Float.floatToIntBits(value);
} }
/** /**

View File

@ -580,7 +580,7 @@ private int substitute(StrBuilder buf, int offset, int length, List<String> prio
StrMatcher suffixMatcher = getVariableSuffixMatcher(); StrMatcher suffixMatcher = getVariableSuffixMatcher();
char escape = getEscapeChar(); char escape = getEscapeChar();
boolean top = (priorVariables == null); boolean top = priorVariables == null;
boolean altered = false; boolean altered = false;
int lengthChange = 0; int lengthChange = 0;
char[] chars = buf.buffer; char[] chars = buf.buffer;
@ -656,7 +656,7 @@ private int substitute(StrBuilder buf, int offset, int length, List<String> prio
int change = substitute(buf, startPos, int change = substitute(buf, startPos,
varLen, priorVariables); varLen, priorVariables);
change = change change = change
+ (varLen - (endPos - startPos)); + varLen - (endPos - startPos);
pos += change; pos += change;
bufEnd += change; bufEnd += change;
lengthChange += change; lengthChange += change;
@ -678,7 +678,7 @@ private int substitute(StrBuilder buf, int offset, int length, List<String> prio
} }
} }
if (top) { if (top) {
return (altered ? 1 : 0); return altered ? 1 : 0;
} }
return lengthChange; return lengthChange;
} }

View File

@ -728,7 +728,7 @@ private int readWithQuotes(char[] chars, int start, int len, StrBuilder workArea
// string or the end of the input // string or the end of the input
workArea.clear(); workArea.clear();
int pos = start; int pos = start;
boolean quoting = (quoteLen > 0); boolean quoting = quoteLen > 0;
int trimStart = 0; int trimStart = 0;
while (pos < len) { while (pos < len) {
@ -746,7 +746,7 @@ private int readWithQuotes(char[] chars, int start, int len, StrBuilder workArea
if (isQuote(chars, pos + quoteLen, len, quoteStart, quoteLen)) { if (isQuote(chars, pos + quoteLen, len, quoteStart, quoteLen)) {
// matched pair of quotes, thus an escaped quote // matched pair of quotes, thus an escaped quote
workArea.append(chars, pos, quoteLen); workArea.append(chars, pos, quoteLen);
pos += (quoteLen * 2); pos += quoteLen * 2;
trimStart = workArea.size(); trimStart = workArea.size();
continue; continue;
} }
@ -820,7 +820,7 @@ private int readWithQuotes(char[] chars, int start, int len, StrBuilder workArea
*/ */
private boolean isQuote(char[] chars, int pos, int len, int quoteStart, int quoteLen) { private boolean isQuote(char[] chars, int pos, int len, int quoteStart, int quoteLen) {
for (int i = 0; i < quoteLen; i++) { 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; return false;
} }
} }

View File

@ -99,7 +99,7 @@ public static String wrap(String str, int wrapLength, String newLineStr, boolean
int offset = 0; int offset = 0;
StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32);
while ((inputLineLength - offset) > wrapLength) { while (inputLineLength - offset > wrapLength) {
if (str.charAt(offset) == ' ') { if (str.charAt(offset) == ' ') {
offset++; offset++;
continue; continue;
@ -267,7 +267,7 @@ public static String capitalizeFully(String str) {
* @since 2.1 * @since 2.1
*/ */
public static String capitalizeFully(String str, char... delimiters) { 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) { if (StringUtils.isEmpty(str) || delimLen == 0) {
return str; return str;
} }
@ -323,7 +323,7 @@ public static String uncapitalize(String str) {
* @since 2.1 * @since 2.1
*/ */
public static String uncapitalize(String str, char... delimiters) { 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) { if (StringUtils.isEmpty(str) || delimLen == 0) {
return str; return str;
} }

View File

@ -68,7 +68,7 @@ public NumericEntityUnescaper(OPTION... options) {
* @return whether the option is set * @return whether the option is set
*/ */
public boolean isSet(OPTION option) { public boolean isSet(OPTION option) {
return (options == null) ? false : options.contains(option); return options == null ? false : options.contains(option);
} }
/** /**
@ -95,14 +95,14 @@ public int translate(CharSequence input, int index, Writer out) throws IOExcepti
int end = start; int end = start;
// Note that this supports character codes without a ; on the end // Note that this supports character codes without a ; on the end
while(end < seqEnd && ( (input.charAt(end) >= '0' && input.charAt(end) <= '9') || 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' ||
(input.charAt(end) >= 'A' && input.charAt(end) <= 'F') ) ) input.charAt(end) >= 'A' && input.charAt(end) <= 'F' ) )
{ {
end++; end++;
} }
boolean semiNext = (end != seqEnd) && (input.charAt(end) == ';'); boolean semiNext = end != seqEnd && input.charAt(end) == ';';
if(!semiNext) { if(!semiNext) {
if(isSet(OPTION.semiColonRequired)) { if(isSet(OPTION.semiColonRequired)) {
@ -132,7 +132,7 @@ public int translate(CharSequence input, int index, Writer out) throws IOExcepti
out.write(entityValue); 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; return 0;
} }

View File

@ -34,18 +34,18 @@ public class UnicodeUnescaper extends CharSequenceTranslator {
*/ */
@Override @Override
public int translate(CharSequence input, int index, Writer out) throws IOException { 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 // consume optional additional 'u' chars
int i = 2; int i = 2;
while ((index + i < input.length()) && input.charAt(index + i) == 'u') { while (index + i < input.length() && input.charAt(index + i) == 'u') {
i++; i++;
} }
if ((index + i < input.length()) && (input.charAt(index + i) == '+')) { if (index + i < input.length() && input.charAt(index + i) == '+') {
i++; i++;
} }
if ((index + i + 4 <= input.length())) { if (index + i + 4 <= input.length()) {
// Get 4 hex digits // Get 4 hex digits
CharSequence unicode = input.subSequence(index + i, index + i + 4); CharSequence unicode = input.subSequence(index + i, index + i + 4);

View File

@ -248,7 +248,7 @@ public void resume() {
if (this.runningState != STATE_SUSPENDED) { if (this.runningState != STATE_SUSPENDED) {
throw new IllegalStateException("Stopwatch must be suspended to resume. "); 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; this.runningState = STATE_RUNNING;
} }

View File

@ -197,33 +197,33 @@ public void testAddObjectArrayObject() {
//show that not casting is okay //show that not casting is okay
newArray = ArrayUtils.add((Object[])null, "a"); newArray = ArrayUtils.add((Object[])null, "a");
assertTrue(Arrays.equals((new String[]{"a"}), newArray)); assertTrue(Arrays.equals(new String[]{"a"}, newArray));
assertTrue(Arrays.equals((new Object[]{"a"}), newArray)); assertTrue(Arrays.equals(new Object[]{"a"}, newArray));
assertEquals(String.class, newArray.getClass().getComponentType()); assertEquals(String.class, newArray.getClass().getComponentType());
//show that not casting to Object[] is okay and will assume String based on "a" //show that not casting to Object[] is okay and will assume String based on "a"
String[] newStringArray = ArrayUtils.add(null, "a"); String[] newStringArray = ArrayUtils.add(null, "a");
assertTrue(Arrays.equals((new String[]{"a"}), newStringArray)); assertTrue(Arrays.equals(new String[]{"a"}, newStringArray));
assertTrue(Arrays.equals((new Object[]{"a"}), newStringArray)); assertTrue(Arrays.equals(new Object[]{"a"}, newStringArray));
assertEquals(String.class, newStringArray.getClass().getComponentType()); assertEquals(String.class, newStringArray.getClass().getComponentType());
String[] stringArray1 = new String[]{"a", "b", "c"}; String[] stringArray1 = new String[]{"a", "b", "c"};
newArray = ArrayUtils.add(stringArray1, null); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.add(stringArray1, "d"); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
Number[] numberArray1 = new Number[]{Integer.valueOf(1), Double.valueOf(2)}; Number[] numberArray1 = new Number[]{Integer.valueOf(1), Double.valueOf(2)};
newArray = ArrayUtils.add(numberArray1, Float.valueOf(3)); 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()); assertEquals(Number.class, newArray.getClass().getComponentType());
numberArray1 = null; numberArray1 = null;
newArray = ArrayUtils.add(numberArray1, Float.valueOf(3)); 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()); assertEquals(Float.class, newArray.getClass().getComponentType());
} }
@ -256,31 +256,31 @@ public void testAddObjectArrayToObjectArray() {
newArray = ArrayUtils.addAll(stringArray1, (String[]) null); newArray = ArrayUtils.addAll(stringArray1, (String[]) null);
assertNotSame(stringArray1, newArray); assertNotSame(stringArray1, newArray);
assertTrue(Arrays.equals(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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.addAll(null, stringArray2); newArray = ArrayUtils.addAll(null, stringArray2);
assertNotSame(stringArray2, newArray); assertNotSame(stringArray2, newArray);
assertTrue(Arrays.equals(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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.addAll(stringArray1, stringArray2); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, (String[]) null); newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, (String[]) null);
assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.addAll(null, ArrayUtils.EMPTY_STRING_ARRAY); newArray = ArrayUtils.addAll(null, ArrayUtils.EMPTY_STRING_ARRAY);
assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.EMPTY_STRING_ARRAY); newArray = ArrayUtils.addAll(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.EMPTY_STRING_ARRAY);
assertTrue(Arrays.equals(ArrayUtils.EMPTY_STRING_ARRAY, newArray)); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
String[] stringArrayNull = new String []{null}; String[] stringArrayNull = new String []{null};
newArray = ArrayUtils.addAll(stringArrayNull, stringArrayNull); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
// boolean // boolean
@ -369,21 +369,21 @@ public void testAddObjectArrayToObjectArray() {
public void testAddObjectAtIndex() { public void testAddObjectAtIndex() {
Object[] newArray; Object[] newArray;
newArray = ArrayUtils.add((Object[])null, 0, "a"); newArray = ArrayUtils.add((Object[])null, 0, "a");
assertTrue(Arrays.equals((new String[]{"a"}), newArray)); assertTrue(Arrays.equals(new String[]{"a"}, newArray));
assertTrue(Arrays.equals((new Object[]{"a"}), newArray)); assertTrue(Arrays.equals(new Object[]{"a"}, newArray));
assertEquals(String.class, newArray.getClass().getComponentType()); assertEquals(String.class, newArray.getClass().getComponentType());
String[] stringArray1 = new String[]{"a", "b", "c"}; String[] stringArray1 = new String[]{"a", "b", "c"};
newArray = ArrayUtils.add(stringArray1, 0, null); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.add(stringArray1, 1, null); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.add(stringArray1, 3, null); 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()); assertEquals(String.class, newArray.getClass().getComponentType());
newArray = ArrayUtils.add(stringArray1, 3, "d"); 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());
assertEquals(String.class, newArray.getClass().getComponentType()); assertEquals(String.class, newArray.getClass().getComponentType());

View File

@ -149,7 +149,7 @@ public void testSetShortValue() {
} }
for (int j = 0; j < 128; j++) { for (int j = 0; j < 128; j++) {
assertEquals(bf_zero.getShortValue(bf_zero.setShortValue((short) 0, (short) j)), (short) 0); 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 // verify that excess bits are stripped off

View File

@ -148,7 +148,7 @@ private int run_inlined_CharUtils_isAsciiNumeric(int loopCount) {
int t = 0; int t = 0;
for (int i = 0; i < loopCount; i++) { for (int i = 0; i < loopCount; i++) {
for (char ch : CHAR_SAMPLES) { for (char ch : CHAR_SAMPLES) {
boolean b = (ch >= '0' && ch <= '9'); boolean b = ch >= '0' && ch <= '9';
t += b ? 1 : 0; t += b ? 1 : 0;
} }
} }

View File

@ -286,7 +286,7 @@ private double chiSquare(int[] expected, int[] observed) {
double sumSq = 0.0d; double sumSq = 0.0d;
double dev = 0.0d; double dev = 0.0d;
for (int i = 0; i < observed.length; i++) { for (int i = 0; i < observed.length; i++) {
dev = (observed[i] - expected[i]); dev = observed[i] - expected[i];
sumSq += dev * dev / expected[i]; sumSq += dev * dev / expected[i];
} }
return sumSq; return sumSq;
@ -311,8 +311,8 @@ public void testLang100() throws Exception {
for (int i=0; i < orig.length() && i < copy.length(); i++) { for (int i=0; i < orig.length() && i < copy.length(); i++) {
char o = orig.charAt(i); char o = orig.charAt(i);
char c = copy.charAt(i); char c = copy.charAt(i);
assertEquals("differs at " + i + "(" + Integer.toHexString((new Character(o)).hashCode()) + "," + assertEquals("differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," +
Integer.toHexString((new Character(c)).hashCode()) + ")", o, c); Integer.toHexString(new Character(c).hashCode()) + ")", o, c);
} }
// compare length also // compare length also
assertEquals(orig.length(), copy.length()); assertEquals(orig.length(), copy.length());

View File

@ -46,7 +46,7 @@ public boolean equals(Object o) {
return false; return false;
} }
TestObject rhs = (TestObject) o; TestObject rhs = (TestObject) o;
return (a == rhs.a); return a == rhs.a;
} }
public void setA(int a) { public void setA(int a) {
@ -57,7 +57,7 @@ public int getA() {
return a; return a;
} }
public int compareTo(TestObject rhs) { 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 boolean equals(Object o) {
return false; return false;
} }
TestSubObject rhs = (TestSubObject) o; TestSubObject rhs = (TestSubObject) o;
return super.equals(o) && (b == rhs.b); return super.equals(o) && b == rhs.b;
} }
} }
@ -231,7 +231,7 @@ private void assertReflectionCompareContract(Object x, Object y, Object z, boole
} }
// strongly recommended but not strictly required // 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 void testMultiFloatArray() {
float[][] array3 = new float[2][3]; float[][] array3 = new float[2][3];
for (int i = 0; i < array1.length; ++i) { for (int i = 0; i < array1.length; ++i) {
for (int j = 0; j < array1[0].length; j++) { for (int j = 0; j < array1[0].length; j++) {
array1[i][j] = ((i + 1) * (j + 1)); array1[i][j] = (i + 1) * (j + 1);
array2[i][j] = ((i + 1) * (j + 1)); array2[i][j] = (i + 1) * (j + 1);
array3[i][j] = ((i + 1) * (j + 1)); array3[i][j] = (i + 1) * (j + 1);
} }
} }
array3[1][2] = 100; array3[1][2] = 100;
@ -847,9 +847,9 @@ public void testMultiDoubleArray() {
double[][] array3 = new double[2][3]; double[][] array3 = new double[2][3];
for (int i = 0; i < array1.length; ++i) { for (int i = 0; i < array1.length; ++i) {
for (int j = 0; j < array1[0].length; j++) { for (int j = 0; j < array1[0].length; j++) {
array1[i][j] = ((i + 1) * (j + 1)); array1[i][j] = (i + 1) * (j + 1);
array2[i][j] = ((i + 1) * (j + 1)); array2[i][j] = (i + 1) * (j + 1);
array3[i][j] = ((i + 1) * (j + 1)); array3[i][j] = (i + 1) * (j + 1);
} }
} }
array3[1][2] = 100; array3[1][2] = 100;
@ -871,9 +871,9 @@ public void testMultiBooleanArray() {
boolean[][] array3 = new boolean[2][3]; boolean[][] array3 = new boolean[2][3];
for (int i = 0; i < array1.length; ++i) { for (int i = 0; i < array1.length; ++i) {
for (int j = 0; j < array1[0].length; j++) { for (int j = 0; j < array1[0].length; j++) {
array1[i][j] = ((i == 1) ^ (j == 1)); array1[i][j] = i == 1 ^ j == 1;
array2[i][j] = ((i == 1) ^ (j == 1)); array2[i][j] = i == 1 ^ j == 1;
array3[i][j] = ((i == 1) ^ (j == 1)); array3[i][j] = i == 1 ^ j == 1;
} }
} }
array3[1][2] = false; array3[1][2] = false;

View File

@ -50,7 +50,7 @@ public boolean equals(Object o) {
} }
TestObject rhs = (TestObject) o; TestObject rhs = (TestObject) o;
return (a == rhs.a); return a == rhs.a;
} }
public void setA(int a) { public void setA(int a) {
@ -80,7 +80,7 @@ public boolean equals(Object o) {
} }
TestSubObject rhs = (TestSubObject) o; TestSubObject rhs = (TestSubObject) o;
return super.equals(o) && (b == rhs.b); return super.equals(o) && b == rhs.b;
} }
public void setB(int b) { public void setB(int b) {
@ -712,8 +712,8 @@ public void testMultiBooleanArray() {
boolean[][] array2 = new boolean[2][2]; boolean[][] array2 = new boolean[2][2];
for (int i = 0; i < array1.length; ++i) { for (int i = 0; i < array1.length; ++i) {
for (int j = 0; j < array1[0].length; j++) { for (int j = 0; j < array1[0].length; j++) {
array1[i][j] = (i == 1) || (j == 1); array1[i][j] = i == 1 || j == 1;
array2[i][j] = (i == 1) || (j == 1); array2[i][j] = i == 1 || j == 1;
} }
} }
assertTrue(new EqualsBuilder().append(array1, array1).isEquals()); assertTrue(new EqualsBuilder().append(array1, array1).isEquals());

View File

@ -94,7 +94,7 @@ public boolean equals(Object o) {
return false; return false;
} }
TestObject rhs = (TestObject) o; TestObject rhs = (TestObject) o;
return (a == rhs.a); return a == rhs.a;
} }
public void setA(int a) { public void setA(int a) {
@ -131,7 +131,7 @@ public boolean equals(Object o) {
return false; return false;
} }
TestSubObject rhs = (TestSubObject) o; TestSubObject rhs = (TestSubObject) o;
return super.equals(o) && (b == rhs.b); return super.equals(o) && b == rhs.b;
} }
} }
@ -204,7 +204,7 @@ public void testReflectionHashCodeEx3() {
@Test @Test
public void testSuper() { public void testSuper() {
Object obj = new Object(); 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()); new HashCodeBuilder(19, 41).append(obj).toHashCode()).toHashCode());
} }
@ -228,7 +228,7 @@ public void testObjectBuild() {
@SuppressWarnings("cast") // cast is not really needed, keep for consistency @SuppressWarnings("cast") // cast is not really needed, keep for consistency
public void testLong() { public void testLong() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long) 0L).toHashCode()); 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()); (long) 123456789L).toHashCode());
} }
@ -263,7 +263,7 @@ public void testDouble() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double) 0d).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double) 0d).toHashCode());
double d = 1234567.89; double d = 1234567.89;
long l = Double.doubleToLongBits(d); 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 @Test
@ -285,7 +285,7 @@ public void testBoolean() {
public void testObjectArray() { public void testObjectArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((Object[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((Object[]) null).toHashCode());
Object[] obj = new Object[2]; 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(); obj[0] = new Object();
assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = new Object(); obj[1] = new Object();
@ -296,7 +296,7 @@ public void testObjectArray() {
@Test @Test
public void testObjectArrayAsObject() { public void testObjectArrayAsObject() {
Object[] obj = new Object[2]; 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(); obj[0] = new Object();
assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + obj[0].hashCode()) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = new Object(); obj[1] = new Object();
@ -308,24 +308,24 @@ public void testObjectArrayAsObject() {
public void testLongArray() { public void testLongArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((long[]) null).toHashCode());
long[] obj = new long[2]; 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; 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()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = 6L; 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()); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode());
} }
@Test @Test
public void testLongArrayAsObject() { public void testLongArrayAsObject() {
long[] obj = new long[2]; 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; 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()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = 6L; 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()); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
} }
@ -333,7 +333,7 @@ public void testLongArrayAsObject() {
public void testIntArray() { public void testIntArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((int[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((int[]) null).toHashCode());
int[] obj = new int[2]; 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; obj[0] = 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = 6; obj[1] = 6;
@ -343,7 +343,7 @@ public void testIntArray() {
@Test @Test
public void testIntArrayAsObject() { public void testIntArrayAsObject() {
int[] obj = new int[2]; 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; obj[0] = 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = 6; obj[1] = 6;
@ -354,7 +354,7 @@ public void testIntArrayAsObject() {
public void testShortArray() { public void testShortArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((short[]) null).toHashCode());
short[] obj = new short[2]; 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; obj[0] = (short) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = (short) 6; obj[1] = (short) 6;
@ -364,7 +364,7 @@ public void testShortArray() {
@Test @Test
public void testShortArrayAsObject() { public void testShortArrayAsObject() {
short[] obj = new short[2]; 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; obj[0] = (short) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = (short) 6; obj[1] = (short) 6;
@ -375,7 +375,7 @@ public void testShortArrayAsObject() {
public void testCharArray() { public void testCharArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((char[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((char[]) null).toHashCode());
char[] obj = new char[2]; 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; obj[0] = (char) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = (char) 6; obj[1] = (char) 6;
@ -385,7 +385,7 @@ public void testCharArray() {
@Test @Test
public void testCharArrayAsObject() { public void testCharArrayAsObject() {
char[] obj = new char[2]; 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; obj[0] = (char) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = (char) 6; obj[1] = (char) 6;
@ -396,7 +396,7 @@ public void testCharArrayAsObject() {
public void testByteArray() { public void testByteArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((byte[]) null).toHashCode());
byte[] obj = new byte[2]; 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; obj[0] = (byte) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = (byte) 6; obj[1] = (byte) 6;
@ -406,7 +406,7 @@ public void testByteArray() {
@Test @Test
public void testByteArrayAsObject() { public void testByteArrayAsObject() {
byte[] obj = new byte[2]; 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; obj[0] = (byte) 5;
assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + 5) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = (byte) 6; obj[1] = (byte) 6;
@ -417,28 +417,28 @@ public void testByteArrayAsObject() {
public void testDoubleArray() { public void testDoubleArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((double[]) null).toHashCode());
double[] obj = new double[2]; 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; obj[0] = 5.4d;
long l1 = Double.doubleToLongBits(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()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = 6.3d; obj[1] = 6.3d;
long l2 = Double.doubleToLongBits(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()); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append(obj).toHashCode());
} }
@Test @Test
public void testDoubleArrayAsObject() { public void testDoubleArrayAsObject() {
double[] obj = new double[2]; 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; obj[0] = 5.4d;
long l1 = Double.doubleToLongBits(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()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
obj[1] = 6.3d; obj[1] = 6.3d;
long l2 = Double.doubleToLongBits(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()); assertEquals((17 * 37 + h1) * 37 + h2, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
} }
@ -446,7 +446,7 @@ public void testDoubleArrayAsObject() {
public void testFloatArray() { public void testFloatArray() {
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((float[]) null).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append((float[]) null).toHashCode());
float[] obj = new float[2]; 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; obj[0] = 5.4f;
int h1 = Float.floatToIntBits(5.4f); int h1 = Float.floatToIntBits(5.4f);
assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
@ -458,7 +458,7 @@ public void testFloatArray() {
@Test @Test
public void testFloatArrayAsObject() { public void testFloatArrayAsObject() {
float[] obj = new float[2]; 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; obj[0] = 5.4f;
int h1 = Float.floatToIntBits(5.4f); int h1 = Float.floatToIntBits(5.4f);
assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode()); assertEquals((17 * 37 + h1) * 37, new HashCodeBuilder(17, 37).append((Object) obj).toHashCode());
@ -491,7 +491,7 @@ public void testBooleanArrayAsObject() {
@Test @Test
public void testBooleanMultiArray() { public void testBooleanMultiArray() {
boolean[][] obj = new boolean[2][]; 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]; obj[0] = new boolean[0];
assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals(17 * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[0] = new boolean[1]; obj[0] = new boolean[1];
@ -501,23 +501,23 @@ public void testBooleanMultiArray() {
obj[0][0] = true; obj[0][0] = true;
assertEquals(((17 * 37 + 0) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode()); assertEquals(((17 * 37 + 0) * 37 + 1) * 37, new HashCodeBuilder(17, 37).append(obj).toHashCode());
obj[1] = new boolean[1]; 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 @Test
public void testReflectionHashCodeExcludeFields() throws Exception { public void testReflectionHashCodeExcludeFields() throws Exception {
TestObjectWithMultipleFields x = new TestObjectWithMultipleFields(1, 2, 3); 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, (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[]{}));
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, new String[]{"xxx"}));
assertEquals(((17 * 37 + 1) * 37 + 3), HashCodeBuilder.reflectionHashCode(x, new String[]{"two"})); 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 + 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"}));
assertEquals(17, HashCodeBuilder.reflectionHashCode(x, new String[]{"one", "two", "three", "xxx"})); assertEquals(17, HashCodeBuilder.reflectionHashCode(x, new String[]{"one", "two", "three", "xxx"}));

View File

@ -428,7 +428,7 @@ protected void endOfPeriod() {
*/ */
@Override @Override
protected ScheduledFuture<?> startTimer() { protected ScheduledFuture<?> startTimer() {
return (schedFuture != null) ? schedFuture : super.startTimer(); return schedFuture != null ? schedFuture : super.startTimer();
} }
} }

View File

@ -551,12 +551,12 @@ public void testChaining() {
* <code>null</code>. * <code>null</code>.
*/ */
public void testCloneNotSupportedException() { public void testCloneNotSupportedException() {
Object notCloned = (new StrTokenizer() { Object notCloned = new StrTokenizer() {
@Override @Override
Object cloneReset() throws CloneNotSupportedException { Object cloneReset() throws CloneNotSupportedException {
throw new CloneNotSupportedException("test"); throw new CloneNotSupportedException("test");
} }
}).clone(); }.clone();
assertNull(notCloned); assertNull(notCloned);
} }