Use final consistently.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1606051 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-06-27 12:22:17 +00:00
parent ba8c6f6d6f
commit 96c30e248d
46 changed files with 308 additions and 307 deletions

View File

@ -1570,7 +1570,7 @@ public static void reverse(final boolean[] array) {
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final boolean[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final boolean[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1605,7 +1605,7 @@ public static void reverse(final boolean[] array, int startIndexInclusive, int e
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final byte[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final byte[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1640,7 +1640,7 @@ public static void reverse(final byte[] array, int startIndexInclusive, int endI
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final char[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final char[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1675,7 +1675,7 @@ public static void reverse(final char[] array, int startIndexInclusive, int endI
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final double[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final double[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1710,7 +1710,7 @@ public static void reverse(final double[] array, int startIndexInclusive, int en
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final float[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final float[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1745,7 +1745,7 @@ public static void reverse(final float[] array, int startIndexInclusive, int end
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final int[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final int[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1780,7 +1780,7 @@ public static void reverse(final int[] array, int startIndexInclusive, int endIn
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final long[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final long[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1815,7 +1815,7 @@ public static void reverse(final long[] array, int startIndexInclusive, int endI
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final Object[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final Object[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }
@ -1850,7 +1850,7 @@ public static void reverse(final Object[] array, int startIndexInclusive, int en
* change. Overvalue (>array.length) is demoted to array length. * change. Overvalue (>array.length) is demoted to array length.
* @since 3.2 * @since 3.2
*/ */
public static void reverse(final short[] array, int startIndexInclusive, int endIndexExclusive) { public static void reverse(final short[] array, final int startIndexInclusive, final int endIndexExclusive) {
if (array == null) { if (array == null) {
return; return;
} }

View File

@ -193,8 +193,8 @@ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, fi
int tmpLen = length; int tmpLen = length;
while (tmpLen-- > 0) { while (tmpLen-- > 0) {
char c1 = cs.charAt(index1++); final char c1 = cs.charAt(index1++);
char c2 = substring.charAt(index2++); final char c2 = substring.charAt(index2++);
if (c1 == c2) { if (c1 == c2) {
continue; continue;

View File

@ -80,7 +80,7 @@ public static String toFullyQualifiedName(final Class<?> context, final String r
public static String toFullyQualifiedName(final Package context, final String resourceName) { public static String toFullyQualifiedName(final Package context, final String resourceName) {
Validate.notNull(context, "Parameter '%s' must not be null!", "context" ); Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName"); Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(context.getName()); sb.append(context.getName());
sb.append("."); sb.append(".");
sb.append(resourceName); sb.append(resourceName);
@ -129,7 +129,7 @@ public static String toFullyQualifiedPath(final Class<?> context, final String r
public static String toFullyQualifiedPath(final Package context, final String resourceName) { public static String toFullyQualifiedPath(final Package context, final String resourceName) {
Validate.notNull(context, "Parameter '%s' must not be null!", "context" ); Validate.notNull(context, "Parameter '%s' must not be null!", "context" );
Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName"); Validate.notNull(resourceName, "Parameter '%s' must not be null!", "resourceName");
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(context.getName().replace('.', '/')); sb.append(context.getName().replace('.', '/'));
sb.append("/"); sb.append("/");
sb.append(resourceName); sb.append(resourceName);

View File

@ -127,7 +127,7 @@ public enum Interfaces {
m.put("char", "C"); m.put("char", "C");
m.put("void", "V"); m.put("void", "V");
final Map<String, String> r = new HashMap<String, String>(); final Map<String, String> r = new HashMap<String, String>();
for (Map.Entry<String, String> e : m.entrySet()) { for (final Map.Entry<String, String> e : m.entrySet()) {
r.put(e.getValue(), e.getKey()); r.put(e.getValue(), e.getKey());
} }
abbreviationMap = Collections.unmodifiableMap(m); abbreviationMap = Collections.unmodifiableMap(m);
@ -1158,7 +1158,7 @@ public static Iterable<Class<?>> hierarchy(final Class<?> type) {
* @return Iterable an Iterable over the class hierarchy of the given class * @return Iterable an Iterable over the class hierarchy of the given class
* @since 3.2 * @since 3.2
*/ */
public static Iterable<Class<?>> hierarchy(final Class<?> type, Interfaces interfacesBehavior) { public static Iterable<Class<?>> hierarchy(final Class<?> type, final Interfaces interfacesBehavior) {
final Iterable<Class<?>> classes = new Iterable<Class<?>>() { final Iterable<Class<?>> classes = new Iterable<Class<?>>() {
@Override @Override
@ -1219,8 +1219,8 @@ public Class<?> next() {
return nextSuperclass; return nextSuperclass;
} }
private void walkInterfaces(Set<Class<?>> addTo, Class<?> c) { private void walkInterfaces(final Set<Class<?>> addTo, final Class<?> c) {
for (Class<?> iface : c.getInterfaces()) { for (final Class<?> iface : c.getInterfaces()) {
if (!seenInterfaces.contains(iface)) { if (!seenInterfaces.contains(iface)) {
addTo.add(iface); addTo.add(iface);
} }

View File

@ -266,7 +266,7 @@ public static <E extends Enum<E>> EnumSet<E> processBitVector(final Class<E> enu
*/ */
public static <E extends Enum<E>> EnumSet<E> processBitVectors(final Class<E> enumClass, final long... values) { public static <E extends Enum<E>> EnumSet<E> processBitVectors(final Class<E> enumClass, final long... values) {
final EnumSet<E> results = EnumSet.noneOf(asEnum(enumClass)); final EnumSet<E> results = EnumSet.noneOf(asEnum(enumClass));
long[] lvalues = ArrayUtils.clone(Validate.notNull(values)); final long[] lvalues = ArrayUtils.clone(Validate.notNull(values));
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;

View File

@ -123,8 +123,8 @@ public static Locale toLocale(final String str) {
return new Locale("", str.substring(1, 3), str.substring(4)); return new Locale("", str.substring(1, 3), str.substring(4));
} }
String[] split = str.split("_", -1); final String[] split = str.split("_", -1);
int occurrences = split.length -1; final int occurrences = split.length -1;
switch (occurrences) { switch (occurrences) {
case 0: case 0:
if (StringUtils.isAllLowerCase(str) && (len == 2 || len == 3)) { if (StringUtils.isAllLowerCase(str) && (len == 2 || len == 3)) {

View File

@ -239,7 +239,7 @@ public static int hashCodeMulti(final Object... objects) {
int hash = 1; int hash = 1;
if (objects != null) { if (objects != null) {
for (final Object object : objects) { for (final Object object : objects) {
int tmpHash = ObjectUtils.hashCode(object); final int tmpHash = ObjectUtils.hashCode(object);
hash = hash * 31 + tmpHash; hash = hash * 31 + tmpHash;
} }
} }

View File

@ -59,10 +59,10 @@ public RandomUtils() {
* @return the random byte array * @return the random byte array
* @throws IllegalArgumentException if {@code count} is negative * @throws IllegalArgumentException if {@code count} is negative
*/ */
public static byte[] nextBytes(int count) { public static byte[] nextBytes(final int count) {
Validate.isTrue(count >= 0, "Count cannot be negative."); Validate.isTrue(count >= 0, "Count cannot be negative.");
byte[] result = new byte[count]; final byte[] result = new byte[count];
RANDOM.nextBytes(result); RANDOM.nextBytes(result);
return result; return result;
} }
@ -81,7 +81,7 @@ public static byte[] nextBytes(int count) {
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random integer * @return the random integer
*/ */
public static int nextInt(int startInclusive, int endExclusive) { public static int nextInt(final int startInclusive, final int endExclusive) {
Validate.isTrue(endExclusive >= startInclusive, Validate.isTrue(endExclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
@ -107,7 +107,7 @@ public static int nextInt(int startInclusive, int endExclusive) {
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random long * @return the random long
*/ */
public static long nextLong(long startInclusive, long endExclusive) { public static long nextLong(final long startInclusive, final long endExclusive) {
Validate.isTrue(endExclusive >= startInclusive, Validate.isTrue(endExclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
@ -134,7 +134,7 @@ public static long nextLong(long startInclusive, long endExclusive) {
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random double * @return the random double
*/ */
public static double nextDouble(double startInclusive, double endInclusive) { public static double nextDouble(final double startInclusive, final double endInclusive) {
Validate.isTrue(endInclusive >= startInclusive, Validate.isTrue(endInclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");
@ -160,7 +160,7 @@ public static double nextDouble(double startInclusive, double endInclusive) {
* {@code startInclusive} is negative * {@code startInclusive} is negative
* @return the random float * @return the random float
*/ */
public static float nextFloat(float startInclusive, float endInclusive) { public static float nextFloat(final float startInclusive, final float endInclusive) {
Validate.isTrue(endInclusive >= startInclusive, Validate.isTrue(endInclusive >= startInclusive,
"Start value must be smaller or equal to end value."); "Start value must be smaller or equal to end value.");
Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative."); Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");

View File

@ -255,11 +255,11 @@ public static boolean isNotEmpty(final CharSequence cs) {
* @return {@code true} if any of the CharSequences are empty or null * @return {@code true} if any of the CharSequences are empty or null
* @since 3.2 * @since 3.2
*/ */
public static boolean isAnyEmpty(CharSequence... css) { public static boolean isAnyEmpty(final CharSequence... css) {
if (ArrayUtils.isEmpty(css)) { if (ArrayUtils.isEmpty(css)) {
return true; return true;
} }
for (CharSequence cs : css){ for (final CharSequence cs : css){
if (isEmpty(cs)) { if (isEmpty(cs)) {
return true; return true;
} }
@ -284,7 +284,7 @@ public static boolean isAnyEmpty(CharSequence... css) {
* @return {@code true} if none of the CharSequences are empty or null * @return {@code true} if none of the CharSequences are empty or null
* @since 3.2 * @since 3.2
*/ */
public static boolean isNoneEmpty(CharSequence... css) { public static boolean isNoneEmpty(final CharSequence... css) {
return !isAnyEmpty(css); return !isAnyEmpty(css);
} }
/** /**
@ -355,11 +355,11 @@ public static boolean isNotBlank(final CharSequence cs) {
* @return {@code true} if any of the CharSequences are blank or null or whitespace only * @return {@code true} if any of the CharSequences are blank or null or whitespace only
* @since 3.2 * @since 3.2
*/ */
public static boolean isAnyBlank(CharSequence... css) { public static boolean isAnyBlank(final CharSequence... css) {
if (ArrayUtils.isEmpty(css)) { if (ArrayUtils.isEmpty(css)) {
return true; return true;
} }
for (CharSequence cs : css){ for (final CharSequence cs : css){
if (isBlank(cs)) { if (isBlank(cs)) {
return true; return true;
} }
@ -385,7 +385,7 @@ public static boolean isAnyBlank(CharSequence... css) {
* @return {@code true} if none of the CharSequences are blank or null or whitespace only * @return {@code true} if none of the CharSequences are blank or null or whitespace only
* @since 3.2 * @since 3.2
*/ */
public static boolean isNoneBlank(CharSequence... css) { public static boolean isNoneBlank(final CharSequence... css) {
return !isAnyBlank(css); return !isAnyBlank(css);
} }
@ -4041,6 +4041,7 @@ public static String join(final Iterator<?> iterator, final char separator) {
final Object first = iterator.next(); final Object first = iterator.next();
if (!iterator.hasNext()) { if (!iterator.hasNext()) {
@SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2 @SuppressWarnings( "deprecation" ) // ObjectUtils.toString(Object) has been deprecated in 3.2
final
String result = ObjectUtils.toString(first); String result = ObjectUtils.toString(first);
return result; return result;
} }
@ -5689,7 +5690,7 @@ public static String capitalize(final String str) {
return str; return str;
} }
char firstChar = str.charAt(0); final char firstChar = str.charAt(0);
if (Character.isTitleCase(firstChar)) { if (Character.isTitleCase(firstChar)) {
// already capitalized // already capitalized
return str; return str;
@ -5727,7 +5728,7 @@ public static String uncapitalize(final String str) {
return str; return str;
} }
char firstChar = str.charAt(0); final char firstChar = str.charAt(0);
if (Character.isLowerCase(firstChar)) { if (Character.isLowerCase(firstChar)) {
// already uncapitalized // already uncapitalized
return str; return str;
@ -7126,11 +7127,11 @@ public static int getFuzzyDistance(final CharSequence term, final CharSequence q
int previousMatchingCharacterIndex = Integer.MIN_VALUE; int previousMatchingCharacterIndex = Integer.MIN_VALUE;
for (int queryIndex = 0; queryIndex < queryLowerCase.length(); queryIndex++) { for (int queryIndex = 0; queryIndex < queryLowerCase.length(); queryIndex++) {
char queryChar = queryLowerCase.charAt(queryIndex); final char queryChar = queryLowerCase.charAt(queryIndex);
boolean termCharacterMatchFound = false; boolean termCharacterMatchFound = false;
for (; termIndex < termLowerCase.length() && !termCharacterMatchFound; termIndex++) { for (; termIndex < termLowerCase.length() && !termCharacterMatchFound; termIndex++) {
char termChar = termLowerCase.charAt(termIndex); final char termChar = termLowerCase.charAt(termIndex);
if (queryChar == termChar) { if (queryChar == termChar) {
// simple character matches result in one point // simple character matches result in one point
@ -7191,7 +7192,7 @@ private static String getSetOfMatchingCharacterWithin(final CharSequence first,
* @param second The second string. * @param second The second string.
* @return The number of transposition between the two strings. * @return The number of transposition between the two strings.
*/ */
private static int transpositions(CharSequence first, CharSequence second) { private static int transpositions(final CharSequence first, final CharSequence second) {
int transpositions = 0; int transpositions = 0;
for (int i = 0; i < first.length(); i++) { for (int i = 0; i < first.length(); i++) {
if (first.charAt(i) != second.charAt(i)) { if (first.charAt(i) != second.charAt(i)) {
@ -7208,7 +7209,7 @@ private static int transpositions(CharSequence first, CharSequence second) {
* @param second The second string. * @param second The second string.
* @return A number between 0 and 4. * @return A number between 0 and 4.
*/ */
private static int commonPrefixLength(CharSequence first, CharSequence second) { private static int commonPrefixLength(final CharSequence first, final CharSequence second) {
final int result = getCommonPrefix(first.toString(), second.toString()).length(); final int result = getCommonPrefix(first.toString(), second.toString()).length();
// Limit the result to 4. // Limit the result to 4.
@ -7714,7 +7715,7 @@ public static String toString(final byte[] bytes, final String charsetName) thro
* @since 3.2 * @since 3.2
* @since 3.3 No longer throws {@link UnsupportedEncodingException}. * @since 3.3 No longer throws {@link UnsupportedEncodingException}.
*/ */
public static String toEncodedString(byte[] bytes, Charset charset) { public static String toEncodedString(final byte[] bytes, final Charset charset) {
return new String(bytes, charset != null ? charset : Charset.defaultCharset()); return new String(bytes, charset != null ? charset : Charset.defaultCharset());
} }
@ -7739,7 +7740,7 @@ public static String toEncodedString(byte[] bytes, Charset charset) {
* @return the wrapped string, or {@code null} if {@code str==null} * @return the wrapped string, or {@code null} if {@code str==null}
* @since 3.4 * @since 3.4
*/ */
public static String wrap(String str, char wrapWith) { public static String wrap(final String str, final char wrapWith) {
if (isEmpty(str) || wrapWith == '\0') { if (isEmpty(str) || wrapWith == '\0') {
return str; return str;
@ -7777,7 +7778,7 @@ public static String wrap(String str, char wrapWith) {
* @return wrapped String, {@code null} if null String input * @return wrapped String, {@code null} if null String input
* @since 3.4 * @since 3.4
*/ */
public static String wrap(String str, String wrapWith) { public static String wrap(final String str, final String wrapWith) {
if (isEmpty(str) || isEmpty(wrapWith)) { if (isEmpty(str) || isEmpty(wrapWith)) {
return str; return str;

View File

@ -940,7 +940,7 @@ public static <T> void inclusiveBetween(final T start, final T end, final Compar
* @since 3.3 * @since 3.3
*/ */
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public static void inclusiveBetween(long start, long end, long value) { public static void inclusiveBetween(final long start, final long end, final long value) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value < start || value > end) { if (value < start || value > end) {
throw new IllegalArgumentException(String.format(DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end)); throw new IllegalArgumentException(String.format(DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
@ -963,7 +963,7 @@ public static void inclusiveBetween(long start, long end, long value) {
* *
* @since 3.3 * @since 3.3
*/ */
public static void inclusiveBetween(long start, long end, long value, String message) { public static void inclusiveBetween(final long start, final long end, final long value, final String message) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value < start || value > end) { if (value < start || value > end) {
throw new IllegalArgumentException(String.format(message)); throw new IllegalArgumentException(String.format(message));
@ -984,7 +984,7 @@ public static void inclusiveBetween(long start, long end, long value, String mes
* @since 3.3 * @since 3.3
*/ */
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public static void inclusiveBetween(double start, double end, double value) { public static void inclusiveBetween(final double start, final double end, final double value) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value < start || value > end) { if (value < start || value > end) {
throw new IllegalArgumentException(String.format(DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end)); throw new IllegalArgumentException(String.format(DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
@ -1007,7 +1007,7 @@ public static void inclusiveBetween(double start, double end, double value) {
* *
* @since 3.3 * @since 3.3
*/ */
public static void inclusiveBetween(double start, double end, double value, String message) { public static void inclusiveBetween(final double start, final double end, final double value, final String message) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value < start || value > end) { if (value < start || value > end) {
throw new IllegalArgumentException(String.format(message)); throw new IllegalArgumentException(String.format(message));
@ -1078,7 +1078,7 @@ public static <T> void exclusiveBetween(final T start, final T end, final Compar
* @since 3.3 * @since 3.3
*/ */
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public static void exclusiveBetween(long start, long end, long value) { public static void exclusiveBetween(final long start, final long end, final long value) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value <= start || value >= end) { if (value <= start || value >= end) {
throw new IllegalArgumentException(String.format(DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end)); throw new IllegalArgumentException(String.format(DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
@ -1101,7 +1101,7 @@ public static void exclusiveBetween(long start, long end, long value) {
* *
* @since 3.3 * @since 3.3
*/ */
public static void exclusiveBetween(long start, long end, long value, String message) { public static void exclusiveBetween(final long start, final long end, final long value, final String message) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value <= start || value >= end) { if (value <= start || value >= end) {
throw new IllegalArgumentException(String.format(message)); throw new IllegalArgumentException(String.format(message));
@ -1122,7 +1122,7 @@ public static void exclusiveBetween(long start, long end, long value, String mes
* @since 3.3 * @since 3.3
*/ */
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public static void exclusiveBetween(double start, double end, double value) { public static void exclusiveBetween(final double start, final double end, final double value) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value <= start || value >= end) { if (value <= start || value >= end) {
throw new IllegalArgumentException(String.format(DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end)); throw new IllegalArgumentException(String.format(DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE, value, start, end));
@ -1145,7 +1145,7 @@ public static void exclusiveBetween(double start, double end, double value) {
* *
* @since 3.3 * @since 3.3
*/ */
public static void exclusiveBetween(double start, double end, double value, String message) { public static void exclusiveBetween(final double start, final double end, final double value, final String message) {
// TODO when breaking BC, consider returning value // TODO when breaking BC, consider returning value
if (value <= start || value >= end) { if (value <= start || value >= end) {
throw new IllegalArgumentException(String.format(message)); throw new IllegalArgumentException(String.format(message));

View File

@ -56,7 +56,7 @@ public abstract class Diff<T> extends Pair<T, T> {
* @param fieldName * @param fieldName
* the name of the field * the name of the field
*/ */
protected Diff(String fieldName) { protected Diff(final String fieldName) {
this.type = ObjectUtils.defaultIfNull( this.type = ObjectUtils.defaultIfNull(
TypeUtils.getTypeArguments(getClass(), Diff.class).get( TypeUtils.getTypeArguments(getClass(), Diff.class).get(
Diff.class.getTypeParameters()[0]), Object.class); Diff.class.getTypeParameters()[0]), Object.class);
@ -112,7 +112,7 @@ public final String toString() {
* @return nothing * @return nothing
*/ */
@Override @Override
public final T setValue(T value) { public final T setValue(final T value) {
throw new UnsupportedOperationException("Cannot alter Diff object."); throw new UnsupportedOperationException("Cannot alter Diff object.");
} }
} }

View File

@ -177,15 +177,15 @@ public String toString() {
* *
* @return a {@code String} description of the differences. * @return a {@code String} description of the differences.
*/ */
public String toString(ToStringStyle style) { public String toString(final ToStringStyle style) {
if (diffs.size() == 0) { if (diffs.size() == 0) {
return OBJECTS_SAME_STRING; return OBJECTS_SAME_STRING;
} }
ToStringBuilder lhsBuilder = new ToStringBuilder(lhs, style); final ToStringBuilder lhsBuilder = new ToStringBuilder(lhs, style);
ToStringBuilder rhsBuilder = new ToStringBuilder(rhs, style); final ToStringBuilder rhsBuilder = new ToStringBuilder(rhs, style);
for (Diff<?> diff : diffs) { for (final Diff<?> diff : diffs) {
lhsBuilder.append(diff.getFieldName(), diff.getLeft()); lhsBuilder.append(diff.getFieldName(), diff.getLeft());
rhsBuilder.append(diff.getFieldName(), diff.getRight()); rhsBuilder.append(diff.getFieldName(), diff.getRight());
} }

View File

@ -68,7 +68,7 @@ public RecursiveToStringStyle() {
} }
@Override @Override
public void appendDetail(StringBuffer buffer, String fieldName, Object value) { public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) {
if (!ClassUtils.isPrimitiveWrapper(value.getClass()) && if (!ClassUtils.isPrimitiveWrapper(value.getClass()) &&
!String.class.equals(value.getClass()) && !String.class.equals(value.getClass()) &&
accept(value.getClass())) { accept(value.getClass())) {
@ -79,7 +79,7 @@ public void appendDetail(StringBuffer buffer, String fieldName, Object value) {
} }
@Override @Override
protected void appendDetail(StringBuffer buffer, String fieldName, Collection<?> coll) { protected void appendDetail(final StringBuffer buffer, final String fieldName, final Collection<?> coll) {
appendClassName(buffer, coll); appendClassName(buffer, coll);
appendIdentityHashCode(buffer, coll); appendIdentityHashCode(buffer, coll);
appendDetail(buffer, fieldName, coll.toArray()); appendDetail(buffer, fieldName, coll.toArray());

View File

@ -193,7 +193,7 @@ public static Field getDeclaredField(final Class<?> cls, final String fieldName,
* if the class is {@code null} * if the class is {@code null}
* @since 3.2 * @since 3.2
*/ */
public static Field[] getAllFields(Class<?> cls) { public static Field[] getAllFields(final Class<?> cls) {
final List<Field> allFieldsList = getAllFieldsList(cls); final List<Field> allFieldsList = getAllFieldsList(cls);
return allFieldsList.toArray(new Field[allFieldsList.size()]); return allFieldsList.toArray(new Field[allFieldsList.size()]);
} }
@ -208,13 +208,13 @@ public static Field[] getAllFields(Class<?> cls) {
* if the class is {@code null} * if the class is {@code null}
* @since 3.2 * @since 3.2
*/ */
public static List<Field> getAllFieldsList(Class<?> cls) { public static List<Field> getAllFieldsList(final Class<?> cls) {
Validate.isTrue(cls != null, "The class must not be null"); Validate.isTrue(cls != null, "The class must not be null");
final List<Field> allFields = new ArrayList<Field>(); final List<Field> allFields = new ArrayList<Field>();
Class<?> currentClass = cls; Class<?> currentClass = cls;
while (currentClass != null) { while (currentClass != null) {
final Field[] declaredFields = currentClass.getDeclaredFields(); final Field[] declaredFields = currentClass.getDeclaredFields();
for (Field field : declaredFields) { for (final Field field : declaredFields) {
allFields.add(field); allFields.add(field);
} }
currentClass = currentClass.getSuperclass(); currentClass = currentClass.getSuperclass();
@ -658,7 +658,7 @@ public static void writeField(final Field field, final Object target, final Obje
* if the field is {@code null} * if the field is {@code null}
* @since 3.2 * @since 3.2
*/ */
public static void removeFinalModifier(Field field) { public static void removeFinalModifier(final Field field) {
removeFinalModifier(field, true); removeFinalModifier(field, true);
} }
@ -675,13 +675,13 @@ public static void removeFinalModifier(Field field) {
* if the field is {@code null} * if the field is {@code null}
* @since 3.3 * @since 3.3
*/ */
public static void removeFinalModifier(Field field, boolean forceAccess) { public static void removeFinalModifier(final Field field, final boolean forceAccess) {
Validate.isTrue(field != null, "The field must not be null"); Validate.isTrue(field != null, "The field must not be null");
try { try {
if (Modifier.isFinal(field.getModifiers())) { if (Modifier.isFinal(field.getModifiers())) {
// Do all JREs implement Field with a private ivar called "modifiers"? // Do all JREs implement Field with a private ivar called "modifiers"?
Field modifiersField = Field.class.getDeclaredField("modifiers"); final Field modifiersField = Field.class.getDeclaredField("modifiers");
final boolean doForceAccess = forceAccess && !modifiersField.isAccessible(); final boolean doForceAccess = forceAccess && !modifiersField.isAccessible();
if (doForceAccess) { if (doForceAccess) {
modifiersField.setAccessible(true); modifiersField.setAccessible(true);
@ -694,9 +694,9 @@ public static void removeFinalModifier(Field field, boolean forceAccess) {
} }
} }
} }
} catch (NoSuchFieldException ignored) { } catch (final NoSuchFieldException ignored) {
// The field class contains always a modifiers field // The field class contains always a modifiers field
} catch (IllegalAccessException ignored) { } catch (final IllegalAccessException ignored) {
// The modifiers field is made accessible // The modifiers field is made accessible
} }
} }

View File

@ -439,7 +439,7 @@ private static Method getAccessibleMethodFromInterfaceNest(Class<?> cls,
*/ */
} }
// Recursively check our parent interfaces // Recursively check our parent interfaces
Method method = getAccessibleMethodFromInterfaceNest(interfaces[i], final Method method = getAccessibleMethodFromInterfaceNest(interfaces[i],
methodName, parameterTypes); methodName, parameterTypes);
if (method != null) { if (method != null) {
return method; return method;
@ -509,7 +509,7 @@ public static Method getMatchingAccessibleMethod(final Class<?> cls,
* @throws NullPointerException if the specified method is {@code null} * @throws NullPointerException if the specified method is {@code null}
* @since 3.2 * @since 3.2
*/ */
public static Set<Method> getOverrideHierarchy(final Method method, Interfaces interfacesBehavior) { public static Set<Method> getOverrideHierarchy(final Method method, final Interfaces interfacesBehavior) {
Validate.notNull(method); Validate.notNull(method);
final Set<Method> result = new LinkedHashSet<Method>(); final Set<Method> result = new LinkedHashSet<Method>();
result.add(method); result.add(method);

View File

@ -96,7 +96,7 @@ protected TypeLiteral() {
} }
@Override @Override
public final boolean equals(Object obj) { public final boolean equals(final Object obj) {
if (obj == this) { if (obj == this) {
return true; return true;
} }

View File

@ -65,7 +65,7 @@ private WildcardTypeBuilder() {
* @param bounds to set * @param bounds to set
* @return {@code this} * @return {@code this}
*/ */
public WildcardTypeBuilder withUpperBounds(Type... bounds) { public WildcardTypeBuilder withUpperBounds(final Type... bounds) {
this.upperBounds = bounds; this.upperBounds = bounds;
return this; return this;
} }
@ -75,7 +75,7 @@ public WildcardTypeBuilder withUpperBounds(Type... bounds) {
* @param bounds to set * @param bounds to set
* @return {@code this} * @return {@code this}
*/ */
public WildcardTypeBuilder withLowerBounds(Type... bounds) { public WildcardTypeBuilder withLowerBounds(final Type... bounds) {
this.lowerBounds = bounds; this.lowerBounds = bounds;
return this; return this;
} }
@ -100,7 +100,7 @@ private static final class GenericArrayTypeImpl implements GenericArrayType {
* Constructor * Constructor
* @param componentType of this array type * @param componentType of this array type
*/ */
private GenericArrayTypeImpl(Type componentType) { private GenericArrayTypeImpl(final Type componentType) {
this.componentType = componentType; this.componentType = componentType;
} }
@ -124,7 +124,7 @@ public String toString() {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
return obj == this || obj instanceof GenericArrayType && TypeUtils.equals(this, (GenericArrayType) obj); return obj == this || obj instanceof GenericArrayType && TypeUtils.equals(this, (GenericArrayType) obj);
} }
@ -154,7 +154,7 @@ private static final class ParameterizedTypeImpl implements ParameterizedType {
* @param useOwner owner type to use, if any * @param useOwner owner type to use, if any
* @param typeArguments formal type arguments * @param typeArguments formal type arguments
*/ */
private ParameterizedTypeImpl(Class<?> raw, Type useOwner, Type[] typeArguments) { private ParameterizedTypeImpl(final Class<?> raw, final Type useOwner, final Type[] typeArguments) {
this.raw = raw; this.raw = raw;
this.useOwner = useOwner; this.useOwner = useOwner;
this.typeArguments = typeArguments; this.typeArguments = typeArguments;
@ -196,7 +196,7 @@ public String toString() {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, ((ParameterizedType) obj)); return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, ((ParameterizedType) obj));
} }
@ -231,7 +231,7 @@ private static final class WildcardTypeImpl implements WildcardType {
* @param upperBounds of this type * @param upperBounds of this type
* @param lowerBounds of this type * @param lowerBounds of this type
*/ */
private WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) { private WildcardTypeImpl(final Type[] upperBounds, final Type[] lowerBounds) {
this.upperBounds = ObjectUtils.defaultIfNull(upperBounds, EMPTY_BOUNDS); this.upperBounds = ObjectUtils.defaultIfNull(upperBounds, EMPTY_BOUNDS);
this.lowerBounds = ObjectUtils.defaultIfNull(lowerBounds, EMPTY_BOUNDS); this.lowerBounds = ObjectUtils.defaultIfNull(lowerBounds, EMPTY_BOUNDS);
} }
@ -264,7 +264,7 @@ public String toString() {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
return obj == this || obj instanceof WildcardType && TypeUtils.equals(this, (WildcardType) obj); return obj == this || obj instanceof WildcardType && TypeUtils.equals(this, (WildcardType) obj);
} }
@ -1424,7 +1424,7 @@ private static Type[] unrollBounds(final Map<TypeVariable<?>, Type> typeArgument
* @return boolean * @return boolean
* @since 3.2 * @since 3.2
*/ */
public static boolean containsTypeVariables(Type type) { public static boolean containsTypeVariables(final Type type) {
if (type instanceof TypeVariable<?>) { if (type instanceof TypeVariable<?>) {
return true; return true;
} }
@ -1432,7 +1432,7 @@ public static boolean containsTypeVariables(Type type) {
return ((Class<?>) type).getTypeParameters().length > 0; return ((Class<?>) type).getTypeParameters().length > 0;
} }
if (type instanceof ParameterizedType) { if (type instanceof ParameterizedType) {
for (Type arg : ((ParameterizedType) type).getActualTypeArguments()) { for (final Type arg : ((ParameterizedType) type).getActualTypeArguments()) {
if (containsTypeVariables(arg)) { if (containsTypeVariables(arg)) {
return true; return true;
} }
@ -1440,7 +1440,7 @@ public static boolean containsTypeVariables(Type type) {
return false; return false;
} }
if (type instanceof WildcardType) { if (type instanceof WildcardType) {
WildcardType wild = (WildcardType) type; final WildcardType wild = (WildcardType) type;
return containsTypeVariables(TypeUtils.getImplicitLowerBounds(wild)[0]) return containsTypeVariables(TypeUtils.getImplicitLowerBounds(wild)[0])
|| containsTypeVariables(TypeUtils.getImplicitUpperBounds(wild)[0]); || containsTypeVariables(TypeUtils.getImplicitUpperBounds(wild)[0]);
} }
@ -1528,10 +1528,10 @@ public static final ParameterizedType parameterizeWithOwner(final Type owner, fi
* @param variables expected map keys * @param variables expected map keys
* @return array of map values corresponding to specified keys * @return array of map values corresponding to specified keys
*/ */
private static Type[] extractTypeArgumentsFrom(Map<TypeVariable<?>, Type> mappings, TypeVariable<?>[] variables) { private static Type[] extractTypeArgumentsFrom(final Map<TypeVariable<?>, Type> mappings, final TypeVariable<?>[] variables) {
final Type[] result = new Type[variables.length]; final Type[] result = new Type[variables.length];
int index = 0; int index = 0;
for (TypeVariable<?> var : variables) { for (final TypeVariable<?> var : variables) {
Validate.isTrue(mappings.containsKey(var), "missing argument mapping for %s", toString(var)); Validate.isTrue(mappings.containsKey(var), "missing argument mapping for %s", toString(var));
result[index++] = mappings.get(var); result[index++] = mappings.get(var);
} }
@ -1568,7 +1568,7 @@ public static GenericArrayType genericArrayType(final Type componentType) {
* @since 3.2 * @since 3.2
*/ */
@SuppressWarnings( "deprecation" ) // ObjectUtils.equals(Object, Object) has been deprecated in 3.2 @SuppressWarnings( "deprecation" ) // ObjectUtils.equals(Object, Object) has been deprecated in 3.2
public static boolean equals(Type t1, Type t2) { public static boolean equals(final Type t1, final Type t2) {
if (ObjectUtils.equals(t1, t2)) { if (ObjectUtils.equals(t1, t2)) {
return true; return true;
} }
@ -1591,7 +1591,7 @@ public static boolean equals(Type t1, Type t2) {
* @return boolean * @return boolean
* @since 3.2 * @since 3.2
*/ */
private static boolean equals(ParameterizedType p, Type t) { private static boolean equals(final ParameterizedType p, final Type t) {
if (t instanceof ParameterizedType) { if (t instanceof ParameterizedType) {
final ParameterizedType other = (ParameterizedType) t; final ParameterizedType other = (ParameterizedType) t;
if (equals(p.getRawType(), other.getRawType()) && equals(p.getOwnerType(), other.getOwnerType())) { if (equals(p.getRawType(), other.getRawType()) && equals(p.getOwnerType(), other.getOwnerType())) {
@ -1608,7 +1608,7 @@ private static boolean equals(ParameterizedType p, Type t) {
* @return boolean * @return boolean
* @since 3.2 * @since 3.2
*/ */
private static boolean equals(GenericArrayType a, Type t) { private static boolean equals(final GenericArrayType a, final Type t) {
return t instanceof GenericArrayType return t instanceof GenericArrayType
&& equals(a.getGenericComponentType(), ((GenericArrayType) t).getGenericComponentType()); && equals(a.getGenericComponentType(), ((GenericArrayType) t).getGenericComponentType());
} }
@ -1620,7 +1620,7 @@ private static boolean equals(GenericArrayType a, Type t) {
* @return boolean * @return boolean
* @since 3.2 * @since 3.2
*/ */
private static boolean equals(WildcardType w, Type t) { private static boolean equals(final WildcardType w, final Type t) {
if (t instanceof WildcardType) { if (t instanceof WildcardType) {
final WildcardType other = (WildcardType) t; final WildcardType other = (WildcardType) t;
return equals(getImplicitLowerBounds(w), getImplicitLowerBounds(other)) return equals(getImplicitLowerBounds(w), getImplicitLowerBounds(other))
@ -1636,7 +1636,7 @@ private static boolean equals(WildcardType w, Type t) {
* @return boolean * @return boolean
* @since 3.2 * @since 3.2
*/ */
private static boolean equals(Type[] t1, Type[] t2) { private static boolean equals(final Type[] t1, final Type[] t2) {
if (t1.length == t2.length) { if (t1.length == t2.length) {
for (int i = 0; i < t1.length; i++) { for (int i = 0; i < t1.length; i++) {
if (!equals(t1[i], t2[i])) { if (!equals(t1[i], t2[i])) {
@ -1655,7 +1655,7 @@ private static boolean equals(Type[] t1, Type[] t2) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
public static String toString(Type type) { public static String toString(final Type type) {
Validate.notNull(type); Validate.notNull(type);
if (type instanceof Class<?>) { if (type instanceof Class<?>) {
return classToString((Class<?>) type); return classToString((Class<?>) type);
@ -1682,7 +1682,7 @@ public static String toString(Type type) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
public static String toLongString(TypeVariable<?> var) { public static String toLongString(final TypeVariable<?> var) {
Validate.notNull(var, "var is null"); Validate.notNull(var, "var is null");
final StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration(); final GenericDeclaration d = ((TypeVariable<?>) var).getGenericDeclaration();
@ -1739,7 +1739,7 @@ public static <T> Typed<T> wrap(final Class<T> type) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
private static String classToString(Class<?> c) { private static String classToString(final Class<?> c) {
final StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
if (c.getEnclosingClass() != null) { if (c.getEnclosingClass() != null) {
@ -1761,7 +1761,7 @@ private static String classToString(Class<?> c) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
private static String typeVariableToString(TypeVariable<?> v) { private static String typeVariableToString(final TypeVariable<?> v) {
final StringBuilder buf = new StringBuilder(v.getName()); final StringBuilder buf = new StringBuilder(v.getName());
final Type[] bounds = v.getBounds(); final Type[] bounds = v.getBounds();
if (bounds.length > 0 && !(bounds.length == 1 && Object.class.equals(bounds[0]))) { if (bounds.length > 0 && !(bounds.length == 1 && Object.class.equals(bounds[0]))) {
@ -1777,7 +1777,7 @@ private static String typeVariableToString(TypeVariable<?> v) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
private static String parameterizedTypeToString(ParameterizedType p) { private static String parameterizedTypeToString(final ParameterizedType p) {
final StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
final Type useOwner = p.getOwnerType(); final Type useOwner = p.getOwnerType();
@ -1804,7 +1804,7 @@ private static String parameterizedTypeToString(ParameterizedType p) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
private static String wildcardTypeToString(WildcardType w) { private static String wildcardTypeToString(final WildcardType w) {
final StringBuilder buf = new StringBuilder().append('?'); final StringBuilder buf = new StringBuilder().append('?');
final Type[] lowerBounds = w.getLowerBounds(); final Type[] lowerBounds = w.getLowerBounds();
final Type[] upperBounds = w.getUpperBounds(); final Type[] upperBounds = w.getUpperBounds();
@ -1822,7 +1822,7 @@ private static String wildcardTypeToString(WildcardType w) {
* @return String * @return String
* @since 3.2 * @since 3.2
*/ */
private static String genericArrayTypeToString(GenericArrayType g) { private static String genericArrayTypeToString(final GenericArrayType g) {
return String.format("%s[]", toString(g.getGenericComponentType())); return String.format("%s[]", toString(g.getGenericComponentType()));
} }
@ -1834,7 +1834,7 @@ private static String genericArrayTypeToString(GenericArrayType g) {
* @return {@code buf} * @return {@code buf}
* @since 3.2 * @since 3.2
*/ */
private static StringBuilder appendAllTo(StringBuilder buf, String sep, Type... types) { private static StringBuilder appendAllTo(final StringBuilder buf, final String sep, final Type... types) {
Validate.notEmpty(Validate.noNullElements(types)); Validate.notEmpty(Validate.noNullElements(types));
if (types.length > 0) { if (types.length > 0) {
buf.append(toString(types[0])); buf.append(toString(types[0]));

View File

@ -510,7 +510,7 @@ public String replace(final StringBuffer source, final int offset, final int len
* @return the result of the replace operation * @return the result of the replace operation
* @since 3.2 * @since 3.2
*/ */
public String replace(CharSequence source) { public String replace(final CharSequence source) {
if (source == null) { if (source == null) {
return null; return null;
} }
@ -531,11 +531,11 @@ public String replace(CharSequence source) {
* @return the result of the replace operation * @return the result of the replace operation
* @since 3.2 * @since 3.2
*/ */
public String replace(CharSequence source, int offset, int length) { public String replace(final CharSequence source, final int offset, final int length) {
if (source == null) { if (source == null) {
return null; return null;
} }
StrBuilder buf = new StrBuilder(length).append(source, offset, length); final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
substitute(buf, 0, length); substitute(buf, 0, length);
return buf.toString(); return buf.toString();
} }
@ -649,7 +649,7 @@ public boolean replaceIn(final StringBuffer source, final int offset, final int
* @return true if altered * @return true if altered
* @since 3.2 * @since 3.2
*/ */
public boolean replaceIn(StringBuilder source) { public boolean replaceIn(final StringBuilder source) {
if (source == null) { if (source == null) {
return false; return false;
} }
@ -670,11 +670,11 @@ public boolean replaceIn(StringBuilder source) {
* @return true if altered * @return true if altered
* @since 3.2 * @since 3.2
*/ */
public boolean replaceIn(StringBuilder source, int offset, int length) { public boolean replaceIn(final StringBuilder source, final int offset, final int length) {
if (source == null) { if (source == null) {
return false; return false;
} }
StrBuilder buf = new StrBuilder(length).append(source, offset, length); final StrBuilder buf = new StrBuilder(length).append(source, offset, length);
if (substitute(buf, 0, length) == false) { if (substitute(buf, 0, length) == false) {
return false; return false;
} }

View File

@ -37,12 +37,12 @@ public class OctalUnescaper extends CharSequenceTranslator {
*/ */
@Override @Override
public int translate(final CharSequence input, final int index, final Writer out) throws IOException { public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \
StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
if(input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1)) ) { if(input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1)) ) {
int next = index + 1; final int next = index + 1;
int next2 = index + 2; final int next2 = index + 2;
int next3 = index + 3; final int next3 = index + 3;
// we know this is good as we checked it in the if block above // we know this is good as we checked it in the if block above
builder.append(input.charAt(next)); builder.append(input.charAt(next));
@ -65,7 +65,7 @@ public int translate(final CharSequence input, final int index, final Writer out
* @param ch the char to check * @param ch the char to check
* @return true if the given char is the character representation of one of the digits from 0 to 7 * @return true if the given char is the character representation of one of the digits from 0 to 7
*/ */
private boolean isOctalDigit(char ch) { private boolean isOctalDigit(final char ch) {
return ch >= '0' && ch <= '7'; return ch >= '0' && ch <= '7';
} }
@ -74,7 +74,7 @@ private boolean isOctalDigit(char ch) {
* @param ch the char to check * @param ch the char to check
* @return true if the given char is the character representation of one of the digits from 0 to 3 * @return true if the given char is the character representation of one of the digits from 0 to 3
*/ */
private boolean isZeroToThree(char ch) { private boolean isZeroToThree(final char ch) {
return ch >= '0' && ch <= '3'; return ch >= '0' && ch <= '3';
} }
} }

View File

@ -30,7 +30,7 @@ public class UnicodeUnpairedSurrogateRemover extends CodePointTranslator {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean translate(int codepoint, Writer out) throws IOException { public boolean translate(final int codepoint, final Writer out) throws IOException {
if (codepoint >= Character.MIN_SURROGATE && codepoint <= Character.MAX_SURROGATE) { if (codepoint >= Character.MIN_SURROGATE && codepoint <= Character.MAX_SURROGATE) {
// It's a surrogate. Write nothing and say we've translated. // It's a surrogate. Write nothing and say we've translated.
return true; return true;

View File

@ -1671,7 +1671,7 @@ private static long getFragment(final Calendar calendar, final int fragment, fin
long result = 0; long result = 0;
int offset = (unit == TimeUnit.DAYS) ? 0 : 1; final int offset = (unit == TimeUnit.DAYS) ? 0 : 1;
// Fragments bigger than a day require a breakdown to days // Fragments bigger than a day require a breakdown to days
switch (fragment) { switch (fragment) {

View File

@ -424,7 +424,7 @@ public static String formatPeriod(final long startMillis, final long endMillis,
* @return the formatted string * @return the formatted string
*/ */
static String format(final Token[] tokens, final long years, final long months, final long days, final long hours, final long minutes, final long seconds, static String format(final Token[] tokens, final long years, final long months, final long days, final long hours, final long minutes, final long seconds,
long milliseconds, final boolean padWithZeros) { final long milliseconds, final boolean padWithZeros) {
final StringBuilder buffer = new StringBuilder(); final StringBuilder buffer = new StringBuilder();
boolean lastOutputSeconds = false; boolean lastOutputSeconds = false;
for (final Token token : tokens) { for (final Token token : tokens) {
@ -454,7 +454,7 @@ static String format(final Token[] tokens, final long years, final long months,
} else if (value == S) { } else if (value == S) {
if (lastOutputSeconds) { if (lastOutputSeconds) {
// ensure at least 3 digits are displayed even if padding is not selected // ensure at least 3 digits are displayed even if padding is not selected
int width = padWithZeros ? Math.max(3, count) : 3; final int width = padWithZeros ? Math.max(3, count) : 3;
buffer.append(paddedValue(milliseconds, true, width)); buffer.append(paddedValue(milliseconds, true, width));
} else { } else {
buffer.append(paddedValue(milliseconds, padWithZeros, count)); buffer.append(paddedValue(milliseconds, padWithZeros, count));
@ -581,7 +581,7 @@ static class Token {
* @return boolean <code>true</code> if contained * @return boolean <code>true</code> if contained
*/ */
static boolean containsTokenWithValue(final Token[] tokens, final Object value) { static boolean containsTokenWithValue(final Token[] tokens, final Object value) {
for (Token token : tokens) { for (final Token token : tokens) {
if (token.getValue() == value) { if (token.getValue() == value) {
return true; return true;
} }

View File

@ -145,7 +145,7 @@ else if(locale.equals(JAPANESE_IMPERIAL)) {
* *
* @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser
*/ */
private void init(Calendar definingCalendar) { private void init(final Calendar definingCalendar) {
final StringBuilder regex= new StringBuilder(); final StringBuilder regex= new StringBuilder();
final List<Strategy> collector = new ArrayList<Strategy>(); final List<Strategy> collector = new ArrayList<Strategy>();
@ -398,7 +398,7 @@ private static Map<String, Integer> getDisplayNames(final int field, final Calen
* @return A value between centuryStart(inclusive) to centuryStart+100(exclusive) * @return A value between centuryStart(inclusive) to centuryStart+100(exclusive)
*/ */
private int adjustYear(final int twoDigitYear) { private int adjustYear(final int twoDigitYear) {
int trial= century + twoDigitYear; final int trial= century + twoDigitYear;
return twoDigitYear>=startYear ?trial :trial+100; return twoDigitYear>=startYear ?trial :trial+100;
} }
@ -606,10 +606,10 @@ private static class CaseInsensitiveTextStrategy extends Strategy {
CaseInsensitiveTextStrategy(final int field, final Calendar definingCalendar, final Locale locale) { CaseInsensitiveTextStrategy(final int field, final Calendar definingCalendar, final Locale locale) {
this.field= field; this.field= field;
this.locale= locale; this.locale= locale;
Map<String, Integer> keyValues = getDisplayNames(field, definingCalendar, locale); final Map<String, Integer> keyValues = getDisplayNames(field, definingCalendar, locale);
this.lKeyValues= new HashMap<String,Integer>(); this.lKeyValues= new HashMap<String,Integer>();
for(Map.Entry<String, Integer> entry : keyValues.entrySet()) { for(final Map.Entry<String, Integer> entry : keyValues.entrySet()) {
lKeyValues.put(entry.getKey().toLowerCase(locale), entry.getValue()); lKeyValues.put(entry.getKey().toLowerCase(locale), entry.getValue());
} }
} }
@ -751,7 +751,7 @@ private static class TimeZoneStrategy extends Strategy {
*/ */
TimeZoneStrategy(final Locale locale) { TimeZoneStrategy(final Locale locale) {
final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings();
for (String[] zone : zones) { for (final String[] zone : zones) {
if (zone[ID].startsWith("GMT")) { if (zone[ID].startsWith("GMT")) {
continue; continue;
} }

View File

@ -139,7 +139,7 @@ private F getDateTimeInstance(final Integer dateStyle, final Integer timeStyle,
* pattern defined * pattern defined
*/ */
// package protected, for access from FastDateFormat; do not make public or protected // package protected, for access from FastDateFormat; do not make public or protected
F getDateTimeInstance(final int dateStyle, final int timeStyle, final TimeZone timeZone, Locale locale) { F getDateTimeInstance(final int dateStyle, final int timeStyle, final TimeZone timeZone, final Locale locale) {
return getDateTimeInstance(Integer.valueOf(dateStyle), Integer.valueOf(timeStyle), timeZone, locale); return getDateTimeInstance(Integer.valueOf(dateStyle), Integer.valueOf(timeStyle), timeZone, locale);
} }
@ -156,7 +156,7 @@ F getDateTimeInstance(final int dateStyle, final int timeStyle, final TimeZone t
* pattern defined * pattern defined
*/ */
// package protected, for access from FastDateFormat; do not make public or protected // package protected, for access from FastDateFormat; do not make public or protected
F getDateInstance(final int dateStyle, final TimeZone timeZone, Locale locale) { F getDateInstance(final int dateStyle, final TimeZone timeZone, final Locale locale) {
return getDateTimeInstance(Integer.valueOf(dateStyle), null, timeZone, locale); return getDateTimeInstance(Integer.valueOf(dateStyle), null, timeZone, locale);
} }
@ -173,7 +173,7 @@ F getDateInstance(final int dateStyle, final TimeZone timeZone, Locale locale) {
* pattern defined * pattern defined
*/ */
// package protected, for access from FastDateFormat; do not make public or protected // package protected, for access from FastDateFormat; do not make public or protected
F getTimeInstance(final int timeStyle, final TimeZone timeZone, Locale locale) { F getTimeInstance(final int timeStyle, final TimeZone timeZone, final Locale locale) {
return getDateTimeInstance(null, Integer.valueOf(timeStyle), timeZone, locale); return getDateTimeInstance(null, Integer.valueOf(timeStyle), timeZone, locale);
} }

View File

@ -53,8 +53,8 @@ public void testToFullyQualifiedNameClassNull() throws Exception {
@Test @Test
public void testToFullyQualifiedNameClassString() throws Exception { public void testToFullyQualifiedNameClassString() throws Exception {
String expected = "org.apache.commons.lang3.Test.properties"; final String expected = "org.apache.commons.lang3.Test.properties";
String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, "Test.properties"); final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class, "Test.properties");
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -71,8 +71,8 @@ public void testToFullyQualifiedNamePackageNull() throws Exception {
@Test @Test
public void testToFullyQualifiedNamePackageString() throws Exception { public void testToFullyQualifiedNamePackageString() throws Exception {
String expected = "org.apache.commons.lang3.Test.properties"; final String expected = "org.apache.commons.lang3.Test.properties";
String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), "Test.properties"); final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), "Test.properties");
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -89,8 +89,8 @@ public void testToFullyQualifiedPathClassNull() throws Exception {
@Test @Test
public void testToFullyQualifiedPathClass() throws Exception { public void testToFullyQualifiedPathClass() throws Exception {
String expected = "org/apache/commons/lang3/Test.properties"; final String expected = "org/apache/commons/lang3/Test.properties";
String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, "Test.properties"); final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class, "Test.properties");
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -107,8 +107,8 @@ public void testToFullyQualifiedPathPackageNull() throws Exception {
@Test @Test
public void testToFullyQualifiedPathPackage() throws Exception { public void testToFullyQualifiedPathPackage() throws Exception {
String expected = "org/apache/commons/lang3/Test.properties"; final String expected = "org/apache/commons/lang3/Test.properties";
String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), "Test.properties"); final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), "Test.properties");
assertEquals(expected, actual); assertEquals(expected, actual);
} }

View File

@ -378,8 +378,8 @@ public void testIsAvailableLocale() {
*/ */
@Test @Test
public void testThreeCharsLocale() { public void testThreeCharsLocale() {
for (String str : Arrays.asList("udm", "tet")) { for (final String str : Arrays.asList("udm", "tet")) {
Locale locale = LocaleUtils.toLocale(str); final Locale locale = LocaleUtils.toLocale(str);
assertNotNull(locale); assertNotNull(locale);
assertEquals(str, locale.getLanguage()); assertEquals(str, locale.getLanguage());
assertTrue(StringUtils.isBlank(locale.getCountry())); assertTrue(StringUtils.isBlank(locale.getCountry()));
@ -554,11 +554,11 @@ public void testLang865() {
@Test @Test
public void testParseAllLocales() { public void testParseAllLocales() {
Locale[] locales = Locale.getAvailableLocales(); final Locale[] locales = Locale.getAvailableLocales();
int failures = 0; int failures = 0;
for (Locale l : locales) { for (final Locale l : locales) {
// Check if it's possible to recreate the Locale using just the standard constructor // Check if it's possible to recreate the Locale using just the standard constructor
Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant()); final Locale locale = new Locale(l.getLanguage(), l.getCountry(), l.getVariant());
if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales if (l.equals(locale)) { // it is possible for LocaleUtils.toLocale to handle these Locales
String str = l.toString(); String str = l.toString();
// Look for the script/extension suffix // Look for the script/extension suffix
@ -572,12 +572,12 @@ public void testParseAllLocales() {
System.out.println("Should not have parsed: " + str); System.out.println("Should not have parsed: " + str);
failures++; failures++;
continue; // try next Locale continue; // try next Locale
} catch (IllegalArgumentException iae) { } catch (final IllegalArgumentException iae) {
// expected; try without suffix // expected; try without suffix
str = str.substring(0, suff); str = str.substring(0, suff);
} }
} }
Locale loc = LocaleUtils.toLocale(str); final Locale loc = LocaleUtils.toLocale(str);
if (!l.equals(loc)) { if (!l.equals(loc)) {
System.out.println("Failed to parse: " + str); System.out.println("Failed to parse: " + str);
failures++; failures++;

View File

@ -29,9 +29,9 @@ public class NotImplementedExceptionTest {
@Test @Test
public void testConstructors() { public void testConstructors() {
Throwable nested = new RuntimeException(); final Throwable nested = new RuntimeException();
String message = "Not Implemented"; final String message = "Not Implemented";
String code = "CODE"; final String code = "CODE";
NotImplementedException nie = new NotImplementedException(message); NotImplementedException nie = new NotImplementedException(message);
assertCorrect("Issue in (String)", nie, message, null, null); assertCorrect("Issue in (String)", nie, message, null, null);
@ -47,7 +47,7 @@ public void testConstructors() {
assertCorrect("Issue in (String, Throwable, String)", nie, message, nested, code); assertCorrect("Issue in (String, Throwable, String)", nie, message, nested, code);
} }
private void assertCorrect(String assertMessage, NotImplementedException nie, String message, Throwable nested, String code) { private void assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code) {
assertNotNull(assertMessage + ": target is null", nie); assertNotNull(assertMessage + ": target is null", nie);
assertEquals(assertMessage + ": Message not equal", message, nie.getMessage()); assertEquals(assertMessage + ": Message not equal", message, nie.getMessage());
assertEquals(assertMessage + ": Nested throwable not equal", nested, nie.getCause()); assertEquals(assertMessage + ": Nested throwable not equal", nested, nie.getCause());

View File

@ -264,7 +264,7 @@ public void testIdentityToStringAppendable() {
final Appendable appendable = new StringBuilder(); final Appendable appendable = new StringBuilder();
ObjectUtils.identityToString(appendable, i); ObjectUtils.identityToString(appendable, i);
assertEquals(expected, appendable.toString()); assertEquals(expected, appendable.toString());
} catch(IOException ex) { } catch(final IOException ex) {
fail("IOException unexpected"); fail("IOException unexpected");
} }
@ -272,14 +272,14 @@ public void testIdentityToStringAppendable() {
ObjectUtils.identityToString((Appendable)null, "tmp"); ObjectUtils.identityToString((Appendable)null, "tmp");
fail("NullPointerException expected"); fail("NullPointerException expected");
} catch(final NullPointerException npe) { } catch(final NullPointerException npe) {
} catch (IOException ex) { } catch (final IOException ex) {
} }
try { try {
ObjectUtils.identityToString((Appendable)(new StringBuilder()), null); ObjectUtils.identityToString((Appendable)(new StringBuilder()), null);
fail("NullPointerException expected"); fail("NullPointerException expected");
} catch(final NullPointerException npe) { } catch(final NullPointerException npe) {
} catch (IOException ex) { } catch (final IOException ex) {
} }
} }

View File

@ -93,7 +93,7 @@ public void testZeroLengthNextBytes() throws Exception {
*/ */
@Test @Test
public void testNextBytes() throws Exception { public void testNextBytes() throws Exception {
byte[] result = RandomUtils.nextBytes(20); final byte[] result = RandomUtils.nextBytes(20);
assertEquals(20, result.length); assertEquals(20, result.length);
} }
@ -110,7 +110,7 @@ public void testNextIntMinimalRange() throws Exception {
*/ */
@Test @Test
public void testNextInt() throws Exception { public void testNextInt() throws Exception {
int result = RandomUtils.nextInt(33, 42); final int result = RandomUtils.nextInt(33, 42);
assertTrue(result >= 33 && result < 42); assertTrue(result >= 33 && result < 42);
} }
@ -135,7 +135,7 @@ public void testNextFloatMinimalRange() throws Exception {
*/ */
@Test @Test
public void testNextDouble() throws Exception { public void testNextDouble() throws Exception {
double result = RandomUtils.nextDouble(33d, 42d); final double result = RandomUtils.nextDouble(33d, 42d);
assertTrue(result >= 33d && result <= 42d); assertTrue(result >= 33d && result <= 42d);
} }
@ -144,7 +144,7 @@ public void testNextDouble() throws Exception {
*/ */
@Test @Test
public void testNextFloat() throws Exception { public void testNextFloat() throws Exception {
double result = RandomUtils.nextFloat(33f, 42f); final double result = RandomUtils.nextFloat(33f, 42f);
assertTrue(result >= 33f && result <= 42f); assertTrue(result >= 33f && result <= 42f);
} }
@ -161,7 +161,7 @@ public void testNextLongMinimalRange() throws Exception {
*/ */
@Test @Test
public void testNextLong() throws Exception { public void testNextLong() throws Exception {
long result = RandomUtils.nextLong(33L, 42L); final long result = RandomUtils.nextLong(33L, 42L);
assertTrue(result >= 33L && result < 42L); assertTrue(result >= 33L && result < 42L);
} }
@ -171,7 +171,7 @@ public void testNextLong() throws Exception {
*/ */
@Test @Test
public void testExtremeRangeInt() throws Exception { public void testExtremeRangeInt() throws Exception {
int result = RandomUtils.nextInt(0, Integer.MAX_VALUE); final int result = RandomUtils.nextInt(0, Integer.MAX_VALUE);
assertTrue(result >= 0 && result < Integer.MAX_VALUE); assertTrue(result >= 0 && result < Integer.MAX_VALUE);
} }
@ -180,7 +180,7 @@ public void testExtremeRangeInt() throws Exception {
*/ */
@Test @Test
public void testExtremeRangeLong() throws Exception { public void testExtremeRangeLong() throws Exception {
long result = RandomUtils.nextLong(0, Long.MAX_VALUE); final long result = RandomUtils.nextLong(0, Long.MAX_VALUE);
assertTrue(result >= 0 && result < Long.MAX_VALUE); assertTrue(result >= 0 && result < Long.MAX_VALUE);
} }
@ -189,7 +189,7 @@ public void testExtremeRangeLong() throws Exception {
*/ */
@Test @Test
public void testExtremeRangeFloat() throws Exception { public void testExtremeRangeFloat() throws Exception {
float result = RandomUtils.nextFloat(0, Float.MAX_VALUE); final float result = RandomUtils.nextFloat(0, Float.MAX_VALUE);
assertTrue(result >= 0f && result <= Float.MAX_VALUE); assertTrue(result >= 0f && result <= Float.MAX_VALUE);
} }
@ -198,7 +198,7 @@ public void testExtremeRangeFloat() throws Exception {
*/ */
@Test @Test
public void testExtremeRangeDouble() throws Exception { public void testExtremeRangeDouble() throws Exception {
double result = RandomUtils.nextDouble(0, Double.MAX_VALUE); final double result = RandomUtils.nextDouble(0, Double.MAX_VALUE);
assertTrue(result >= 0 && result <= Double.MAX_VALUE); assertTrue(result >= 0 && result <= Double.MAX_VALUE);
} }
} }

View File

@ -273,7 +273,7 @@ public void testDeserializeStreamClassNotFound() throws Exception {
@Test @Test
public void testRoundtrip() { public void testRoundtrip() {
HashMap<Object, Object> newMap = SerializationUtils.roundtrip(iMap); final HashMap<Object, Object> newMap = SerializationUtils.roundtrip(iMap);
assertEquals(iMap, newMap); assertEquals(iMap, newMap);
} }

View File

@ -219,7 +219,7 @@ public void testEscapeEcmaScript() {
@Test @Test
public void testEscapeHtml() { public void testEscapeHtml() {
for (String[] element : HTML_ESCAPES) { for (final String[] element : HTML_ESCAPES) {
final String message = element[0]; final String message = element[0];
final String expected = element[1]; final String expected = element[1];
final String original = element[2]; final String original = element[2];
@ -236,7 +236,7 @@ public void testEscapeHtml() {
@Test @Test
public void testUnescapeHtml4() { public void testUnescapeHtml4() {
for (String[] element : HTML_ESCAPES) { for (final String[] element : HTML_ESCAPES) {
final String message = element[0]; final String message = element[0];
final String expected = element[2]; final String expected = element[2];
final String original = element[1]; final String original = element[1];
@ -584,9 +584,9 @@ public void testLang720() {
*/ */
@Test @Test
public void testLang911() { public void testLang911() {
String bellsTest = "\ud83d\udc80\ud83d\udd14"; final String bellsTest = "\ud83d\udc80\ud83d\udd14";
String value = StringEscapeUtils.escapeJava(bellsTest); final String value = StringEscapeUtils.escapeJava(bellsTest);
String valueTest = StringEscapeUtils.unescapeJava(value); final String valueTest = StringEscapeUtils.unescapeJava(value);
assertEquals(bellsTest, valueTest); assertEquals(bellsTest, valueTest);
} }
@ -610,8 +610,8 @@ public void testEscapeJson() {
assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\"")); assertEquals("He didn't say, \\\"stop!\\\"", StringEscapeUtils.escapeJson("He didn't say, \"stop!\""));
String expected = "\\\"foo\\\" isn't \\\"bar\\\". specials: \\b\\r\\n\\f\\t\\\\\\/"; final String expected = "\\\"foo\\\" isn't \\\"bar\\\". specials: \\b\\r\\n\\f\\t\\\\\\/";
String input ="\"foo\" isn't \"bar\". specials: \b\r\n\f\t\\/"; final String input ="\"foo\" isn't \"bar\". specials: \b\r\n\f\t\\/";
assertEquals(expected, StringEscapeUtils.escapeJson(input)); assertEquals(expected, StringEscapeUtils.escapeJson(input));
} }

View File

@ -55,7 +55,7 @@ public class StringUtilsTest {
static { static {
String ws = ""; String ws = "";
String nws = ""; String nws = "";
String hs = String.valueOf(((char) 160)); final String hs = String.valueOf(((char) 160));
String tr = ""; String tr = "";
String ntr = ""; String ntr = "";
for (int i = 0; i < Character.MAX_VALUE; i++) { for (int i = 0; i < Character.MAX_VALUE; i++) {

View File

@ -54,7 +54,7 @@ private static class TypeTestClass implements Diffable<TypeTestClass> {
private Object[] objectArrayField = {null}; private Object[] objectArrayField = {null};
@Override @Override
public DiffResult diff(TypeTestClass obj) { public DiffResult diff(final TypeTestClass obj) {
return new DiffBuilder(this, obj, style) return new DiffBuilder(this, obj, style)
.append("boolean", booleanField, obj.booleanField) .append("boolean", booleanField, obj.booleanField)
.append("booleanArray", booleanArrayField, obj.booleanArrayField) .append("booleanArray", booleanArrayField, obj.booleanArrayField)
@ -83,7 +83,7 @@ public int hashCode() {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
return EqualsBuilder.reflectionEquals(this, obj, false); return EqualsBuilder.reflectionEquals(this, obj, false);
} }
} }
@ -91,12 +91,12 @@ public boolean equals(Object obj) {
@Test @Test
public void testBoolean() { public void testBoolean() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.booleanField = false; class2.booleanField = false;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Boolean.class, diff.getType()); assertEquals(Boolean.class, diff.getType());
assertEquals(Boolean.TRUE, diff.getLeft()); assertEquals(Boolean.TRUE, diff.getLeft());
assertEquals(Boolean.FALSE, diff.getRight()); assertEquals(Boolean.FALSE, diff.getRight());
@ -104,12 +104,12 @@ public void testBoolean() {
@Test @Test
public void testBooleanArray() throws Exception { public void testBooleanArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.booleanArrayField = new boolean[] {false, false}; class2.booleanArrayField = new boolean[] {false, false};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.booleanArrayField), assertArrayEquals(ArrayUtils.toObject(class1.booleanArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.booleanArrayField), assertArrayEquals(ArrayUtils.toObject(class2.booleanArrayField),
@ -119,24 +119,24 @@ public void testBooleanArray() throws Exception {
@Test @Test
public void testByte() { public void testByte() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.byteField = 0x01; class2.byteField = 0x01;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Byte.valueOf(class1.byteField), diff.getLeft()); assertEquals(Byte.valueOf(class1.byteField), diff.getLeft());
assertEquals(Byte.valueOf(class2.byteField), diff.getRight()); assertEquals(Byte.valueOf(class2.byteField), diff.getRight());
} }
@Test @Test
public void testByteArray() throws Exception { public void testByteArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.byteArrayField= new byte[] {0x01, 0x02}; class2.byteArrayField= new byte[] {0x01, 0x02};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.byteArrayField), assertArrayEquals(ArrayUtils.toObject(class1.byteArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.byteArrayField), assertArrayEquals(ArrayUtils.toObject(class2.byteArrayField),
@ -145,12 +145,12 @@ public void testByteArray() throws Exception {
@Test @Test
public void testChar() { public void testChar() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.charField = 'z'; class2.charField = 'z';
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Character.valueOf(class1.charField), diff.getLeft()); assertEquals(Character.valueOf(class1.charField), diff.getLeft());
assertEquals(Character.valueOf(class2.charField), diff.getRight()); assertEquals(Character.valueOf(class2.charField), diff.getRight());
} }
@ -158,12 +158,12 @@ public void testChar() {
@Test @Test
public void testCharArray() throws Exception { public void testCharArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.charArrayField = new char[] {'f', 'o', 'o'}; class2.charArrayField = new char[] {'f', 'o', 'o'};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.charArrayField), assertArrayEquals(ArrayUtils.toObject(class1.charArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.charArrayField), assertArrayEquals(ArrayUtils.toObject(class2.charArrayField),
@ -173,12 +173,12 @@ public void testCharArray() throws Exception {
@Test @Test
public void testDouble() { public void testDouble() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.doubleField = 99.99; class2.doubleField = 99.99;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Double.valueOf(class1.doubleField), diff.getLeft()); assertEquals(Double.valueOf(class1.doubleField), diff.getLeft());
assertEquals(Double.valueOf(class2.doubleField), diff.getRight()); assertEquals(Double.valueOf(class2.doubleField), diff.getRight());
} }
@ -186,12 +186,12 @@ public void testDouble() {
@Test @Test
public void testDoubleArray() throws Exception { public void testDoubleArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.doubleArrayField = new double[] {3.0, 2.9, 2.8}; class2.doubleArrayField = new double[] {3.0, 2.9, 2.8};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.doubleArrayField), assertArrayEquals(ArrayUtils.toObject(class1.doubleArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.doubleArrayField), assertArrayEquals(ArrayUtils.toObject(class2.doubleArrayField),
@ -200,12 +200,12 @@ public void testDoubleArray() throws Exception {
@Test @Test
public void testFloat() { public void testFloat() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.floatField = 99.99F; class2.floatField = 99.99F;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Float.valueOf(class1.floatField), diff.getLeft()); assertEquals(Float.valueOf(class1.floatField), diff.getLeft());
assertEquals(Float.valueOf(class2.floatField), diff.getRight()); assertEquals(Float.valueOf(class2.floatField), diff.getRight());
} }
@ -213,12 +213,12 @@ public void testFloat() {
@Test @Test
public void testFloatArray() throws Exception { public void testFloatArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.floatArrayField = new float[] {3.0F, 2.9F, 2.8F}; class2.floatArrayField = new float[] {3.0F, 2.9F, 2.8F};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.floatArrayField), assertArrayEquals(ArrayUtils.toObject(class1.floatArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.floatArrayField), assertArrayEquals(ArrayUtils.toObject(class2.floatArrayField),
@ -228,12 +228,12 @@ public void testFloatArray() throws Exception {
@Test @Test
public void testInt() { public void testInt() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.intField = 42; class2.intField = 42;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Integer.valueOf(class1.intField), diff.getLeft()); assertEquals(Integer.valueOf(class1.intField), diff.getLeft());
assertEquals(Integer.valueOf(class2.intField), diff.getRight()); assertEquals(Integer.valueOf(class2.intField), diff.getRight());
} }
@ -241,12 +241,12 @@ public void testInt() {
@Test @Test
public void testIntArray() throws Exception { public void testIntArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.intArrayField = new int[] {3, 2, 1}; class2.intArrayField = new int[] {3, 2, 1};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.intArrayField), assertArrayEquals(ArrayUtils.toObject(class1.intArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.intArrayField), assertArrayEquals(ArrayUtils.toObject(class2.intArrayField),
@ -255,12 +255,12 @@ public void testIntArray() throws Exception {
@Test @Test
public void testLong() { public void testLong() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.longField = 42L; class2.longField = 42L;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Long.valueOf(class1.longField), diff.getLeft()); assertEquals(Long.valueOf(class1.longField), diff.getLeft());
assertEquals(Long.valueOf(class2.longField), diff.getRight()); assertEquals(Long.valueOf(class2.longField), diff.getRight());
} }
@ -268,12 +268,12 @@ public void testLong() {
@Test @Test
public void testLongArray() throws Exception { public void testLongArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.longArrayField = new long[] {3L, 2L, 1L}; class2.longArrayField = new long[] {3L, 2L, 1L};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.longArrayField), assertArrayEquals(ArrayUtils.toObject(class1.longArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.longArrayField), assertArrayEquals(ArrayUtils.toObject(class2.longArrayField),
@ -282,12 +282,12 @@ public void testLongArray() throws Exception {
@Test @Test
public void testShort() { public void testShort() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.shortField = 42; class2.shortField = 42;
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(Short.valueOf(class1.shortField), diff.getLeft()); assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
assertEquals(Short.valueOf(class2.shortField), diff.getRight()); assertEquals(Short.valueOf(class2.shortField), diff.getRight());
} }
@ -295,12 +295,12 @@ public void testShort() {
@Test @Test
public void testShortArray() throws Exception { public void testShortArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.shortArrayField = new short[] {3, 2, 1}; class2.shortArrayField = new short[] {3, 2, 1};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField), assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
(Object[]) diff.getLeft()); (Object[]) diff.getLeft());
assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField), assertArrayEquals(ArrayUtils.toObject(class2.shortArrayField),
@ -309,53 +309,53 @@ public void testShortArray() throws Exception {
@Test @Test
public void testObject() throws Exception { public void testObject() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.objectField = "Some string"; class2.objectField = "Some string";
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertEquals(class1.objectField, diff.getLeft()); assertEquals(class1.objectField, diff.getLeft());
assertEquals(class2.objectField, diff.getRight()); assertEquals(class2.objectField, diff.getRight());
} }
@Test @Test
public void testObjectsEqual() throws Exception { public void testObjectsEqual() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class1.objectField = "Some string"; class1.objectField = "Some string";
class2.objectField = "Some string"; class2.objectField = "Some string";
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(0, list.getNumberOfDiffs()); assertEquals(0, list.getNumberOfDiffs());
} }
@Test @Test
public void testObjectArray() throws Exception { public void testObjectArray() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class2.objectArrayField = new Object[] {"string", 1, 2}; class2.objectArrayField = new Object[] {"string", 1, 2};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0); final Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft()); assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight()); assertArrayEquals(class2.objectArrayField, (Object[]) diff.getRight());
} }
@Test @Test
public void testObjectArrayEqual() throws Exception { public void testObjectArrayEqual() throws Exception {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass(); final TypeTestClass class2 = new TypeTestClass();
class1.objectArrayField = new Object[] {"string", 1, 2}; class1.objectArrayField = new Object[] {"string", 1, 2};
class2.objectArrayField = new Object[] {"string", 1, 2}; class2.objectArrayField = new Object[] {"string", 1, 2};
DiffResult list = class1.diff(class2); final DiffResult list = class1.diff(class2);
assertEquals(0, list.getNumberOfDiffs()); assertEquals(0, list.getNumberOfDiffs());
} }
@Test @Test
public void testByteArrayEqualAsObject() throws Exception { public void testByteArrayEqualAsObject() throws Exception {
DiffResult list = new DiffBuilder("String1", "String2", SHORT_STYLE) final DiffResult list = new DiffBuilder("String1", "String2", SHORT_STYLE)
.append("foo", (Object) new boolean[] {false}, (Object) new boolean[] {false}) .append("foo", (Object) new boolean[] {false}, (Object) new boolean[] {false})
.append("foo", (Object) new byte[] {0x01}, (Object) new byte[] {0x01}) .append("foo", (Object) new byte[] {0x01}, (Object) new byte[] {0x01})
.append("foo", (Object) new char[] {'a'}, (Object) new char[] {'a'}) .append("foo", (Object) new char[] {'a'}, (Object) new char[] {'a'})
@ -384,8 +384,8 @@ public void testNullRhs() {
@Test @Test
public void testSameObjectIgnoresAppends() { public void testSameObjectIgnoresAppends() {
TypeTestClass testClass = new TypeTestClass(); final TypeTestClass testClass = new TypeTestClass();
DiffResult list = new DiffBuilder(testClass, testClass, SHORT_STYLE) final DiffResult list = new DiffBuilder(testClass, testClass, SHORT_STYLE)
.append("ignored", false, true) .append("ignored", false, true)
.build(); .build();
assertEquals(0, list.getNumberOfDiffs()); assertEquals(0, list.getNumberOfDiffs());
@ -393,9 +393,9 @@ public void testSameObjectIgnoresAppends() {
@Test @Test
public void testSimilarObjectIgnoresAppends() { public void testSimilarObjectIgnoresAppends() {
TypeTestClass testClass1 = new TypeTestClass(); final TypeTestClass testClass1 = new TypeTestClass();
TypeTestClass testClass2 = new TypeTestClass(); final TypeTestClass testClass2 = new TypeTestClass();
DiffResult list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE) final DiffResult list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE)
.append("ignored", false, true) .append("ignored", false, true)
.build(); .build();
assertEquals(0, list.getNumberOfDiffs()); assertEquals(0, list.getNumberOfDiffs());
@ -404,7 +404,7 @@ public void testSimilarObjectIgnoresAppends() {
@Test @Test
public void testStylePassedToDiffResult() { public void testStylePassedToDiffResult() {
TypeTestClass class1 = new TypeTestClass(); final TypeTestClass class1 = new TypeTestClass();
DiffResult list = class1.diff(class1); DiffResult list = class1.diff(class1);
assertEquals(SHORT_STYLE, list.getToStringStyle()); assertEquals(SHORT_STYLE, list.getToStringStyle());

View File

@ -36,9 +36,9 @@ public class DiffResultTest {
private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE; private static final ToStringStyle SHORT_STYLE = ToStringStyle.SHORT_PREFIX_STYLE;
private static class SimpleClass implements Diffable<SimpleClass> { private static class SimpleClass implements Diffable<SimpleClass> {
private boolean booleanField; private final boolean booleanField;
public SimpleClass(boolean booleanField) { public SimpleClass(final boolean booleanField) {
this.booleanField = booleanField; this.booleanField = booleanField;
} }
@ -47,7 +47,7 @@ public static String getFieldName() {
} }
@Override @Override
public DiffResult diff(SimpleClass obj) { public DiffResult diff(final SimpleClass obj) {
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE) return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
.append(getFieldName(), booleanField, obj.booleanField) .append(getFieldName(), booleanField, obj.booleanField)
.build(); .build();
@ -59,12 +59,12 @@ private static class EmptyClass {
@Test(expected = UnsupportedOperationException.class) @Test(expected = UnsupportedOperationException.class)
public void testListIsNonModifiable() { public void testListIsNonModifiable() {
SimpleClass lhs = new SimpleClass(true); final SimpleClass lhs = new SimpleClass(true);
SimpleClass rhs = new SimpleClass(false); final SimpleClass rhs = new SimpleClass(false);
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs(); final List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE); final DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
assertEquals(diffs, list.getDiffs()); assertEquals(diffs, list.getDiffs());
assertEquals(1, list.getNumberOfDiffs()); assertEquals(1, list.getNumberOfDiffs());
list.getDiffs().remove(0); list.getDiffs().remove(0);
@ -72,14 +72,14 @@ public void testListIsNonModifiable() {
@Test @Test
public void testIterator() { public void testIterator() {
SimpleClass lhs = new SimpleClass(true); final SimpleClass lhs = new SimpleClass(true);
SimpleClass rhs = new SimpleClass(false); final SimpleClass rhs = new SimpleClass(false);
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs(); final List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
Iterator<Diff<?>> expectedIterator = diffs.iterator(); final Iterator<Diff<?>> expectedIterator = diffs.iterator();
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE); final DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
Iterator<Diff<?>> iterator = list.iterator(); final Iterator<Diff<?>> iterator = list.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
assertTrue(expectedIterator.hasNext()); assertTrue(expectedIterator.hasNext());
@ -89,7 +89,7 @@ public void testIterator() {
@Test @Test
public void testToStringOutput() { public void testToStringOutput() {
DiffResult list = new DiffBuilder(new EmptyClass(), new EmptyClass(), final DiffResult list = new DiffBuilder(new EmptyClass(), new EmptyClass(),
ToStringStyle.SHORT_PREFIX_STYLE).append("test", false, true) ToStringStyle.SHORT_PREFIX_STYLE).append("test", false, true)
.build(); .build();
assertEquals( assertEquals(
@ -99,18 +99,18 @@ public void testToStringOutput() {
@Test @Test
public void testToStringSpecifyStyleOutput() { public void testToStringSpecifyStyleOutput() {
DiffResult list = SIMPLE_FALSE.diff(SIMPLE_TRUE); final DiffResult list = SIMPLE_FALSE.diff(SIMPLE_TRUE);
assertTrue(list.getToStringStyle().equals(SHORT_STYLE)); assertTrue(list.getToStringStyle().equals(SHORT_STYLE));
String lhsString = new ToStringBuilder(SIMPLE_FALSE, final String lhsString = new ToStringBuilder(SIMPLE_FALSE,
ToStringStyle.MULTI_LINE_STYLE).append( ToStringStyle.MULTI_LINE_STYLE).append(
SimpleClass.getFieldName(), SIMPLE_FALSE.booleanField).build(); SimpleClass.getFieldName(), SIMPLE_FALSE.booleanField).build();
String rhsString = new ToStringBuilder(SIMPLE_TRUE, final String rhsString = new ToStringBuilder(SIMPLE_TRUE,
ToStringStyle.MULTI_LINE_STYLE).append( ToStringStyle.MULTI_LINE_STYLE).append(
SimpleClass.getFieldName(), SIMPLE_TRUE.booleanField).build(); SimpleClass.getFieldName(), SIMPLE_TRUE.booleanField).build();
String expectedOutput = String.format("%s differs from %s", lhsString, final String expectedOutput = String.format("%s differs from %s", lhsString,
rhsString); rhsString);
assertEquals(expectedOutput, assertEquals(expectedOutput,
list.toString(ToStringStyle.MULTI_LINE_STYLE)); list.toString(ToStringStyle.MULTI_LINE_STYLE));
@ -135,14 +135,14 @@ public void testNullList() {
@Test @Test
public void testNullStyle() { public void testNullStyle() {
DiffResult diffResult = new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE final DiffResult diffResult = new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE
.diff(SIMPLE_FALSE).getDiffs(), null); .diff(SIMPLE_FALSE).getDiffs(), null);
assertEquals(ToStringStyle.DEFAULT_STYLE, diffResult.getToStringStyle()); assertEquals(ToStringStyle.DEFAULT_STYLE, diffResult.getToStringStyle());
} }
@Test @Test
public void testNoDifferencesString() { public void testNoDifferencesString() {
DiffResult diffResult = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE, final DiffResult diffResult = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE,
SHORT_STYLE).build(); SHORT_STYLE).build();
assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString()); assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString());
} }

View File

@ -34,7 +34,7 @@ public class DiffTest {
private static class BooleanDiff extends Diff<Boolean> { private static class BooleanDiff extends Diff<Boolean> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
protected BooleanDiff(String fieldName) { protected BooleanDiff(final String fieldName) {
super(fieldName); super(fieldName);
} }

View File

@ -1133,17 +1133,17 @@ public void testReflectionArrays() throws Exception {
final TestObject one = new TestObject(1); final TestObject one = new TestObject(1);
final TestObject two = new TestObject(2); final TestObject two = new TestObject(2);
Object[] o1 = new Object[] { one }; final Object[] o1 = new Object[] { one };
Object[] o2 = new Object[] { two }; final Object[] o2 = new Object[] { two };
Object[] o3 = new Object[] { one }; final Object[] o3 = new Object[] { one };
assertTrue(!EqualsBuilder.reflectionEquals(o1, o2)); assertTrue(!EqualsBuilder.reflectionEquals(o1, o2));
assertTrue(EqualsBuilder.reflectionEquals(o1, o1)); assertTrue(EqualsBuilder.reflectionEquals(o1, o1));
assertTrue(EqualsBuilder.reflectionEquals(o1, o3)); assertTrue(EqualsBuilder.reflectionEquals(o1, o3));
double[] d1 = { 0, 1 }; final double[] d1 = { 0, 1 };
double[] d2 = { 2, 3 }; final double[] d2 = { 2, 3 };
double[] d3 = { 0, 1 }; final double[] d3 = { 0, 1 };
assertTrue(!EqualsBuilder.reflectionEquals(d1, d2)); assertTrue(!EqualsBuilder.reflectionEquals(d1, d2));
assertTrue(EqualsBuilder.reflectionEquals(d1, d1)); assertTrue(EqualsBuilder.reflectionEquals(d1, d1));

View File

@ -121,9 +121,9 @@ public void testToFloatStringF() {
*/ */
@Test @Test
public void testStringCreateNumberEnsureNoPrecisionLoss(){ public void testStringCreateNumberEnsureNoPrecisionLoss(){
String shouldBeFloat = "1.23"; final String shouldBeFloat = "1.23";
String shouldBeDouble = "3.40282354e+38"; final String shouldBeDouble = "3.40282354e+38";
String shouldBeBigDecimal = "1.797693134862315759e+308"; final String shouldBeBigDecimal = "1.797693134862315759e+308";
assertTrue(NumberUtils.createNumber(shouldBeFloat) instanceof Float); assertTrue(NumberUtils.createNumber(shouldBeFloat) instanceof Float);
assertTrue(NumberUtils.createNumber(shouldBeDouble) instanceof Double); assertTrue(NumberUtils.createNumber(shouldBeDouble) instanceof Double);

View File

@ -1255,7 +1255,7 @@ public void testAmbig() {
@Test @Test
public void testRemoveFinalModifier() throws Exception { public void testRemoveFinalModifier() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2"); final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
assertFalse(field.isAccessible()); assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers())); assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field); FieldUtils.removeFinalModifier(field);
@ -1266,7 +1266,7 @@ public void testRemoveFinalModifier() throws Exception {
@Test @Test
public void testRemoveFinalModifierWithAccess() throws Exception { public void testRemoveFinalModifierWithAccess() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2"); final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
assertFalse(field.isAccessible()); assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers())); assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, true); FieldUtils.removeFinalModifier(field, true);
@ -1277,7 +1277,7 @@ public void testRemoveFinalModifierWithAccess() throws Exception {
@Test @Test
public void testRemoveFinalModifierWithoutAccess() throws Exception { public void testRemoveFinalModifierWithoutAccess() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2"); final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
assertFalse(field.isAccessible()); assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers())); assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, false); FieldUtils.removeFinalModifier(field, false);
@ -1288,7 +1288,7 @@ public void testRemoveFinalModifierWithoutAccess() throws Exception {
@Test @Test
public void testRemoveFinalModifierAccessNotNeeded() throws Exception { public void testRemoveFinalModifierAccessNotNeeded() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE"); final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE");
assertFalse(field.isAccessible()); assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers())); assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, false); FieldUtils.removeFinalModifier(field, false);

View File

@ -392,7 +392,7 @@ public void testGetOverrideHierarchyIncludingInterfaces() {
new MethodDescriptor(GenericParent.class, "consume", GenericParent.class.getTypeParameters()[0]), new MethodDescriptor(GenericParent.class, "consume", GenericParent.class.getTypeParameters()[0]),
new MethodDescriptor(GenericConsumer.class, "consume", GenericConsumer.class.getTypeParameters()[0])) new MethodDescriptor(GenericConsumer.class, "consume", GenericConsumer.class.getTypeParameters()[0]))
.iterator(); .iterator();
for (Method m : MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE)) { for (final Method m : MethodUtils.getOverrideHierarchy(method, Interfaces.INCLUDE)) {
assertTrue(expected.hasNext()); assertTrue(expected.hasNext());
final MethodDescriptor md = expected.next(); final MethodDescriptor md = expected.next();
assertEquals(md.declaringClass, m.getDeclaringClass()); assertEquals(md.declaringClass, m.getDeclaringClass());
@ -412,7 +412,7 @@ public void testGetOverrideHierarchyExcludingInterfaces() {
Arrays.asList(new MethodDescriptor(StringParameterizedChild.class, "consume", String.class), Arrays.asList(new MethodDescriptor(StringParameterizedChild.class, "consume", String.class),
new MethodDescriptor(GenericParent.class, "consume", GenericParent.class.getTypeParameters()[0])) new MethodDescriptor(GenericParent.class, "consume", GenericParent.class.getTypeParameters()[0]))
.iterator(); .iterator();
for (Method m : MethodUtils.getOverrideHierarchy(method, Interfaces.EXCLUDE)) { for (final Method m : MethodUtils.getOverrideHierarchy(method, Interfaces.EXCLUDE)) {
assertTrue(expected.hasNext()); assertTrue(expected.hasNext());
final MethodDescriptor md = expected.next(); final MethodDescriptor md = expected.next();
assertEquals(md.declaringClass, m.getDeclaringClass()); assertEquals(md.declaringClass, m.getDeclaringClass());
@ -466,7 +466,7 @@ private static class MethodDescriptor {
final String name; final String name;
final Type[] parameterTypes; final Type[] parameterTypes;
MethodDescriptor(Class<?> declaringClass, String name, Type... parameterTypes) { MethodDescriptor(final Class<?> declaringClass, final String name, final Type... parameterTypes) {
this.declaringClass = declaringClass; this.declaringClass = declaringClass;
this.name = name; this.name = name;
this.parameterTypes = parameterTypes; this.parameterTypes = parameterTypes;

View File

@ -23,7 +23,7 @@
public class GenericParent<T> implements GenericConsumer<T> { public class GenericParent<T> implements GenericConsumer<T> {
@Override @Override
public void consume(T t) { public void consume(final T t) {
} }
} }

View File

@ -22,7 +22,7 @@
*/ */
public class StringParameterizedChild extends GenericParent<String> { public class StringParameterizedChild extends GenericParent<String> {
@Override @Override
public void consume(String t) { public void consume(final String t) {
super.consume(t); super.consume(t);
} }
} }

View File

@ -1049,8 +1049,8 @@ public void testAppend_FormattedString() {
sb = new StrBuilder(); sb = new StrBuilder();
sb.append("Hi %s %,d", "Alice", 5000); sb.append("Hi %s %,d", "Alice", 5000);
// group separator depends on system locale // group separator depends on system locale
char groupingSeparator = DecimalFormatSymbols.getInstance().getGroupingSeparator(); final char groupingSeparator = DecimalFormatSymbols.getInstance().getGroupingSeparator();
String expected = "Hi Alice 5" + groupingSeparator + "000"; final String expected = "Hi Alice 5" + groupingSeparator + "000";
assertEquals(expected, sb.toString()); assertEquals(expected, sb.toString());
} }

View File

@ -101,8 +101,8 @@ public void testChaining() {
public void testReadFromReader() throws Exception { public void testReadFromReader() throws Exception {
String s = ""; String s = "";
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
StrBuilder sb = new StrBuilder(); final StrBuilder sb = new StrBuilder();
int len = sb.readFrom(new StringReader(s)); final int len = sb.readFrom(new StringReader(s));
assertEquals(s.length(), len); assertEquals(s.length(), len);
assertEquals(s, sb.toString()); assertEquals(s, sb.toString());
@ -113,7 +113,7 @@ public void testReadFromReader() throws Exception {
@Test @Test
public void testReadFromReaderAppendsToEnd() throws Exception { public void testReadFromReaderAppendsToEnd() throws Exception {
StrBuilder sb = new StrBuilder("Test"); final StrBuilder sb = new StrBuilder("Test");
sb.readFrom(new StringReader(" 123")); sb.readFrom(new StringReader(" 123"));
assertEquals("Test 123", sb.toString()); assertEquals("Test 123", sb.toString());
} }
@ -122,8 +122,8 @@ public void testReadFromReaderAppendsToEnd() throws Exception {
public void testReadFromCharBuffer() throws Exception { public void testReadFromCharBuffer() throws Exception {
String s = ""; String s = "";
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
StrBuilder sb = new StrBuilder(); final StrBuilder sb = new StrBuilder();
int len = sb.readFrom(CharBuffer.wrap(s)); final int len = sb.readFrom(CharBuffer.wrap(s));
assertEquals(s.length(), len); assertEquals(s.length(), len);
assertEquals(s, sb.toString()); assertEquals(s, sb.toString());
@ -134,7 +134,7 @@ public void testReadFromCharBuffer() throws Exception {
@Test @Test
public void testReadFromCharBufferAppendsToEnd() throws Exception { public void testReadFromCharBufferAppendsToEnd() throws Exception {
StrBuilder sb = new StrBuilder("Test"); final StrBuilder sb = new StrBuilder("Test");
sb.readFrom(CharBuffer.wrap(" 123")); sb.readFrom(CharBuffer.wrap(" 123"));
assertEquals("Test 123", sb.toString()); assertEquals("Test 123", sb.toString());
} }
@ -143,8 +143,8 @@ public void testReadFromCharBufferAppendsToEnd() throws Exception {
public void testReadFromReadable() throws Exception { public void testReadFromReadable() throws Exception {
String s = ""; String s = "";
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
StrBuilder sb = new StrBuilder(); final StrBuilder sb = new StrBuilder();
int len = sb.readFrom(new MockReadable(s)); final int len = sb.readFrom(new MockReadable(s));
assertEquals(s.length(), len); assertEquals(s.length(), len);
assertEquals(s, sb.toString()); assertEquals(s, sb.toString());
@ -155,7 +155,7 @@ public void testReadFromReadable() throws Exception {
@Test @Test
public void testReadFromReadableAppendsToEnd() throws Exception { public void testReadFromReadableAppendsToEnd() throws Exception {
StrBuilder sb = new StrBuilder("Test"); final StrBuilder sb = new StrBuilder("Test");
sb.readFrom(new MockReadable(" 123")); sb.readFrom(new MockReadable(" 123"));
assertEquals("Test 123", sb.toString()); assertEquals("Test 123", sb.toString());
} }

View File

@ -533,7 +533,7 @@ public void testMinutesOfYearWithCalendar() {
@Test @Test
public void testMinutesOfYearWithWrongOffsetBugWithCalendar() { public void testMinutesOfYearWithWrongOffsetBugWithCalendar() {
Calendar c = Calendar.getInstance(); final Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.MONTH, Calendar.JANUARY);
c.set(Calendar.DAY_OF_YEAR, 1); c.set(Calendar.DAY_OF_YEAR, 1);
c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.HOUR_OF_DAY, 0);

View File

@ -255,7 +255,7 @@ public void testTimeDateDefaults() {
*/ */
@Test @Test
public void testLang954() throws Exception { public void testLang954() throws Exception {
String pattern = "yyyy-MM-dd'T'"; final String pattern = "yyyy-MM-dd'T'";
FastDateFormat.getInstance(pattern); FastDateFormat.getInstance(pattern);
} }

View File

@ -188,8 +188,8 @@ public void testAmPm() throws ParseException {
assertEquals(cal.getTime(), H.parse("2010-08-01 12:33:20")); assertEquals(cal.getTime(), H.parse("2010-08-01 12:33:20"));
} }
private Calendar getEraStart(int year, TimeZone zone, Locale locale) { private Calendar getEraStart(int year, final TimeZone zone, final Locale locale) {
Calendar cal = Calendar.getInstance(zone, locale); final Calendar cal = Calendar.getInstance(zone, locale);
cal.clear(); cal.clear();
// http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
@ -209,7 +209,7 @@ private Calendar getEraStart(int year, TimeZone zone, Locale locale) {
return cal; return cal;
} }
private void validateSdfFormatFdpParseEquality(String format, Locale locale, TimeZone tz, DateParser fdp, Date in, int year, Date cs) throws ParseException { private void validateSdfFormatFdpParseEquality(final String format, final Locale locale, final TimeZone tz, final DateParser fdp, final Date in, final int year, final Date cs) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale); final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
if (format.equals(SHORT_FORMAT)) { if (format.equals(SHORT_FORMAT)) {
sdf.set2DigitYearStart( cs ); sdf.set2DigitYearStart( cs );
@ -232,12 +232,12 @@ public void testParses() throws Exception {
for(final Locale locale : Locale.getAvailableLocales()) { for(final Locale locale : Locale.getAvailableLocales()) {
for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) {
for(final int year : new int[]{2003, 1940, 1868, 1867, 1, -1, -1940}) { for(final int year : new int[]{2003, 1940, 1868, 1867, 1, -1, -1940}) {
Calendar cal= getEraStart(year, tz, locale); final Calendar cal= getEraStart(year, tz, locale);
Date centuryStart= cal.getTime(); final Date centuryStart= cal.getTime();
cal.set(Calendar.MONTH, 1); cal.set(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 10); cal.set(Calendar.DAY_OF_MONTH, 10);
Date in= cal.getTime(); final Date in= cal.getTime();
final FastDateParser fdp= new FastDateParser(format, tz, locale, centuryStart); final FastDateParser fdp= new FastDateParser(format, tz, locale, centuryStart);
validateSdfFormatFdpParseEquality(format, locale, tz, fdp, in, year, centuryStart); validateSdfFormatFdpParseEquality(format, locale, tz, fdp, in, year, centuryStart);
@ -544,7 +544,7 @@ public void testTimeZoneMatches() {
@Test @Test
public void testLang996() throws ParseException { public void testLang996() throws ParseException {
Calendar expected = Calendar.getInstance(NEW_YORK, Locale.US); final Calendar expected = Calendar.getInstance(NEW_YORK, Locale.US);
expected.clear(); expected.clear();
expected.set(2014, 4, 14); expected.set(2014, 4, 14);