Use final

- Use method reference
- Remove noisy parens
- Format tweaks
- Remove noisy block nesting
This commit is contained in:
Gary Gregory 2024-01-24 22:38:24 -05:00
parent 62e8c58129
commit 6540edfdc0
56 changed files with 340 additions and 347 deletions

View File

@ -316,7 +316,7 @@ public class BitField {
* parameter replacing the old bits * parameter replacing the old bits
*/ */
public int setValue(final int holder, final int value) { public int setValue(final int holder, final int value) {
return (holder & ~mask) | ((value << shiftCount) & mask); return holder & ~mask | value << shiftCount & mask;
} }
} }

View File

@ -483,10 +483,10 @@ public class CharUtils {
*/ */
public static String unicodeEscaped(final char ch) { public static String unicodeEscaped(final char ch) {
return "\\u" + return "\\u" +
HEX_DIGITS[(ch >> 12) & 15] + HEX_DIGITS[ch >> 12 & 15] +
HEX_DIGITS[(ch >> 8) & 15] + HEX_DIGITS[ch >> 8 & 15] +
HEX_DIGITS[(ch >> 4) & 15] + HEX_DIGITS[ch >> 4 & 15] +
HEX_DIGITS[(ch) & 15]; HEX_DIGITS[ch & 15];
} }
/** /**

View File

@ -528,7 +528,7 @@ public class ClassUtils {
*/ */
public static Class<?> getClass(final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException { public static Class<?> getClass(final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException {
try { try {
Class<?> clazz = namePrimitiveMap.get(className); final Class<?> clazz = namePrimitiveMap.get(className);
return clazz != null ? clazz : Class.forName(toCanonicalName(className), initialize, classLoader); return clazz != null ? clazz : Class.forName(toCanonicalName(className), initialize, classLoader);
} catch (final ClassNotFoundException ex) { } catch (final ClassNotFoundException ex) {
// allow path separators (.) as inner class name separators // allow path separators (.) as inner class name separators

View File

@ -175,7 +175,7 @@ public class Conversion {
final int shift = i + dstPos; final int shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift; final int mask = 0x1 << shift;
out = (byte) ((out & ~mask) | bits); out = (byte) (out & ~mask | bits);
} }
return out; return out;
} }
@ -332,7 +332,7 @@ public class Conversion {
final int shift = i + dstPos; final int shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift; final int mask = 0x1 << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -365,7 +365,7 @@ public class Conversion {
final int shift = i + dstPos; final int shift = i + dstPos;
final long bits = (src[i + srcPos] ? 1L : 0) << shift; final long bits = (src[i + srcPos] ? 1L : 0) << shift;
final long mask = 0x1L << shift; final long mask = 0x1L << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -398,7 +398,7 @@ public class Conversion {
final int shift = i + dstPos; final int shift = i + dstPos;
final int bits = (src[i + srcPos] ? 1 : 0) << shift; final int bits = (src[i + srcPos] ? 1 : 0) << shift;
final int mask = 0x1 << shift; final int mask = 0x1 << shift;
out = (short) ((out & ~mask) | bits); out = (short) (out & ~mask | bits);
} }
return out; return out;
} }
@ -431,7 +431,7 @@ public class Conversion {
final int shift = i * 8 + dstPos; final int shift = i * 8 + dstPos;
final int bits = (0xff & src[i + srcPos]) << shift; final int bits = (0xff & src[i + srcPos]) << shift;
final int mask = 0xff << shift; final int mask = 0xff << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -464,7 +464,7 @@ public class Conversion {
final int shift = i * 8 + dstPos; final int shift = i * 8 + dstPos;
final long bits = (0xffL & src[i + srcPos]) << shift; final long bits = (0xffL & src[i + srcPos]) << shift;
final long mask = 0xffL << shift; final long mask = 0xffL << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -497,7 +497,7 @@ public class Conversion {
final int shift = i * 8 + dstPos; final int shift = i * 8 + dstPos;
final int bits = (0xff & src[i + srcPos]) << shift; final int bits = (0xff & src[i + srcPos]) << shift;
final int mask = 0xff << shift; final int mask = 0xff << shift;
out = (short) ((out & ~mask) | bits); out = (short) (out & ~mask | bits);
} }
return out; return out;
} }
@ -545,7 +545,7 @@ public class Conversion {
} }
for (int i = 0; i < nBools; i++) { for (int i = 0; i < nBools; i++) {
final int shift = i + srcPos; final int shift = i + srcPos;
dst[dstPos + i] = (0x1 & (src >> shift)) != 0; dst[dstPos + i] = (0x1 & src >> shift) != 0;
} }
return dst; return dst;
} }
@ -576,7 +576,7 @@ public class Conversion {
int append = sb.length(); int append = sb.length();
for (int i = 0; i < nHexs; i++) { for (int i = 0; i < nHexs; i++) {
final int shift = i * 4 + srcPos; final int shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift); final int bits = 0xF & src >> shift;
if (dstPos + i == append) { if (dstPos + i == append) {
++append; ++append;
sb.append(intToHexDigit(bits)); sb.append(intToHexDigit(bits));
@ -802,7 +802,7 @@ public class Conversion {
final int shift = i * 4 + dstPos; final int shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift; final int mask = 0xf << shift;
out = (byte) ((out & ~mask) | bits); out = (byte) (out & ~mask | bits);
} }
return out; return out;
} }
@ -832,7 +832,7 @@ public class Conversion {
final int shift = i * 4 + dstPos; final int shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift; final int mask = 0xf << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -863,7 +863,7 @@ public class Conversion {
final int shift = i * 4 + dstPos; final int shift = i * 4 + dstPos;
final long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift; final long bits = (0xfL & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final long mask = 0xfL << shift; final long mask = 0xfL << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -894,7 +894,7 @@ public class Conversion {
final int shift = i * 4 + dstPos; final int shift = i * 4 + dstPos;
final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift; final int bits = (0xf & hexDigitToInt(src.charAt(i + srcPos))) << shift;
final int mask = 0xf << shift; final int mask = 0xf << shift;
out = (short) ((out & ~mask) | bits); out = (short) (out & ~mask | bits);
} }
return out; return out;
} }
@ -927,7 +927,7 @@ public class Conversion {
final int shift = i * 32 + dstPos; final int shift = i * 32 + dstPos;
final long bits = (0xffffffffL & src[i + srcPos]) << shift; final long bits = (0xffffffffL & src[i + srcPos]) << shift;
final long mask = 0xffffffffL << shift; final long mask = 0xffffffffL << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -957,7 +957,7 @@ public class Conversion {
} }
for (int i = 0; i < nBools; i++) { for (int i = 0; i < nBools; i++) {
final int shift = i + srcPos; final int shift = i + srcPos;
dst[dstPos + i] = (0x1 & (src >> shift)) != 0; dst[dstPos + i] = (0x1 & src >> shift) != 0;
} }
return dst; return dst;
} }
@ -987,7 +987,7 @@ public class Conversion {
} }
for (int i = 0; i < nBytes; i++) { for (int i = 0; i < nBytes; i++) {
final int shift = i * 8 + srcPos; final int shift = i * 8 + srcPos;
dst[dstPos + i] = (byte) (0xff & (src >> shift)); dst[dstPos + i] = (byte) (0xff & src >> shift);
} }
return dst; return dst;
} }
@ -1018,7 +1018,7 @@ public class Conversion {
int append = sb.length(); int append = sb.length();
for (int i = 0; i < nHexs; i++) { for (int i = 0; i < nHexs; i++) {
final int shift = i * 4 + srcPos; final int shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift); final int bits = 0xF & src >> shift;
if (dstPos + i == append) { if (dstPos + i == append) {
++append; ++append;
sb.append(intToHexDigit(bits)); sb.append(intToHexDigit(bits));
@ -1135,7 +1135,7 @@ public class Conversion {
} }
for (int i = 0; i < nShorts; i++) { for (int i = 0; i < nShorts; i++) {
final int shift = i * 16 + srcPos; final int shift = i * 16 + srcPos;
dst[dstPos + i] = (short) (0xffff & (src >> shift)); dst[dstPos + i] = (short) (0xffff & src >> shift);
} }
return dst; return dst;
} }
@ -1165,7 +1165,7 @@ public class Conversion {
} }
for (int i = 0; i < nBools; i++) { for (int i = 0; i < nBools; i++) {
final int shift = i + srcPos; final int shift = i + srcPos;
dst[dstPos + i] = (0x1 & (src >> shift)) != 0; dst[dstPos + i] = (0x1 & src >> shift) != 0;
} }
return dst; return dst;
} }
@ -1195,7 +1195,7 @@ public class Conversion {
} }
for (int i = 0; i < nBytes; i++) { for (int i = 0; i < nBytes; i++) {
final int shift = i * 8 + srcPos; final int shift = i * 8 + srcPos;
dst[dstPos + i] = (byte) (0xff & (src >> shift)); dst[dstPos + i] = (byte) (0xff & src >> shift);
} }
return dst; return dst;
} }
@ -1226,7 +1226,7 @@ public class Conversion {
int append = sb.length(); int append = sb.length();
for (int i = 0; i < nHexs; i++) { for (int i = 0; i < nHexs; i++) {
final int shift = i * 4 + srcPos; final int shift = i * 4 + srcPos;
final int bits = (int) (0xF & (src >> shift)); final int bits = (int) (0xF & src >> shift);
if (dstPos + i == append) { if (dstPos + i == append) {
++append; ++append;
sb.append(intToHexDigit(bits)); sb.append(intToHexDigit(bits));
@ -1262,7 +1262,7 @@ public class Conversion {
} }
for (int i = 0; i < nInts; i++) { for (int i = 0; i < nInts; i++) {
final int shift = i * 32 + srcPos; final int shift = i * 32 + srcPos;
dst[dstPos + i] = (int) (0xffffffff & (src >> shift)); dst[dstPos + i] = (int) (0xffffffff & src >> shift);
} }
return dst; return dst;
} }
@ -1292,7 +1292,7 @@ public class Conversion {
} }
for (int i = 0; i < nShorts; i++) { for (int i = 0; i < nShorts; i++) {
final int shift = i * 16 + srcPos; final int shift = i * 16 + srcPos;
dst[dstPos + i] = (short) (0xffff & (src >> shift)); dst[dstPos + i] = (short) (0xffff & src >> shift);
} }
return dst; return dst;
} }
@ -1325,7 +1325,7 @@ public class Conversion {
final int shift = i * 16 + dstPos; final int shift = i * 16 + dstPos;
final int bits = (0xffff & src[i + srcPos]) << shift; final int bits = (0xffff & src[i + srcPos]) << shift;
final int mask = 0xffff << shift; final int mask = 0xffff << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -1358,7 +1358,7 @@ public class Conversion {
final int shift = i * 16 + dstPos; final int shift = i * 16 + dstPos;
final long bits = (0xffffL & src[i + srcPos]) << shift; final long bits = (0xffffL & src[i + srcPos]) << shift;
final long mask = 0xffffL << shift; final long mask = 0xffffL << shift;
out = (out & ~mask) | bits; out = out & ~mask | bits;
} }
return out; return out;
} }
@ -1386,10 +1386,10 @@ public class Conversion {
if (nBools - 1 + srcPos >= 16) { if (nBools - 1 + srcPos >= 16) {
throw new IllegalArgumentException("nBools-1+srcPos is greater or equal to than 16"); throw new IllegalArgumentException("nBools-1+srcPos is greater or equal to than 16");
} }
assert (nBools - 1) < 16 - srcPos; assert nBools - 1 < 16 - srcPos;
for (int i = 0; i < nBools; i++) { for (int i = 0; i < nBools; i++) {
final int shift = i + srcPos; final int shift = i + srcPos;
dst[dstPos + i] = (0x1 & (src >> shift)) != 0; dst[dstPos + i] = (0x1 & src >> shift) != 0;
} }
return dst; return dst;
} }
@ -1419,7 +1419,7 @@ public class Conversion {
} }
for (int i = 0; i < nBytes; i++) { for (int i = 0; i < nBytes; i++) {
final int shift = i * 8 + srcPos; final int shift = i * 8 + srcPos;
dst[dstPos + i] = (byte) (0xff & (src >> shift)); dst[dstPos + i] = (byte) (0xff & src >> shift);
} }
return dst; return dst;
} }
@ -1450,7 +1450,7 @@ public class Conversion {
int append = sb.length(); int append = sb.length();
for (int i = 0; i < nHexs; i++) { for (int i = 0; i < nHexs; i++) {
final int shift = i * 4 + srcPos; final int shift = i * 4 + srcPos;
final int bits = 0xF & (src >> shift); final int bits = 0xF & src >> shift;
if (dstPos + i == append) { if (dstPos + i == append) {
++append; ++append;
sb.append(intToHexDigit(bits)); sb.append(intToHexDigit(bits));

View File

@ -149,7 +149,7 @@ public class EnumUtils {
Collections.addAll(condensed, values); Collections.addAll(condensed, values);
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1]; final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
for (final E value : condensed) { for (final E value : condensed) {
result[value.ordinal() / Long.SIZE] |= 1L << (value.ordinal() % Long.SIZE); result[value.ordinal() / Long.SIZE] |= 1L << value.ordinal() % Long.SIZE;
} }
ArrayUtils.reverse(result); ArrayUtils.reverse(result);
return result; return result;
@ -178,7 +178,7 @@ public class EnumUtils {
values.forEach(constant -> condensed.add(Objects.requireNonNull(constant, NULL_ELEMENTS_NOT_PERMITTED))); values.forEach(constant -> condensed.add(Objects.requireNonNull(constant, NULL_ELEMENTS_NOT_PERMITTED)));
final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1]; final long[] result = new long[(enumClass.getEnumConstants().length - 1) / Long.SIZE + 1];
for (final E value : condensed) { for (final E value : condensed) {
result[value.ordinal() / Long.SIZE] |= 1L << (value.ordinal() % Long.SIZE); result[value.ordinal() / Long.SIZE] |= 1L << value.ordinal() % Long.SIZE;
} }
ArrayUtils.reverse(result); ArrayUtils.reverse(result);
return result; return result;
@ -412,7 +412,7 @@ public class EnumUtils {
ArrayUtils.reverse(lvalues); ArrayUtils.reverse(lvalues);
for (final E constant : enumClass.getEnumConstants()) { for (final E constant : enumClass.getEnumConstants()) {
final int block = constant.ordinal() / Long.SIZE; final int block = constant.ordinal() / Long.SIZE;
if (block < lvalues.length && (lvalues[block] & 1L << (constant.ordinal() % Long.SIZE)) != 0) { if (block < lvalues.length && (lvalues[block] & 1L << constant.ordinal() % Long.SIZE) != 0) {
results.add(constant); results.add(constant);
} }
} }

View File

@ -94,7 +94,7 @@ public class RandomUtils {
return startInclusive; return startInclusive;
} }
return startInclusive + ((endExclusive - startInclusive) * random().nextDouble()); return startInclusive + (endExclusive - startInclusive) * random().nextDouble();
} }
/** /**
@ -129,7 +129,7 @@ public class RandomUtils {
return startInclusive; return startInclusive;
} }
return startInclusive + ((endExclusive - startInclusive) * random().nextFloat()); return startInclusive + (endExclusive - startInclusive) * random().nextFloat();
} }
/** /**
@ -193,7 +193,7 @@ public class RandomUtils {
do { do {
bits = random().nextLong() >>> 1; bits = random().nextLong() >>> 1;
val = bits % n; val = bits % n;
} while (bits - val + (n - 1) < 0); } while (bits - val + n - 1 < 0);
return val; return val;
} }

View File

@ -36,7 +36,7 @@ final class Reflection {
static Object getUnchecked(final Field field, final Object obj) { static Object getUnchecked(final Field field, final Object obj) {
try { try {
return Objects.requireNonNull(field, "field").get(obj); return Objects.requireNonNull(field, "field").get(obj);
} catch (IllegalAccessException e) { } catch (final IllegalAccessException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
} }

View File

@ -151,7 +151,7 @@ public class AtomicInitializer<T> extends AbstractConcurrentInitializer<T, Concu
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected ConcurrentException getTypedException(Exception e) { protected ConcurrentException getTypedException(final Exception e) {
return new ConcurrentException(e); return new ConcurrentException(e);
} }

View File

@ -139,7 +139,7 @@ public class AtomicSafeInitializer<T> extends AbstractConcurrentInitializer<T, C
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected ConcurrentException getTypedException(Exception e) { protected ConcurrentException getTypedException(final Exception e) {
return new ConcurrentException(e); return new ConcurrentException(e);
} }

View File

@ -318,7 +318,7 @@ public class BackgroundInitializer<T> extends AbstractConcurrentInitializer<T, E
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Exception getTypedException(Exception e) { protected Exception getTypedException(final Exception e) {
//This Exception object will be used for type comparison in AbstractConcurrentInitializer.initialize but not thrown //This Exception object will be used for type comparison in AbstractConcurrentInitializer.initialize but not thrown
return new Exception(e); return new Exception(e);
} }

View File

@ -111,7 +111,7 @@ public class CallableBackgroundInitializer<T> extends BackgroundInitializer<T> {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected Exception getTypedException(Exception e) { protected Exception getTypedException(final Exception e) {
//This Exception object will be used for type comparison in AbstractConcurrentInitializer.initialize but not thrown //This Exception object will be used for type comparison in AbstractConcurrentInitializer.initialize but not thrown
return new Exception(e); return new Exception(e);
} }

View File

@ -152,7 +152,7 @@ public class LazyInitializer<T> extends AbstractConcurrentInitializer<T, Concurr
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
protected ConcurrentException getTypedException(Exception e) { protected ConcurrentException getTypedException(final Exception e) {
return new ConcurrentException(e); return new ConcurrentException(e);
} }

View File

@ -288,10 +288,10 @@ public class MultiBackgroundInitializer
public void close() throws ConcurrentException { public void close() throws ConcurrentException {
ConcurrentException exception = null; ConcurrentException exception = null;
for (BackgroundInitializer<?> child : childInitializers.values()) { for (final BackgroundInitializer<?> child : childInitializers.values()) {
try { try {
child.close(); child.close();
} catch (Exception e) { } catch (final Exception e) {
if (exception == null) { if (exception == null) {
exception = new ConcurrentException(); exception = new ConcurrentException();
} }

View File

@ -263,7 +263,7 @@ public class MutableLong extends Number implements Comparable<MutableLong>, Muta
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
return (int) (value ^ (value >>> 32)); return (int) (value ^ value >>> 32);
} }
/** /**

View File

@ -130,10 +130,10 @@ public class UnicodeEscaper extends CodePointTranslator {
out.write(toUtf16Escape(codePoint)); out.write(toUtf16Escape(codePoint));
} else { } else {
out.write("\\u"); out.write("\\u");
out.write(HEX_DIGITS[(codePoint >> 12) & 15]); out.write(HEX_DIGITS[codePoint >> 12 & 15]);
out.write(HEX_DIGITS[(codePoint >> 8) & 15]); out.write(HEX_DIGITS[codePoint >> 8 & 15]);
out.write(HEX_DIGITS[(codePoint >> 4) & 15]); out.write(HEX_DIGITS[codePoint >> 4 & 15]);
out.write(HEX_DIGITS[(codePoint) & 15]); out.write(HEX_DIGITS[codePoint & 15]);
} }
return true; return true;
} }

View File

@ -35,7 +35,7 @@ final class GmtTimeZone extends TimeZone {
static final long serialVersionUID = 1L; static final long serialVersionUID = 1L;
private static StringBuilder twoDigits(final StringBuilder sb, final int n) { private static StringBuilder twoDigits(final StringBuilder sb, final int n) {
return sb.append((char) ('0' + (n / 10))).append((char) ('0' + (n % 10))); return sb.append((char) ('0' + n / 10)).append((char) ('0' + n % 10));
} }
private final int offset; private final int offset;
@ -48,7 +48,7 @@ final class GmtTimeZone extends TimeZone {
if (minutes >= MINUTES_PER_HOUR) { if (minutes >= MINUTES_PER_HOUR) {
throw new IllegalArgumentException(minutes + " minutes out of range"); throw new IllegalArgumentException(minutes + " minutes out of range");
} }
final int milliseconds = (minutes + (hours * MINUTES_PER_HOUR)) * MILLISECONDS_PER_MINUTE; final int milliseconds = (minutes + hours * MINUTES_PER_HOUR) * MILLISECONDS_PER_MINUTE;
offset = negate ? -milliseconds : milliseconds; offset = negate ? -milliseconds : milliseconds;
// @formatter:off // @formatter:off
zoneId = twoDigits(twoDigits(new StringBuilder(9) zoneId = twoDigits(twoDigits(new StringBuilder(9)

View File

@ -434,7 +434,7 @@ public class StopWatch {
* @param nanos nanoseconds to convert. * @param nanos nanoseconds to convert.
* @return milliseconds conversion result. * @return milliseconds conversion result.
*/ */
private long nanosToMillis(long nanos) { private long nanosToMillis(final long nanos) {
return nanos / NANO_2_MILLIS; return nanos / NANO_2_MILLIS;
} }

View File

@ -550,16 +550,16 @@ public class ArrayUtilsRemoveTest extends AbstractLangTest {
double[] array; double[] array;
array = ArrayUtils.removeElement(null, (double) 1); array = ArrayUtils.removeElement(null, (double) 1);
assertNull(array); assertNull(array);
array = ArrayUtils.removeElement(ArrayUtils.EMPTY_DOUBLE_ARRAY, (double) 1); array = ArrayUtils.removeElement(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1);
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array); assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
assertEquals(Double.TYPE, array.getClass().getComponentType()); assertEquals(Double.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new double[] {1}, (double) 1); array = ArrayUtils.removeElement(new double[] {1}, 1);
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array); assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
assertEquals(Double.TYPE, array.getClass().getComponentType()); assertEquals(Double.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new double[] {1, 2}, (double) 1); array = ArrayUtils.removeElement(new double[] {1, 2}, 1);
assertArrayEquals(new double[]{2}, array); assertArrayEquals(new double[]{2}, array);
assertEquals(Double.TYPE, array.getClass().getComponentType()); assertEquals(Double.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new double[] {1, 2, 1}, (double) 1); array = ArrayUtils.removeElement(new double[] {1, 2, 1}, 1);
assertArrayEquals(new double[]{2, 1}, array); assertArrayEquals(new double[]{2, 1}, array);
assertEquals(Double.TYPE, array.getClass().getComponentType()); assertEquals(Double.TYPE, array.getClass().getComponentType());
} }
@ -568,18 +568,18 @@ public class ArrayUtilsRemoveTest extends AbstractLangTest {
@SuppressWarnings("cast") @SuppressWarnings("cast")
public void testRemoveElementFloatArray() { public void testRemoveElementFloatArray() {
float[] array; float[] array;
array = ArrayUtils.removeElement((float[]) null, (float) 1); array = ArrayUtils.removeElement((float[]) null, 1);
assertNull(array); assertNull(array);
array = ArrayUtils.removeElement(ArrayUtils.EMPTY_FLOAT_ARRAY, (float) 1); array = ArrayUtils.removeElement(ArrayUtils.EMPTY_FLOAT_ARRAY, 1);
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array); assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
assertEquals(Float.TYPE, array.getClass().getComponentType()); assertEquals(Float.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new float[] {1}, (float) 1); array = ArrayUtils.removeElement(new float[] {1}, 1);
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array); assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
assertEquals(Float.TYPE, array.getClass().getComponentType()); assertEquals(Float.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new float[] {1, 2}, (float) 1); array = ArrayUtils.removeElement(new float[] {1, 2}, 1);
assertArrayEquals(new float[]{2}, array); assertArrayEquals(new float[]{2}, array);
assertEquals(Float.TYPE, array.getClass().getComponentType()); assertEquals(Float.TYPE, array.getClass().getComponentType());
array = ArrayUtils.removeElement(new float[] {1, 2, 1}, (float) 1); array = ArrayUtils.removeElement(new float[] {1, 2, 1}, 1);
assertArrayEquals(new float[]{2, 1}, array); assertArrayEquals(new float[]{2, 1}, array);
assertEquals(Float.TYPE, array.getClass().getComponentType()); assertEquals(Float.TYPE, array.getClass().getComponentType());
} }

View File

@ -45,7 +45,7 @@ import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation") // deliberate use of deprecated code @SuppressWarnings("deprecation") // deliberate use of deprecated code
public class ArrayUtilsTest extends AbstractLangTest { public class ArrayUtilsTest extends AbstractLangTest {
private final class TestClass { private static final class TestClass {
// empty // empty
} }
@ -284,13 +284,13 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testContainsDouble() { public void testContainsDouble() {
double[] array = null; double[] array = null;
assertFalse(ArrayUtils.contains(array, (double) 1)); assertFalse(ArrayUtils.contains(array, 1));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertTrue(ArrayUtils.contains(array, (double) 0)); assertTrue(ArrayUtils.contains(array, 0));
assertTrue(ArrayUtils.contains(array, (double) 1)); assertTrue(ArrayUtils.contains(array, 1));
assertTrue(ArrayUtils.contains(array, (double) 2)); assertTrue(ArrayUtils.contains(array, 2));
assertTrue(ArrayUtils.contains(array, (double) 3)); assertTrue(ArrayUtils.contains(array, 3));
assertFalse(ArrayUtils.contains(array, (double) 99)); assertFalse(ArrayUtils.contains(array, 99));
} }
@Test @Test
@ -305,7 +305,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testContainsDoubleTolerance() { public void testContainsDoubleTolerance() {
double[] array = null; double[] array = null;
assertFalse(ArrayUtils.contains(array, (double) 1, (double) 0)); assertFalse(ArrayUtils.contains(array, 1, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertFalse(ArrayUtils.contains(array, 4.0, 0.33)); assertFalse(ArrayUtils.contains(array, 4.0, 0.33));
assertFalse(ArrayUtils.contains(array, 2.5, 0.49)); assertFalse(ArrayUtils.contains(array, 2.5, 0.49));
@ -317,13 +317,13 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testContainsFloat() { public void testContainsFloat() {
float[] array = null; float[] array = null;
assertFalse(ArrayUtils.contains(array, (float) 1)); assertFalse(ArrayUtils.contains(array, 1));
array = new float[]{0, 1, 2, 3, 0}; array = new float[]{0, 1, 2, 3, 0};
assertTrue(ArrayUtils.contains(array, (float) 0)); assertTrue(ArrayUtils.contains(array, 0));
assertTrue(ArrayUtils.contains(array, (float) 1)); assertTrue(ArrayUtils.contains(array, 1));
assertTrue(ArrayUtils.contains(array, (float) 2)); assertTrue(ArrayUtils.contains(array, 2));
assertTrue(ArrayUtils.contains(array, (float) 3)); assertTrue(ArrayUtils.contains(array, 3));
assertFalse(ArrayUtils.contains(array, (float) 99)); assertFalse(ArrayUtils.contains(array, 99));
} }
@Test @Test
@ -716,7 +716,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
testSet.set(0); testSet.set(0);
testSet.set(4); testSet.set(4);
assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 0.3)); assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0.3));
testSet.clear(); testSet.clear();
testSet.set(3); testSet.set(3);
assertEquals(testSet, ArrayUtils.indexesOf(array, 4.15, 2.0)); assertEquals(testSet, ArrayUtils.indexesOf(array, 4.15, 2.0));
@ -755,14 +755,14 @@ public class ArrayUtilsTest extends AbstractLangTest {
double[] array = null; double[] array = null;
final BitSet emptySet = new BitSet(); final BitSet emptySet = new BitSet();
final BitSet testSet = new BitSet(); final BitSet testSet = new BitSet();
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0)); assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 0, 0));
array = new double[0]; array = new double[0];
assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0)); assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 0, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
testSet.set(4); testSet.set(4);
assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 1, 0.3)); assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 1, 0.3));
testSet.set(0); testSet.set(0);
assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 0, 0.3)); assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0, 0.3));
testSet.clear(); testSet.clear();
testSet.set(2); testSet.set(2);
assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0, 0.35)); assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0, 0.35));
@ -1070,16 +1070,16 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testIndexOfDouble() { public void testIndexOfDouble() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(0, ArrayUtils.indexOf(array, (double) 0)); assertEquals(0, ArrayUtils.indexOf(array, 0));
assertEquals(1, ArrayUtils.indexOf(array, (double) 1)); assertEquals(1, ArrayUtils.indexOf(array, 1));
assertEquals(2, ArrayUtils.indexOf(array, (double) 2)); assertEquals(2, ArrayUtils.indexOf(array, 2));
assertEquals(3, ArrayUtils.indexOf(array, (double) 3)); assertEquals(3, ArrayUtils.indexOf(array, 3));
assertEquals(3, ArrayUtils.indexOf(array, (double) 3, -1)); assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (double) 99)); assertEquals(-1, ArrayUtils.indexOf(array, 99));
} }
@Test @Test
@ -1099,7 +1099,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, (double) 0)); assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, (double) 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(0, ArrayUtils.indexOf(array, (double) 0, 0.3)); assertEquals(0, ArrayUtils.indexOf(array, 0, 0.3));
assertEquals(2, ArrayUtils.indexOf(array, 2.2, 0.35)); assertEquals(2, ArrayUtils.indexOf(array, 2.2, 0.35));
assertEquals(3, ArrayUtils.indexOf(array, 4.15, 2.0)); assertEquals(3, ArrayUtils.indexOf(array, 4.15, 2.0));
assertEquals(1, ArrayUtils.indexOf(array, 1.00001324, 0.0001)); assertEquals(1, ArrayUtils.indexOf(array, 1.00001324, 0.0001));
@ -1109,29 +1109,29 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testIndexOfDoubleWithStartIndex() { public void testIndexOfDoubleWithStartIndex() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 2)); assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
assertEquals(-1, ArrayUtils.indexOf(array, (double) 1, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, (double) 2, 2)); assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, (double) 3, 2)); assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
assertEquals(-1, ArrayUtils.indexOf(array, (double) 99, 0)); assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 6)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
@Test @Test
public void testIndexOfDoubleWithStartIndexTolerance() { public void testIndexOfDoubleWithStartIndexTolerance() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2, (double) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2, 0));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2, (double) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 99, 0.3)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 99, 0.3));
assertEquals(0, ArrayUtils.indexOf(array, (double) 0, 0, 0.3)); assertEquals(0, ArrayUtils.indexOf(array, 0, 0, 0.3));
assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 3, 0.3)); assertEquals(4, ArrayUtils.indexOf(array, 0, 3, 0.3));
assertEquals(2, ArrayUtils.indexOf(array, 2.2, 0, 0.35)); assertEquals(2, ArrayUtils.indexOf(array, 2.2, 0, 0.35));
assertEquals(3, ArrayUtils.indexOf(array, 4.15, 0, 2.0)); assertEquals(3, ArrayUtils.indexOf(array, 4.15, 0, 2.0));
assertEquals(1, ArrayUtils.indexOf(array, 1.00001324, 0, 0.0001)); assertEquals(1, ArrayUtils.indexOf(array, 1.00001324, 0, 0.0001));
@ -1143,15 +1143,15 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testIndexOfFloat() { public void testIndexOfFloat() {
float[] array = null; float[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0));
array = new float[0]; array = new float[0];
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0)); assertEquals(-1, ArrayUtils.indexOf(array, 0));
array = new float[]{0, 1, 2, 3, 0}; array = new float[]{0, 1, 2, 3, 0};
assertEquals(0, ArrayUtils.indexOf(array, (float) 0)); assertEquals(0, ArrayUtils.indexOf(array, 0));
assertEquals(1, ArrayUtils.indexOf(array, (float) 1)); assertEquals(1, ArrayUtils.indexOf(array, 1));
assertEquals(2, ArrayUtils.indexOf(array, (float) 2)); assertEquals(2, ArrayUtils.indexOf(array, 2));
assertEquals(3, ArrayUtils.indexOf(array, (float) 3)); assertEquals(3, ArrayUtils.indexOf(array, 3));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 99)); assertEquals(-1, ArrayUtils.indexOf(array, 99));
} }
@Test @Test
@ -1166,17 +1166,17 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testIndexOfFloatWithStartIndex() { public void testIndexOfFloatWithStartIndex() {
float[] array = null; float[] array = null;
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
array = new float[0]; array = new float[0];
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
array = new float[]{0, 1, 2, 3, 0}; array = new float[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.indexOf(array, (float) 0, 2)); assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 1, 2)); assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
assertEquals(2, ArrayUtils.indexOf(array, (float) 2, 2)); assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
assertEquals(3, ArrayUtils.indexOf(array, (float) 3, 2)); assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
assertEquals(3, ArrayUtils.indexOf(array, (float) 3, -1)); assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 99, 0)); assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 6)); assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
} }
@Test @Test
@ -1762,15 +1762,15 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testLastIndexOfDouble() { public void testLastIndexOfDouble() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 3)); assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
@ -1781,7 +1781,7 @@ public class ArrayUtilsTest extends AbstractLangTest {
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 0.3)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 0.3));
assertEquals(2, ArrayUtils.lastIndexOf(array, 2.2, 0.35)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2.2, 0.35));
assertEquals(3, ArrayUtils.lastIndexOf(array, 4.15, 2.0)); assertEquals(3, ArrayUtils.lastIndexOf(array, 4.15, 2.0));
assertEquals(1, ArrayUtils.lastIndexOf(array, 1.00001324, 0.0001)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1.00001324, 0.0001));
@ -1791,31 +1791,31 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testLastIndexOfDoubleWithStartIndex() { public void testLastIndexOfDoubleWithStartIndex() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 2)); assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1, 2)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2, 2)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, -1)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 88)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
@Test @Test
public void testLastIndexOfDoubleWithStartIndexTolerance() { public void testLastIndexOfDoubleWithStartIndexTolerance() {
double[] array = null; double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2, 0));
array = new double[0]; array = new double[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2, 0));
array = new double[]{(double) 3}; array = new double[]{3};
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 1, 0, (double) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 1, 0, 0));
array = new double[]{0, 1, 2, 3, 0}; array = new double[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 99, 0.3)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 99, 0.3));
assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 3, 0.3)); assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 3, 0.3));
assertEquals(2, ArrayUtils.lastIndexOf(array, 2.2, 3, 0.35)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2.2, 3, 0.35));
assertEquals(3, ArrayUtils.lastIndexOf(array, 4.15, array.length, 2.0)); assertEquals(3, ArrayUtils.lastIndexOf(array, 4.15, array.length, 2.0));
assertEquals(1, ArrayUtils.lastIndexOf(array, 1.00001324, array.length, 0.0001)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1.00001324, array.length, 0.0001));
@ -1826,32 +1826,32 @@ public class ArrayUtilsTest extends AbstractLangTest {
@Test @Test
public void testLastIndexOfFloat() { public void testLastIndexOfFloat() {
float[] array = null; float[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
array = new float[0]; array = new float[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
array = new float[]{0, 1, 2, 3, 0}; array = new float[]{0, 1, 2, 3, 0};
assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
assertEquals(3, ArrayUtils.lastIndexOf(array, (float) 3)); assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
@Test @Test
public void testLastIndexOfFloatWithStartIndex() { public void testLastIndexOfFloatWithStartIndex() {
float[] array = null; float[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
array = new float[0]; array = new float[0];
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
array = new float[]{0, 1, 2, 3, 0}; array = new float[]{0, 1, 2, 3, 0};
assertEquals(0, ArrayUtils.lastIndexOf(array, (float) 0, 2)); assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1, 2)); assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2, 2)); assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, 2)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, -1)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99)); assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0, 88)); assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
} }
@Test @Test

View File

@ -401,9 +401,9 @@ public class CharSetTest extends AbstractLangTest {
@Test @Test
public void testGetInstance_Stringarray() { public void testGetInstance_Stringarray() {
assertNull(CharSet.getInstance((String[]) null)); assertNull(CharSet.getInstance((String[]) null));
assertEquals("[]", CharSet.getInstance(new String[0]).toString()); assertEquals("[]", CharSet.getInstance().toString());
assertEquals("[]", CharSet.getInstance(new String[] {null}).toString()); assertEquals("[]", CharSet.getInstance(new String[] {null}).toString());
assertEquals("[a-e]", CharSet.getInstance(new String[] {"a-e"}).toString()); assertEquals("[a-e]", CharSet.getInstance("a-e").toString());
} }
@Test @Test

View File

@ -80,7 +80,7 @@ public class CharUtilsTest extends AbstractLangTest {
assertFalse(CharUtils.isAsciiAlpha(CHAR_COPY)); assertFalse(CharUtils.isAsciiAlpha(CHAR_COPY));
for (int i = 0; i < 196; i++) { for (int i = 0; i < 196; i++) {
if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z')) { if (i >= 'A' && i <= 'Z' || i >= 'a' && i <= 'z') {
assertTrue(CharUtils.isAsciiAlpha((char) i)); assertTrue(CharUtils.isAsciiAlpha((char) i));
} else { } else {
assertFalse(CharUtils.isAsciiAlpha((char) i)); assertFalse(CharUtils.isAsciiAlpha((char) i));
@ -116,7 +116,7 @@ public class CharUtilsTest extends AbstractLangTest {
assertFalse(CharUtils.isAsciiAlphanumeric(CHAR_COPY)); assertFalse(CharUtils.isAsciiAlphanumeric(CHAR_COPY));
for (int i = 0; i < 196; i++) { for (int i = 0; i < 196; i++) {
if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || (i >= '0' && i <= '9')) { if (i >= 'A' && i <= 'Z' || i >= 'a' && i <= 'z' || i >= '0' && i <= '9') {
assertTrue(CharUtils.isAsciiAlphanumeric((char) i)); assertTrue(CharUtils.isAsciiAlphanumeric((char) i));
} else { } else {
assertFalse(CharUtils.isAsciiAlphanumeric((char) i)); assertFalse(CharUtils.isAsciiAlphanumeric((char) i));

View File

@ -86,7 +86,7 @@ public class ClassUtilsTest extends AbstractLangTest {
} }
private static final class Inner { private static final class Inner {
private final class DeeplyNested { private static final class DeeplyNested {
// empty // empty
} }
} }

View File

@ -62,9 +62,9 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.generateBitVector(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN))); EnumUtils.generateBitVector(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN)));
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertEquals((1L << 31), EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A31))); assertEquals(1L << 31, EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A31)));
assertEquals((1L << 32), EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A32))); assertEquals(1L << 32, EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A32)));
assertEquals((1L << 63), EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A63))); assertEquals(1L << 63, EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A63)));
assertEquals(Long.MIN_VALUE, EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A63))); assertEquals(Long.MIN_VALUE, EnumUtils.generateBitVector(Enum64.class, EnumSet.of(Enum64.A63)));
} }
@ -145,9 +145,9 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.generateBitVector(Traffic.class, Traffic.RED, Traffic.AMBER, Traffic.GREEN, Traffic.GREEN)); EnumUtils.generateBitVector(Traffic.class, Traffic.RED, Traffic.AMBER, Traffic.GREEN, Traffic.GREEN));
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertEquals((1L << 31), EnumUtils.generateBitVector(Enum64.class, Enum64.A31)); assertEquals(1L << 31, EnumUtils.generateBitVector(Enum64.class, Enum64.A31));
assertEquals((1L << 32), EnumUtils.generateBitVector(Enum64.class, Enum64.A32)); assertEquals(1L << 32, EnumUtils.generateBitVector(Enum64.class, Enum64.A32));
assertEquals((1L << 63), EnumUtils.generateBitVector(Enum64.class, Enum64.A63)); assertEquals(1L << 63, EnumUtils.generateBitVector(Enum64.class, Enum64.A63));
assertEquals(Long.MIN_VALUE, EnumUtils.generateBitVector(Enum64.class, Enum64.A63)); assertEquals(Long.MIN_VALUE, EnumUtils.generateBitVector(Enum64.class, Enum64.A63));
} }
@ -164,15 +164,15 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.generateBitVectors(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN)), 7L); EnumUtils.generateBitVectors(Traffic.class, EnumSet.of(Traffic.RED, Traffic.AMBER, Traffic.GREEN)), 7L);
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A31)), (1L << 31)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A31)), 1L << 31);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A32)), (1L << 32)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A32)), 1L << 32);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A63)), (1L << 63)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A63)), 1L << 63);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A63)), Long.MIN_VALUE); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, EnumSet.of(Enum64.A63)), Long.MIN_VALUE);
// More than 64 values Enum // More than 64 values Enum
assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, EnumSet.of(TooMany.M2)), 1L, 0L); assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, EnumSet.of(TooMany.M2)), 1L, 0L);
assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, EnumSet.of(TooMany.L2, TooMany.M2)), 1L, assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, EnumSet.of(TooMany.L2, TooMany.M2)), 1L,
(1L << 63)); 1L << 63);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -240,14 +240,14 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.generateBitVectors(Traffic.class, Traffic.RED, Traffic.AMBER, Traffic.GREEN, Traffic.GREEN), 7L); EnumUtils.generateBitVectors(Traffic.class, Traffic.RED, Traffic.AMBER, Traffic.GREEN, Traffic.GREEN), 7L);
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A31), (1L << 31)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A31), 1L << 31);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A32), (1L << 32)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A32), 1L << 32);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A63), (1L << 63)); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A63), 1L << 63);
assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A63), Long.MIN_VALUE); assertArrayEquals(EnumUtils.generateBitVectors(Enum64.class, Enum64.A63), Long.MIN_VALUE);
// More than 64 values Enum // More than 64 values Enum
assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, TooMany.M2), 1L, 0L); assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, TooMany.M2), 1L, 0L);
assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, TooMany.L2, TooMany.M2), 1L, (1L << 63)); assertArrayEquals(EnumUtils.generateBitVectors(TooMany.class, TooMany.L2, TooMany.M2), 1L, 1L << 63);
} }
@ -473,9 +473,9 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.processBitVector(Traffic.class, 7L)); EnumUtils.processBitVector(Traffic.class, 7L));
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertEquals(EnumSet.of(Enum64.A31), EnumUtils.processBitVector(Enum64.class, (1L << 31))); assertEquals(EnumSet.of(Enum64.A31), EnumUtils.processBitVector(Enum64.class, 1L << 31));
assertEquals(EnumSet.of(Enum64.A32), EnumUtils.processBitVector(Enum64.class, (1L << 32))); assertEquals(EnumSet.of(Enum64.A32), EnumUtils.processBitVector(Enum64.class, 1L << 32));
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVector(Enum64.class, (1L << 63))); assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVector(Enum64.class, 1L << 63));
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVector(Enum64.class, Long.MIN_VALUE)); assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVector(Enum64.class, Long.MIN_VALUE));
} }
@ -524,9 +524,9 @@ public class EnumUtilsTest extends AbstractLangTest {
EnumUtils.processBitVectors(Traffic.class, 666L, 7L)); EnumUtils.processBitVectors(Traffic.class, 666L, 7L));
// 64 values Enum (to test whether no int<->long jdk conversion issue exists) // 64 values Enum (to test whether no int<->long jdk conversion issue exists)
assertEquals(EnumSet.of(Enum64.A31), EnumUtils.processBitVectors(Enum64.class, (1L << 31))); assertEquals(EnumSet.of(Enum64.A31), EnumUtils.processBitVectors(Enum64.class, 1L << 31));
assertEquals(EnumSet.of(Enum64.A32), EnumUtils.processBitVectors(Enum64.class, (1L << 32))); assertEquals(EnumSet.of(Enum64.A32), EnumUtils.processBitVectors(Enum64.class, 1L << 32));
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, (1L << 63))); assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, 1L << 63));
assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, Long.MIN_VALUE)); assertEquals(EnumSet.of(Enum64.A63), EnumUtils.processBitVectors(Enum64.class, Long.MIN_VALUE));
} }

View File

@ -227,42 +227,42 @@ public class FunctionsTest extends AbstractLangTest {
public void testDouble(final double i) throws Throwable { public void testDouble(final double i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i); acceptedPrimitiveObject1 = (P) (Double) i;
} }
public double testDoubleDouble(final double i, final double j) throws Throwable { public double testDoubleDouble(final double i, final double j) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Double) i); acceptedPrimitiveObject1 = (P) (Double) i;
acceptedPrimitiveObject2 = (P) ((Double) j); acceptedPrimitiveObject2 = (P) (Double) j;
return 3d; return 3d;
} }
public void testInt(final int i) throws Throwable { public void testInt(final int i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Integer) i); acceptedPrimitiveObject1 = (P) (Integer) i;
} }
public void testLong(final long i) throws Throwable { public void testLong(final long i) throws Throwable {
test(throwable); test(throwable);
acceptedPrimitiveObject1 = (P) ((Long) i); acceptedPrimitiveObject1 = (P) (Long) i;
} }
public void testObjDouble(final T object, final double i) throws Throwable { public void testObjDouble(final T object, final double i) throws Throwable {
test(throwable); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Double) i); acceptedPrimitiveObject1 = (P) (Double) i;
} }
public void testObjInt(final T object, final int i) throws Throwable { public void testObjInt(final T object, final int i) throws Throwable {
test(throwable); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Integer) i); acceptedPrimitiveObject1 = (P) (Integer) i;
} }
public void testObjLong(final T object, final long i) throws Throwable { public void testObjLong(final T object, final long i) throws Throwable {
test(throwable); test(throwable);
acceptedObject = object; acceptedObject = object;
acceptedPrimitiveObject1 = (P) ((Long) i); acceptedPrimitiveObject1 = (P) (Long) i;
} }
} }

View File

@ -63,7 +63,7 @@ public class JavaVersionTest extends AbstractLangTest {
assertEquals(JAVA_1_7, get("1.7"), "1.7 failed"); assertEquals(JAVA_1_7, get("1.7"), "1.7 failed");
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed"); assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
int lastSupportedVersion = Integer.parseInt(JavaVersion.values()[JavaVersion.values().length - 2].toString()); final int lastSupportedVersion = Integer.parseInt(JavaVersion.values()[JavaVersion.values().length - 2].toString());
for (int i = 9; i <= lastSupportedVersion; i++) { for (int i = 9; i <= lastSupportedVersion; i++) {
assertEquals(JavaVersion.class.getField("JAVA_" + i).get(null), get("" + i), i + " failed"); assertEquals(JavaVersion.class.getField("JAVA_" + i).get(null), get("" + i), i + " failed");
} }

View File

@ -31,7 +31,6 @@ import java.lang.reflect.Modifier;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -71,11 +70,9 @@ public class LocaleUtilsTest extends AbstractLangTest {
assertSame(list, list2); assertSame(list, list2);
//search through languages //search through languages
for (final String country : countries) { for (final String country : countries) {
final Iterator<Locale> iterator = list.iterator();
boolean found = false; boolean found = false;
// see if it was returned by the set // see if it was returned by the set
while (iterator.hasNext()) { for (Locale locale : list) {
final Locale locale = iterator.next();
// should have an en empty variant // should have an en empty variant
assertTrue(StringUtils.isEmpty(locale.getVariant())); assertTrue(StringUtils.isEmpty(locale.getVariant()));
assertEquals(language, locale.getLanguage()); assertEquals(language, locale.getLanguage());
@ -105,11 +102,9 @@ public class LocaleUtilsTest extends AbstractLangTest {
assertSame(list, list2); assertSame(list, list2);
//search through languages //search through languages
for (final String language : languages) { for (final String language : languages) {
final Iterator<Locale> iterator = list.iterator();
boolean found = false; boolean found = false;
// see if it was returned by the set // see if it was returned by the set
while (iterator.hasNext()) { for (Locale locale : list) {
final Locale locale = iterator.next();
// should have an en empty variant // should have an en empty variant
assertTrue(StringUtils.isEmpty(locale.getVariant())); assertTrue(StringUtils.isEmpty(locale.getVariant()));
assertEquals(country, locale.getCountry()); assertEquals(country, locale.getCountry());

View File

@ -563,7 +563,7 @@ public class ObjectUtilsTest extends AbstractLangTest {
assertThrows( assertThrows(
NullPointerException.class, NullPointerException.class,
() -> ObjectUtils.identityToString((Appendable) (new StringBuilder()), null)); () -> ObjectUtils.identityToString((Appendable) new StringBuilder(), null));
} }
@Test @Test

View File

@ -52,7 +52,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
private double chiSquare(final int[] expected, final int[] observed) { private double chiSquare(final int[] expected, final int[] observed) {
double sumSq = 0.0d; double sumSq = 0.0d;
for (int i = 0; i < observed.length; i++) { for (int i = 0; i < observed.length; i++) {
double dev = observed[i] - expected[i]; final double dev = observed[i] - expected[i];
sumSq += dev * dev / expected[i]; sumSq += dev * dev / expected[i];
} }
return sumSq; return sumSq;
@ -416,7 +416,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
r1 = RandomStringUtils.randomAscii(50); r1 = RandomStringUtils.randomAscii(50);
assertEquals(50, r1.length(), "randomAscii(50) length"); assertEquals(50, r1.length(), "randomAscii(50) length");
for (int i = 0; i < r1.length(); i++) { for (int i = 0; i < r1.length(); i++) {
assertThat("char >= 32 && <= 127", ((int) r1.charAt(i)), allOf(greaterThanOrEqualTo(32), lessThanOrEqualTo(127))); assertThat("char >= 32 && <= 127", (int) r1.charAt(i), allOf(greaterThanOrEqualTo(32), lessThanOrEqualTo(127)));
} }
r2 = RandomStringUtils.randomAscii(50); r2 = RandomStringUtils.randomAscii(50);
assertFalse(r1.equals(r2), "!r1.equals(r2)"); assertFalse(r1.equals(r2), "!r1.equals(r2)");
@ -513,7 +513,7 @@ public class RandomStringUtilsTest extends AbstractLangTest {
final int[] counts = {0, 0, 0}; final int[] counts = {0, 0, 0};
final int[] expected = {200, 200, 200}; final int[] expected = {200, 200, 200};
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
String gen = RandomStringUtils.random(6, chars); final String gen = RandomStringUtils.random(6, chars);
for (int j = 0; j < 6; j++) { for (int j = 0; j < 6; j++) {
switch (gen.charAt(j)) { switch (gen.charAt(j)) {
case 'a': { case 'a': {

View File

@ -117,16 +117,16 @@ public class RangeTest extends AbstractLangTest {
final DerivedComparableA derivedComparableA = new DerivedComparableA(); final DerivedComparableA derivedComparableA = new DerivedComparableA();
final DerivedComparableB derivedComparableB = new DerivedComparableB(); final DerivedComparableB derivedComparableB = new DerivedComparableB();
Range<AbstractComparable> mixed = Range.between(derivedComparableA, derivedComparableB, null); final Range<AbstractComparable> mixed = Range.between(derivedComparableA, derivedComparableB, null);
assertTrue(mixed.contains(derivedComparableA)); assertTrue(mixed.contains(derivedComparableA));
Range<AbstractComparable> same = Range.between(derivedComparableA, derivedComparableA, null); final Range<AbstractComparable> same = Range.between(derivedComparableA, derivedComparableA, null);
assertTrue(same.contains(derivedComparableA)); assertTrue(same.contains(derivedComparableA));
Range<DerivedComparableA> rangeA = Range.between(derivedComparableA, derivedComparableA, null); final Range<DerivedComparableA> rangeA = Range.between(derivedComparableA, derivedComparableA, null);
assertTrue(rangeA.contains(derivedComparableA)); assertTrue(rangeA.contains(derivedComparableA));
Range<DerivedComparableB> rangeB = Range.is(derivedComparableB, null); final Range<DerivedComparableB> rangeB = Range.is(derivedComparableB, null);
assertTrue(rangeB.contains(derivedComparableB)); assertTrue(rangeB.contains(derivedComparableB));
} }

View File

@ -63,7 +63,7 @@ public class StringEscapeUtilsTest extends AbstractLangTest {
private void assertEscapeJava(String message, final String expected, final String original) throws IOException { private void assertEscapeJava(String message, final String expected, final String original) throws IOException {
final String converted = StringEscapeUtils.escapeJava(original); final String converted = StringEscapeUtils.escapeJava(original);
message = "escapeJava(String) failed" + (message == null ? "" : (": " + message)); message = "escapeJava(String) failed" + (message == null ? "" : ": " + message);
assertEquals(expected, converted, message); assertEquals(expected, converted, message);
final StringWriter writer = new StringWriter(); final StringWriter writer = new StringWriter();
@ -81,7 +81,7 @@ public class StringEscapeUtilsTest extends AbstractLangTest {
assertEquals(expected, actual, assertEquals(expected, actual,
"unescape(String) failed" + "unescape(String) failed" +
(message == null ? "" : (": " + message)) + (message == null ? "" : ": " + message) +
": expected '" + StringEscapeUtils.escapeJava(expected) + ": expected '" + StringEscapeUtils.escapeJava(expected) +
// we escape this so we can see it in the error message // we escape this so we can see it in the error message
"' actual '" + StringEscapeUtils.escapeJava(actual) + "'"); "' actual '" + StringEscapeUtils.escapeJava(actual) + "'");
@ -488,8 +488,8 @@ public class StringEscapeUtilsTest extends AbstractLangTest {
final Character c1 = Character.valueOf(i); final Character c1 = Character.valueOf(i);
final Character c2 = Character.valueOf((char) (i+1)); final Character c2 = Character.valueOf((char) (i+1));
final String expected = c1.toString() + c2; final String expected = c1.toString() + c2;
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";"; final String escapedC1 = "&#x" + Integer.toHexString(c1.charValue()) + ";";
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";"; final String escapedC2 = "&#x" + Integer.toHexString(c2.charValue()) + ";";
assertEquals(expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2), "hex number unescape index " + (int) i); assertEquals(expected, StringEscapeUtils.unescapeHtml4(escapedC1 + escapedC2), "hex number unescape index " + (int) i);
} }
} }

View File

@ -167,10 +167,10 @@ public class StringUtilsContainsTest extends AbstractLangTest {
assertFalse(StringUtils.containsAny("", new String[] { "hello" })); assertFalse(StringUtils.containsAny("", new String[] { "hello" }));
assertFalse(StringUtils.containsAny("hello, goodbye", (String[]) null)); assertFalse(StringUtils.containsAny("hello, goodbye", (String[]) null));
assertFalse(StringUtils.containsAny("hello, goodbye", new String[0])); assertFalse(StringUtils.containsAny("hello, goodbye", new String[0]));
assertTrue(StringUtils.containsAny("hello, goodbye", new String[]{"hello", "goodbye"})); assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "goodbye" }));
assertTrue(StringUtils.containsAny("hello, goodbye", new String[]{"hello", "Goodbye"})); assertTrue(StringUtils.containsAny("hello, goodbye", new String[] { "hello", "Goodbye" }));
assertFalse(StringUtils.containsAny("hello, goodbye", new String[]{"Hello", "Goodbye"})); assertFalse(StringUtils.containsAny("hello, goodbye", new String[] { "Hello", "Goodbye" }));
assertFalse(StringUtils.containsAny("hello, goodbye", new String[]{"Hello", null})); assertFalse(StringUtils.containsAny("hello, goodbye", new String[] { "Hello", null }));
assertFalse(StringUtils.containsAny("hello, null", new String[] { "Hello", null })); assertFalse(StringUtils.containsAny("hello, null", new String[] { "Hello", null }));
// Javadoc examples: // Javadoc examples:
assertTrue(StringUtils.containsAny("abcd", "ab", null)); assertTrue(StringUtils.containsAny("abcd", "ab", null));

View File

@ -56,7 +56,7 @@ public class SystemUtilsTest extends AbstractLangTest {
/** /**
* Returns the value of the SystemUtils.IS_JAVA_X field for the versions >= 9. * Returns the value of the SystemUtils.IS_JAVA_X field for the versions >= 9.
*/ */
private boolean getIS_JAVA(int version) throws Exception { private boolean getIS_JAVA(final int version) throws Exception {
return SystemUtils.class.getField("IS_JAVA_" + version).getBoolean(null); return SystemUtils.class.getField("IS_JAVA_" + version).getBoolean(null);
} }
@ -66,7 +66,7 @@ public class SystemUtilsTest extends AbstractLangTest {
public int getLastSupportedJavaVersion() { public int getLastSupportedJavaVersion() {
int lastSupportedVersion = 0; int lastSupportedVersion = 0;
for (Field field : SystemUtils.class.getFields()) { for (final Field field : SystemUtils.class.getFields()) {
if (field.getName().matches("IS_JAVA_\\d+")) { if (field.getName().matches("IS_JAVA_\\d+")) {
lastSupportedVersion = Math.max(lastSupportedVersion, Integer.parseInt(field.getName().substring(8))); lastSupportedVersion = Math.max(lastSupportedVersion, Integer.parseInt(field.getName().substring(8)));
} }
@ -78,8 +78,8 @@ public class SystemUtilsTest extends AbstractLangTest {
@Test @Test
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void test_IS_JAVA() throws Exception { public void test_IS_JAVA() throws Exception {
String javaVersion = SystemUtils.JAVA_VERSION; final String javaVersion = SystemUtils.JAVA_VERSION;
int lastSupportedVersion = getLastSupportedJavaVersion(); final int lastSupportedVersion = getLastSupportedJavaVersion();
if (javaVersion == null) { if (javaVersion == null) {
assertFalse(SystemUtils.IS_JAVA_1_1); assertFalse(SystemUtils.IS_JAVA_1_1);

View File

@ -155,14 +155,14 @@ public class ThreadUtilsTest extends AbstractLangTest {
@Test @Test
public void testGetAllThreadGroupsDoesNotReturnNull() { public void testGetAllThreadGroupsDoesNotReturnNull() {
// LANG-1706 getAllThreadGroups and findThreadGroups should not return null items // LANG-1706 getAllThreadGroups and findThreadGroups should not return null items
Collection<ThreadGroup> threads = ThreadUtils.getAllThreadGroups(); final Collection<ThreadGroup> threads = ThreadUtils.getAllThreadGroups();
assertEquals(0, threads.stream().filter(Objects::isNull).count()); assertEquals(0, threads.stream().filter(Objects::isNull).count());
} }
@Test @Test
public void testGetAllThreadsDoesNotReturnNull() { public void testGetAllThreadsDoesNotReturnNull() {
// LANG-1706 getAllThreads and findThreads should not return null items // LANG-1706 getAllThreads and findThreads should not return null items
Collection<Thread> threads = ThreadUtils.getAllThreads(); final Collection<Thread> threads = ThreadUtils.getAllThreads();
assertEquals(0, threads.stream().filter(Objects::isNull).count()); assertEquals(0, threads.stream().filter(Objects::isNull).count());
} }

View File

@ -837,7 +837,7 @@ public class ValidateTest extends AbstractLangTest {
@Test @Test
void shouldReturnSameInstance() { void shouldReturnSameInstance() {
final String[] expected = new String[] {"a", "b"}; final String[] expected = {"a", "b"};
assertSame(expected, Validate.noNullElements(expected)); assertSame(expected, Validate.noNullElements(expected));
} }
@ -1032,7 +1032,7 @@ public class ValidateTest extends AbstractLangTest {
@Test @Test
void shouldReturnTheSameInstance() { void shouldReturnTheSameInstance() {
final String[] expected = new String[] {"hi"}; final String[] expected = {"hi"};
assertSame(expected, Validate.notEmpty(expected, "MSG")); assertSame(expected, Validate.notEmpty(expected, "MSG"));
} }
@ -1059,7 +1059,7 @@ public class ValidateTest extends AbstractLangTest {
@Test @Test
void shouldReturnTheSameInstance() { void shouldReturnTheSameInstance() {
final String[] expected = new String[] {"hi"}; final String[] expected = {"hi"};
assertSame(expected, Validate.notEmpty(expected)); assertSame(expected, Validate.notEmpty(expected));
} }

View File

@ -128,13 +128,13 @@ public class HashCodeBuilderTest extends AbstractLangTest {
static class TestObjectWithMultipleFields { static class TestObjectWithMultipleFields {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private int one; private final int one;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private int two; private final int two;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private int three; private final int three;
TestObjectWithMultipleFields(final int one, final int two, final int three) { TestObjectWithMultipleFields(final int one, final int two, final int three) {
this.one = one; this.one = one;

View File

@ -33,12 +33,12 @@ public class ReflectionToStringBuilderCustomImplementationTest extends AbstractL
private static final String CUSTOM_PREFIX = "prefix:"; private static final String CUSTOM_PREFIX = "prefix:";
public CustomReflectionToStringBuilder(Object object, ToStringStyle toStringStyle) { public CustomReflectionToStringBuilder(final Object object, final ToStringStyle toStringStyle) {
super(object, toStringStyle); super(object, toStringStyle);
} }
@Override @Override
protected Object getValue(Field field) throws IllegalAccessException { protected Object getValue(final Field field) throws IllegalAccessException {
return CUSTOM_PREFIX + super.getValue(field); return CUSTOM_PREFIX + super.getValue(field);
} }
} }

View File

@ -136,7 +136,7 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
@Test @Test
public void test_toStringIncludeNullArrayMultiplesValues() { public void test_toStringIncludeNullArrayMultiplesValues() {
final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), new String[] {null, null, null, null}); final String toString = ReflectionToStringBuilder.toStringInclude(new TestFeature(), null, null, null, null);
this.validateAllFieldsPresent(toString); this.validateAllFieldsPresent(toString);
} }
@ -193,8 +193,8 @@ public class ReflectionToStringBuilderIncludeTest extends AbstractLangTest {
@Test @Test
public void test_toStringSetIncludeWithArrayWithMultipleNullFields() { public void test_toStringSetIncludeWithArrayWithMultipleNullFields() {
final ReflectionToStringBuilder builder = new ReflectionToStringBuilder(new TestFeature()); final ReflectionToStringBuilder builder = new ReflectionToStringBuilder(new TestFeature());
builder.setExcludeFieldNames(new String[] {FIELDS[1], FIELDS[4]}); builder.setExcludeFieldNames(FIELDS[1], FIELDS[4]);
builder.setIncludeFieldNames(new String[] {null, null, null}); builder.setIncludeFieldNames(null, null, null);
final String toString = builder.toString(); final String toString = builder.toString();
this.validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]}); this.validateIncludeFieldsPresent(toString, new String[]{FIELDS[0], FIELDS[2], FIELDS[3]}, new String[]{VALUES[0], VALUES[2], VALUES[3]});
} }

View File

@ -123,42 +123,42 @@ public class StandardToStringStyleTest extends AbstractLangTest {
@Test @Test
public void testDefaultIsArrayContentDetail() { public void testDefaultIsArrayContentDetail() {
assertTrue((new StandardToStringStyle()).isArrayContentDetail()); assertTrue(new StandardToStringStyle().isArrayContentDetail());
} }
@Test @Test
public void testDefaultIsFieldSeparatorAtEnd() { public void testDefaultIsFieldSeparatorAtEnd() {
assertFalse((new StandardToStringStyle()).isFieldSeparatorAtEnd()); assertFalse(new StandardToStringStyle().isFieldSeparatorAtEnd());
} }
@Test @Test
public void testDefaultIsFieldSeparatorAtStart() { public void testDefaultIsFieldSeparatorAtStart() {
assertFalse((new StandardToStringStyle()).isFieldSeparatorAtStart()); assertFalse(new StandardToStringStyle().isFieldSeparatorAtStart());
} }
@Test @Test
public void testDefaultValueOfFullDetail() { public void testDefaultValueOfFullDetail() {
assertTrue((new StandardToStringStyle()).isDefaultFullDetail()); assertTrue(new StandardToStringStyle().isDefaultFullDetail());
} }
@Test @Test
public void testDefaultValueOfUseClassName() { public void testDefaultValueOfUseClassName() {
assertTrue((new StandardToStringStyle()).isUseClassName()); assertTrue(new StandardToStringStyle().isUseClassName());
} }
@Test @Test
public void testDefaultValueOfUseFieldNames() { public void testDefaultValueOfUseFieldNames() {
assertTrue((new StandardToStringStyle()).isUseFieldNames()); assertTrue(new StandardToStringStyle().isUseFieldNames());
} }
@Test @Test
public void testDefaultValueOfUseIdentityHashCode() { public void testDefaultValueOfUseIdentityHashCode() {
assertTrue((new StandardToStringStyle()).isUseIdentityHashCode()); assertTrue(new StandardToStringStyle().isUseIdentityHashCode());
} }
@Test @Test
public void testDefaultValueOfUseShortClassName() { public void testDefaultValueOfUseShortClassName() {
assertFalse((new StandardToStringStyle()).isUseShortClassName()); assertFalse(new StandardToStringStyle().isUseShortClassName());
} }
@Test @Test

View File

@ -258,7 +258,7 @@ public class ToStringBuilderTest extends AbstractLangTest {
@Test @Test
public void testAppendAsObjectToStringNullPointerException() { public void testAppendAsObjectToStringNullPointerException() {
ToStringBuilder builder = new ToStringBuilder(1); final ToStringBuilder builder = new ToStringBuilder(1);
assertThrows(NullPointerException.class, () -> builder.appendAsObjectToString(null)); assertThrows(NullPointerException.class, () -> builder.appendAsObjectToString(null));
builder.toString(); builder.toString();
} }

View File

@ -61,7 +61,7 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend
// The use of enums rather than accepting an Exception as the input means we can have // The use of enums rather than accepting an Exception as the input means we can have
// multiple exception types on the method signature. // multiple exception types on the method signature.
protected static CloseableObject methodThatThrowsException(ExceptionToThrow input) throws IOException, SQLException, ConcurrentException { protected static CloseableObject methodThatThrowsException(final ExceptionToThrow input) throws IOException, SQLException, ConcurrentException {
switch (input) { switch (input) {
case IOException: case IOException:
throw new IOException(); throw new IOException();
@ -87,12 +87,12 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend
public void testCloserThrowsCheckedException() throws ConcurrentException { public void testCloserThrowsCheckedException() throws ConcurrentException {
final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException( final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException(
CloseableObject::new, CloseableObject::new,
(CloseableObject) -> methodThatThrowsException(ExceptionToThrow.IOException)); CloseableObject -> methodThatThrowsException(ExceptionToThrow.IOException));
try { try {
initializer.get(); initializer.get();
((AbstractConcurrentInitializer) initializer).close(); ((AbstractConcurrentInitializer) initializer).close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
assertThat(e, instanceOf(ConcurrentException.class)); assertThat(e, instanceOf(ConcurrentException.class));
assertThat(e.getCause(), instanceOf(IOException.class)); assertThat(e.getCause(), instanceOf(IOException.class));
} }
@ -107,7 +107,7 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend
public void testCloserThrowsRuntimeException() throws ConcurrentException { public void testCloserThrowsRuntimeException() throws ConcurrentException {
final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException( final ConcurrentInitializer<CloseableObject> initializer = createInitializerThatThrowsException(
CloseableObject::new, CloseableObject::new,
(CloseableObject) -> methodThatThrowsException(ExceptionToThrow.NullPointerException)); CloseableObject -> methodThatThrowsException(ExceptionToThrow.NullPointerException));
initializer.get(); initializer.get();
assertThrows(NullPointerException.class, () -> { assertThrows(NullPointerException.class, () -> {
@ -148,7 +148,7 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend
try { try {
initializer.get(); initializer.get();
fail(); fail();
} catch (ConcurrentException e) { } catch (final ConcurrentException e) {
assertEquals(concurrentException, e); assertEquals(concurrentException, e);
} }
} }
@ -176,7 +176,7 @@ public abstract class AbstractConcurrentInitializerCloseAndExceptionsTest extend
CloseableObject::new, CloseableObject::new,
CloseableObject::close); CloseableObject::close);
CloseableObject closeableObject = initializer.get(); final CloseableObject closeableObject = initializer.get();
assertFalse(closeableObject.isClosed()); assertFalse(closeableObject.isClosed());
((AbstractConcurrentInitializer) initializer).close(); ((AbstractConcurrentInitializer) initializer).close();
assertTrue(closeableObject.isClosed()); assertTrue(closeableObject.isClosed());

View File

@ -128,7 +128,7 @@ public abstract class AbstractConcurrentInitializerTest extends AbstractLangTest
public void testisInitialized() throws Throwable { public void testisInitialized() throws Throwable {
final ConcurrentInitializer<Object> initializer = createInitializer(); final ConcurrentInitializer<Object> initializer = createInitializer();
if (initializer instanceof AbstractConcurrentInitializer) { if (initializer instanceof AbstractConcurrentInitializer) {
AbstractConcurrentInitializer castedInitializer = (AbstractConcurrentInitializer) initializer; final AbstractConcurrentInitializer castedInitializer = (AbstractConcurrentInitializer) initializer;
assertFalse(castedInitializer.isInitialized(), "was initialized before get()"); assertFalse(castedInitializer.isInitialized(), "was initialized before get()");
assertNotNull(castedInitializer.get(), "No managed object"); assertNotNull(castedInitializer.get(), "No managed object");
assertTrue(castedInitializer.isInitialized(), "was not initialized after get()"); assertTrue(castedInitializer.isInitialized(), "was not initialized after get()");

View File

@ -30,7 +30,7 @@ public class AtomicInitializerSupplierTest extends AbstractConcurrentInitializer
*/ */
@Override @Override
protected ConcurrentInitializer<Object> createInitializer() { protected ConcurrentInitializer<Object> createInitializer() {
return AtomicInitializer.<Object>builder().setInitializer(() -> new Object()).get(); return AtomicInitializer.<Object>builder().setInitializer(Object::new).get();
} }
@Override @Override

View File

@ -50,9 +50,8 @@ public class AtomicInitializerTest extends AbstractConcurrentInitializerTest {
protected Object initialize() { protected Object initialize() {
if (firstRun.getAndSet(false)) { if (firstRun.getAndSet(false)) {
return null; return null;
} else {
return new Object();
} }
return new Object();
} }
}; };

View File

@ -72,9 +72,8 @@ public class AtomicSafeInitializerSupplierTest extends AbstractConcurrentInitial
protected Object initialize() { protected Object initialize() {
if (firstRun.getAndSet(false)) { if (firstRun.getAndSet(false)) {
return null; return null;
} else {
return new Object();
} }
return new Object();
} }
}; };

View File

@ -74,9 +74,8 @@ public class AtomicSafeInitializerTest extends AbstractConcurrentInitializerTest
protected Object initialize() { protected Object initialize() {
if (firstRun.getAndSet(false)) { if (firstRun.getAndSet(false)) {
return null; return null;
} else {
return new Object();
} }
return new Object();
} }
}; };

View File

@ -40,29 +40,27 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
protected static final class SupplierBackgroundInitializerTestImpl extends AbstractBackgroundInitializerTestImpl { protected static final class SupplierBackgroundInitializerTestImpl extends AbstractBackgroundInitializerTestImpl {
SupplierBackgroundInitializerTestImpl() { SupplierBackgroundInitializerTestImpl() {
super(); setSupplierAndCloser((final CloseableCounter cc) -> cc.close());
setSupplierAndCloser((CloseableCounter cc) -> cc.close());
} }
SupplierBackgroundInitializerTestImpl(final ExecutorService exec) { SupplierBackgroundInitializerTestImpl(final ExecutorService exec) {
super(exec); super(exec);
setSupplierAndCloser((CloseableCounter cc) -> cc.close()); setSupplierAndCloser((final CloseableCounter cc) -> cc.close());
} }
SupplierBackgroundInitializerTestImpl(FailableConsumer<?, ?> consumer) { SupplierBackgroundInitializerTestImpl(final FailableConsumer<?, ?> consumer) {
super();
setSupplierAndCloser(consumer); setSupplierAndCloser(consumer);
} }
private void setSupplierAndCloser(FailableConsumer<?, ?> consumer) { private void setSupplierAndCloser(final FailableConsumer<?, ?> consumer) {
try { try {
// Use reflection here because the constructors we need are private // Use reflection here because the constructors we need are private
FailableSupplier<?, ?> supplier = () -> initializeInternal(); final FailableSupplier<?, ?> supplier = this::initializeInternal;
Field initializer = AbstractConcurrentInitializer.class.getDeclaredField("initializer"); final Field initializer = AbstractConcurrentInitializer.class.getDeclaredField("initializer");
initializer.setAccessible(true); initializer.setAccessible(true);
initializer.set(this, supplier); initializer.set(this, supplier);
Field closer = AbstractConcurrentInitializer.class.getDeclaredField("closer"); final Field closer = AbstractConcurrentInitializer.class.getDeclaredField("closer");
closer.setAccessible(true); closer.setAccessible(true);
closer.set(this, consumer); closer.set(this, consumer);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
@ -71,10 +69,12 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
} }
} }
@Override
protected AbstractBackgroundInitializerTestImpl getBackgroundInitializerTestImpl() { protected AbstractBackgroundInitializerTestImpl getBackgroundInitializerTestImpl() {
return new SupplierBackgroundInitializerTestImpl(); return new SupplierBackgroundInitializerTestImpl();
} }
@Override
protected SupplierBackgroundInitializerTestImpl getBackgroundInitializerTestImpl(final ExecutorService exec) { protected SupplierBackgroundInitializerTestImpl getBackgroundInitializerTestImpl(final ExecutorService exec) {
return new SupplierBackgroundInitializerTestImpl(exec); return new SupplierBackgroundInitializerTestImpl(exec);
} }
@ -106,7 +106,7 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
public void testCloseWithCheckedException() throws Exception { public void testCloseWithCheckedException() throws Exception {
final IOException ioException = new IOException(); final IOException ioException = new IOException();
final FailableConsumer<?, ?> IOExceptionConsumer = (CloseableCounter cc) -> { final FailableConsumer<?, ?> IOExceptionConsumer = (final CloseableCounter cc) -> {
throw ioException; throw ioException;
}; };
@ -116,7 +116,7 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
try { try {
init.close(); init.close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
assertThat(e, instanceOf(ConcurrentException.class)); assertThat(e, instanceOf(ConcurrentException.class));
assertSame(ioException, e.getCause()); assertSame(ioException, e.getCause());
} }
@ -131,7 +131,7 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
public void testCloseWithRuntimeException() throws Exception { public void testCloseWithRuntimeException() throws Exception {
final NullPointerException npe = new NullPointerException(); final NullPointerException npe = new NullPointerException();
final FailableConsumer<?, ?> NullPointerExceptionConsumer = (CloseableCounter cc) -> { final FailableConsumer<?, ?> NullPointerExceptionConsumer = (final CloseableCounter cc) -> {
throw npe; throw npe;
}; };
@ -141,7 +141,7 @@ public class BackgroundInitializerSupplierTest extends BackgroundInitializerTest
try { try {
init.close(); init.close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
assertSame(npe, e); assertSame(npe, e);
} }
} }

View File

@ -31,7 +31,7 @@ public class LazyInitializerSupplierTest extends AbstractConcurrentInitializerCl
*/ */
@Override @Override
protected ConcurrentInitializer<Object> createInitializer() { protected ConcurrentInitializer<Object> createInitializer() {
return LazyInitializer.<Object>builder().setInitializer(() -> new Object()).get(); return LazyInitializer.<Object>builder().setInitializer(Object::new).get();
} }
@Override @Override

View File

@ -43,13 +43,13 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
private static final class SupplierChildBackgroundInitializer extends AbstractChildBackgroundInitializer { private static final class SupplierChildBackgroundInitializer extends AbstractChildBackgroundInitializer {
SupplierChildBackgroundInitializer() { SupplierChildBackgroundInitializer() {
this((CloseableCounter cc) -> cc.close()); this((final CloseableCounter cc) -> cc.close());
} }
SupplierChildBackgroundInitializer(FailableConsumer<?, ?> consumer) { SupplierChildBackgroundInitializer(final FailableConsumer<?, ?> consumer) {
try { try {
// Use reflection here because the constructors we need are private // Use reflection here because the constructors we need are private
final FailableSupplier<?, ?> supplier = () -> initializeInternal(); final FailableSupplier<?, ?> supplier = this::initializeInternal;
final Field initializer = AbstractConcurrentInitializer.class.getDeclaredField("initializer"); final Field initializer = AbstractConcurrentInitializer.class.getDeclaredField("initializer");
initializer.setAccessible(true); initializer.setAccessible(true);
initializer.set(this, supplier); initializer.set(this, supplier);
@ -80,10 +80,10 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
public void setUpException() throws Exception { public void setUpException() throws Exception {
npe = new NullPointerException(); npe = new NullPointerException();
ioException = new IOException(); ioException = new IOException();
ioExceptionConsumer = (CloseableCounter cc) -> { ioExceptionConsumer = (final CloseableCounter cc) -> {
throw ioException; throw ioException;
}; };
nullPointerExceptionConsumer = (CloseableCounter cc) -> { nullPointerExceptionConsumer = (final CloseableCounter cc) -> {
throw npe; throw npe;
}; };
} }
@ -109,9 +109,9 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
initializer.start(); initializer.start();
long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
long waitTime = 3000; final long waitTime = 3000;
long endTime = startTime + waitTime; final long endTime = startTime + waitTime;
//wait for the children to start //wait for the children to start
while (!childOne.isStarted() || !childTwo.isStarted()) { while (!childOne.isStarted() || !childTwo.isStarted()) {
if (System.currentTimeMillis() > endTime) { if (System.currentTimeMillis() > endTime) {
@ -131,7 +131,7 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
try { try {
initializer.close(); initializer.close();
} catch (Exception e) { } catch (final Exception e) {
fail(); fail();
} }
@ -151,9 +151,9 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
initializer.addInitializer("child one", childOne); initializer.addInitializer("child one", childOne);
initializer.start(); initializer.start();
long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
long waitTime = 3000; final long waitTime = 3000;
long endTime = startTime + waitTime; final long endTime = startTime + waitTime;
//wait for the children to start //wait for the children to start
while (! childOne.isStarted()) { while (! childOne.isStarted()) {
if (System.currentTimeMillis() > endTime) { if (System.currentTimeMillis() > endTime) {
@ -166,7 +166,7 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
try { try {
initializer.close(); initializer.close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
assertThat(e, instanceOf(ConcurrentException.class)); assertThat(e, instanceOf(ConcurrentException.class));
assertSame(ioException, e.getSuppressed()[0]); assertSame(ioException, e.getSuppressed()[0]);
} }
@ -184,9 +184,9 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
initializer.addInitializer("child one", childOne); initializer.addInitializer("child one", childOne);
initializer.start(); initializer.start();
long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
long waitTime = 3000; final long waitTime = 3000;
long endTime = startTime + waitTime; final long endTime = startTime + waitTime;
//wait for the children to start //wait for the children to start
while (! childOne.isStarted()) { while (! childOne.isStarted()) {
if (System.currentTimeMillis() > endTime) { if (System.currentTimeMillis() > endTime) {
@ -199,7 +199,7 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
try { try {
initializer.close(); initializer.close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
assertThat(e, instanceOf(ConcurrentException.class)); assertThat(e, instanceOf(ConcurrentException.class));
assertSame(npe, e.getSuppressed()[0]); assertSame(npe, e.getSuppressed()[0]);
} }
@ -240,12 +240,12 @@ public class MultiBackgroundInitializerSupplierTest extends MultiBackgroundIniti
try { try {
initializer.close(); initializer.close();
fail(); fail();
} catch (Exception e) { } catch (final Exception e) {
// We don't actually know which order the children will be closed in // We don't actually know which order the children will be closed in
boolean foundChildOneException = false; boolean foundChildOneException = false;
boolean foundChildTwoException = false; boolean foundChildTwoException = false;
for (Throwable t : e.getSuppressed()) { for (final Throwable t : e.getSuppressed()) {
if (t.equals(ioException)) { if (t.equals(ioException)) {
foundChildOneException = true; foundChildOneException = true;
} }

View File

@ -95,7 +95,7 @@ public class MultiBackgroundInitializerTest extends AbstractLangTest {
protected static class CloseableCounter { protected static class CloseableCounter {
// A convenience for testing that a CloseableCounter typed as Object has a specific initializeCalls value // A convenience for testing that a CloseableCounter typed as Object has a specific initializeCalls value
public static CloseableCounter wrapInteger(int i) { public static CloseableCounter wrapInteger(final int i) {
return new CloseableCounter().setInitializeCalls(i); return new CloseableCounter().setInitializeCalls(i);
} }
@ -130,7 +130,7 @@ public class MultiBackgroundInitializerTest extends AbstractLangTest {
return closed; return closed;
} }
public CloseableCounter setInitializeCalls(int i) { public CloseableCounter setInitializeCalls(final int i) {
initializeCalls = i; initializeCalls = i;
return this; return this;
} }
@ -437,9 +437,9 @@ public class MultiBackgroundInitializerTest extends AbstractLangTest {
initializer.addInitializer("child two", childTwo); initializer.addInitializer("child two", childTwo);
initializer.start(); initializer.start();
long startTime = System.currentTimeMillis(); final long startTime = System.currentTimeMillis();
long waitTime = 3000; final long waitTime = 3000;
long endTime = startTime + waitTime; final long endTime = startTime + waitTime;
//wait for the children to start //wait for the children to start
while (! childOne.isStarted() || ! childTwo.isStarted()) { while (! childOne.isStarted() || ! childTwo.isStarted()) {
if (System.currentTimeMillis() > endTime) { if (System.currentTimeMillis() > endTime) {

View File

@ -644,7 +644,7 @@ public class NumberUtilsTest extends AbstractLangTest {
assertEquals(new BigDecimal("1.7976931348623159e+308"), NumberUtils.createNumber("1.7976931348623159e+308")); assertEquals(new BigDecimal("1.7976931348623159e+308"), NumberUtils.createNumber("1.7976931348623159e+308"));
// Requested type is parsed as zero but the value is not zero // Requested type is parsed as zero but the value is not zero
final Double nonZero1 = Double.valueOf(((double) Float.MIN_VALUE) / 2); final Double nonZero1 = Double.valueOf((double) Float.MIN_VALUE / 2);
assertEquals(nonZero1, NumberUtils.createNumber(nonZero1.toString())); assertEquals(nonZero1, NumberUtils.createNumber(nonZero1.toString()));
assertEquals(nonZero1, NumberUtils.createNumber(nonZero1 + "F")); assertEquals(nonZero1, NumberUtils.createNumber(nonZero1 + "F"));
// Smallest double is 4.9e-324. // Smallest double is 4.9e-324.

View File

@ -26,7 +26,7 @@ import org.apache.commons.lang3.time.DurationUtils;
*/ */
public class PrintAtomicVsMutable { public class PrintAtomicVsMutable {
public static void main(String[] args) { public static void main(final String[] args) {
final MutableInt mInt = new MutableInt(); final MutableInt mInt = new MutableInt();
final int max = 100_000_000; final int max = 100_000_000;
System.out.println("MutableInt " + DurationUtils.of(() -> { System.out.println("MutableInt " + DurationUtils.of(() -> {

View File

@ -665,19 +665,19 @@ public class StrBuilderTest extends AbstractLangTest {
assertTrue(sb1.equals(sb2)); assertTrue(sb1.equals(sb2));
assertTrue(sb1.equals(sb1)); assertTrue(sb1.equals(sb1));
assertTrue(sb2.equals(sb2)); assertTrue(sb2.equals(sb2));
assertEquals(sb1, (Object) sb2); assertEquals(sb1, sb2);
sb1.append("abc"); sb1.append("abc");
assertFalse(sb1.equals(sb2)); assertFalse(sb1.equals(sb2));
assertNotEquals(sb1, (Object) sb2); assertNotEquals(sb1, sb2);
sb2.append("ABC"); sb2.append("ABC");
assertFalse(sb1.equals(sb2)); assertFalse(sb1.equals(sb2));
assertNotEquals(sb1, (Object) sb2); assertNotEquals(sb1, sb2);
sb2.clear().append("abc"); sb2.clear().append("abc");
assertTrue(sb1.equals(sb2)); assertTrue(sb1.equals(sb2));
assertEquals(sb1, (Object) sb2); assertEquals(sb1, sb2);
assertNotEquals(sb1, Integer.valueOf(1)); assertNotEquals(sb1, Integer.valueOf(1));
assertNotEquals("abc", sb1); assertNotEquals("abc", sb1);

View File

@ -127,7 +127,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testHoursOfMonthWithCalendar() { public void testHoursOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH); final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
assertEquals( hours +(((days - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals( hours +(days - 1) * DateUtils.MILLIS_PER_DAY
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -135,7 +135,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testHoursOfMonthWithDate() { public void testHoursOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH); final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
assertEquals(hours + (((days - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals(hours + (days - 1) * DateUtils.MILLIS_PER_DAY
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -143,7 +143,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testHoursOfYearWithCalendar() { public void testHoursOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR); final long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
assertEquals( hours +(((aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals( hours +(aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -153,7 +153,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR); final long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
final Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(hours + (((cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals(hours + (cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY
/ DateUtils.MILLIS_PER_HOUR, / DateUtils.MILLIS_PER_HOUR,
testResult); testResult);
} }
@ -201,7 +201,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testMillisecondsOfDayWithCalendar() { public void testMillisecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE); long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE);
final long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR); final long expectedValue = millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE + hours * DateUtils.MILLIS_PER_HOUR;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
@ -211,7 +211,7 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testMillisecondsOfDayWithDate() { public void testMillisecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE); long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE);
final long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR); final long expectedValue = millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE + hours * DateUtils.MILLIS_PER_HOUR;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
@ -222,32 +222,32 @@ public class DateUtilsFragmentTest extends AbstractLangTest {
@Test @Test
public void testMillisecondsOfHourWithCalendar() { public void testMillisecondsOfHourWithCalendar() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY); final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult); assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE, testResult);
} }
@Test @Test
public void testMillisecondsOfHourWithDate() { public void testMillisecondsOfHourWithDate() {
final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY); final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult); assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE, testResult);
} }
@Test @Test
public void testMillisecondsOfMinuteWithCalender() { public void testMillisecondsOfMinuteWithCalender() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE); final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult); assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND, testResult);
} }
@Test @Test
public void testMillisecondsOfMinuteWithDate() { public void testMillisecondsOfMinuteWithDate() {
final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE); final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult); assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND, testResult);
} }
@Test @Test
public void testMillisecondsOfMonthWithCalendar() { public void testMillisecondsOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH); final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY), + hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY,
testResult); testResult);
} }
@ -255,8 +255,8 @@ testResult);
@Test @Test
public void testMillisecondsOfMonthWithDate() { public void testMillisecondsOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH); final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY), + hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY,
testResult); testResult);
} }
@ -276,8 +276,8 @@ testResult);
@Test @Test
public void testMillisecondsOfYearWithCalendar() { public void testMillisecondsOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR); final long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY), + hours * DateUtils.MILLIS_PER_HOUR + (aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY,
testResult); testResult);
} }
@ -287,8 +287,8 @@ testResult);
final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR); final long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR);
final Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) assertEquals(millis + seconds * DateUtils.MILLIS_PER_SECOND + minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR) - 1)* DateUtils.MILLIS_PER_DAY), + hours * DateUtils.MILLIS_PER_HOUR + (cal.get(Calendar.DAY_OF_YEAR) - 1)* DateUtils.MILLIS_PER_DAY,
testResult); testResult);
} }
@ -309,7 +309,7 @@ testResult);
@Test @Test
public void testMinutesOfDayWithCalendar() { public void testMinutesOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE); long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE);
final long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE; final long expectedValue = minutes + hours * DateUtils.MILLIS_PER_HOUR/ DateUtils.MILLIS_PER_MINUTE;
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
@ -318,7 +318,7 @@ testResult);
@Test @Test
public void testMinutesOfDayWithDate() { public void testMinutesOfDayWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE); long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE);
final long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE; final long expectedValue = minutes + hours * DateUtils.MILLIS_PER_HOUR/ DateUtils.MILLIS_PER_MINUTE;
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DAY_OF_YEAR); testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testResult); assertEquals(expectedValue, testResult);
@ -339,7 +339,7 @@ testResult);
@Test @Test
public void testMinutesOfMonthWithCalendar() { public void testMinutesOfMonthWithCalendar() {
final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH); final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals( minutes +(hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -348,7 +348,7 @@ testResult);
public void testMinutesOfMonthWithDate() { public void testMinutesOfMonthWithDate() {
final long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH); final long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
assertEquals(minutes assertEquals(minutes
+ ((hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -356,7 +356,7 @@ testResult);
@Test @Test
public void testMinutesOfYearWithCalendar() { public void testMinutesOfYearWithCalendar() {
final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR); final long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) assertEquals( minutes +(hours * DateUtils.MILLIS_PER_HOUR + (aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -367,7 +367,7 @@ testResult);
final Calendar cal = Calendar.getInstance(); final Calendar cal = Calendar.getInstance();
cal.setTime(aDate); cal.setTime(aDate);
assertEquals(minutes assertEquals(minutes
+ ((hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) + (hours * DateUtils.MILLIS_PER_HOUR + (cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_MINUTE, / DateUtils.MILLIS_PER_MINUTE,
testResult); testResult);
} }
@ -422,7 +422,7 @@ testResult);
@Test @Test
public void testSecondsOfDayWithCalendar() { public void testSecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE); long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE);
final long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND; final long expectedValue = seconds + (minutes * DateUtils.MILLIS_PER_MINUTE + hours * DateUtils.MILLIS_PER_HOUR)/ DateUtils.MILLIS_PER_SECOND;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
@ -431,7 +431,7 @@ testResult);
@Test @Test
public void testSecondsOfDayWithDate() { public void testSecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE); long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE);
final long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND; final long expectedValue = seconds + (minutes * DateUtils.MILLIS_PER_MINUTE + hours * DateUtils.MILLIS_PER_HOUR)/ DateUtils.MILLIS_PER_SECOND;
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DAY_OF_YEAR); testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DAY_OF_YEAR);
assertEquals(expectedValue, testresult); assertEquals(expectedValue, testresult);
@ -442,8 +442,8 @@ testResult);
final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY); final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals( assertEquals(
seconds seconds
+ (minutes + minutes
* DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND), * DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -452,8 +452,8 @@ testResult);
final long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY); final long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals( assertEquals(
seconds seconds
+ (minutes + minutes
* DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND), * DateUtils.MILLIS_PER_MINUTE / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -475,8 +475,8 @@ testResult);
final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH); final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + (minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY)) + hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -486,8 +486,8 @@ testResult);
final long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH); final long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + (minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((days - 1) * DateUtils.MILLIS_PER_DAY)) + hours * DateUtils.MILLIS_PER_HOUR + (days - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -497,8 +497,8 @@ testResult);
final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR); final long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + (minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) + hours * DateUtils.MILLIS_PER_HOUR + (aCalendar.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }
@ -510,8 +510,8 @@ testResult);
cal.setTime(aDate); cal.setTime(aDate);
assertEquals( assertEquals(
seconds seconds
+ ((minutes * DateUtils.MILLIS_PER_MINUTE) + (minutes * DateUtils.MILLIS_PER_MINUTE
+ (hours * DateUtils.MILLIS_PER_HOUR) + ((cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)) + hours * DateUtils.MILLIS_PER_HOUR + (cal.get(Calendar.DAY_OF_YEAR) - 1) * DateUtils.MILLIS_PER_DAY)
/ DateUtils.MILLIS_PER_SECOND, / DateUtils.MILLIS_PER_SECOND,
testResult); testResult);
} }

View File

@ -83,7 +83,7 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
} }
private DurationFormatUtils.Token createTokenWithCount(final Object value, final int count) { private DurationFormatUtils.Token createTokenWithCount(final Object value, final int count) {
DurationFormatUtils.Token token = new DurationFormatUtils.Token(value, false, -1); final DurationFormatUtils.Token token = new DurationFormatUtils.Token(value, false, -1);
for (int i = 1; i < count; i++) { for (int i = 1; i < count; i++) {
token.increment(); token.increment();
} }
@ -92,7 +92,7 @@ public class DurationFormatUtilsTest extends AbstractLangTest {
@Test @Test
public void testAlternatingLiteralOptionals() { public void testAlternatingLiteralOptionals() {
String format = "['d'dH'h'][m'm']['s's]['ms'S]"; final String format = "['d'dH'h'][m'm']['s's]['ms'S]";
assertEquals("d1", assertEquals("d1",
DurationFormatUtils.formatDuration(Duration.ofDays(1).toMillis(), format)); DurationFormatUtils.formatDuration(Duration.ofDays(1).toMillis(), format));

View File

@ -627,7 +627,7 @@ public class FastDateParserTest extends AbstractLangTest {
} }
} }
// SDF and FDF should produce equivalent results // SDF and FDF should produce equivalent results
assertEquals((f == null), (s == null), "Should both or neither throw Exceptions"); assertEquals(f == null, s == null, "Should both or neither throw Exceptions");
assertEquals(dsdf, dfdp, "Parsed dates should be equal"); assertEquals(dsdf, dfdp, "Parsed dates should be equal");
} }

View File

@ -116,7 +116,7 @@ public class FastDateParser_TimeZoneStrategyTest extends AbstractLangTest {
// An exception will be thrown and the test will fail if parsing isn't successful // An exception will be thrown and the test will fail if parsing isn't successful
try { try {
parser.parse(tzDisplay); parser.parse(tzDisplay);
} catch (ParseException e) { } catch (final ParseException e) {
// Hack Start // Hack Start
// See failures on GitHub Actions builds for Java 17. // See failures on GitHub Actions builds for Java 17.
final String localeStr = locale.toString(); final String localeStr = locale.toString();
@ -131,7 +131,8 @@ public class FastDateParser_TimeZoneStrategyTest extends AbstractLangTest {
localeStr, tzDisplay); localeStr, tzDisplay);
assumeTrue(false, localeStr); assumeTrue(false, localeStr);
continue; continue;
} else if (SystemUtils.IS_JAVA_11 }
if (SystemUtils.IS_JAVA_11
&& (localeStr.contains("_") || "Coordinated Universal Time".equals(tzDisplay))) { && (localeStr.contains("_") || "Coordinated Universal Time".equals(tzDisplay))) {
Java11Failures.add(locale); Java11Failures.add(locale);
// Mark as an assumption failure instead of a hard fail // Mark as an assumption failure instead of a hard fail
@ -167,7 +168,7 @@ public class FastDateParser_TimeZoneStrategyTest extends AbstractLangTest {
final String displayName = timeZone.getDisplayName(locale); final String displayName = timeZone.getDisplayName(locale);
try { try {
parser.parse(displayName); parser.parse(displayName);
} catch (ParseException e) { } catch (final ParseException e) {
// Missing "Zulu" or something else in broken JDK's GH builds? // Missing "Zulu" or something else in broken JDK's GH builds?
fail(String.format("%s: with locale = %s, id = '%s', timeZone = %s, displayName = '%s', parser = '%s'", e, locale, id, timeZone, displayName, fail(String.format("%s: with locale = %s, id = '%s', timeZone = %s, displayName = '%s', parser = '%s'", e, locale, id, timeZone, displayName,
parser.toStringAll()), e); parser.toStringAll()), e);