diff --git a/src/main/java/org/apache/commons/lang3/CharSet.java b/src/main/java/org/apache/commons/lang3/CharSet.java index 70f9509a2..cbb221da1 100644 --- a/src/main/java/org/apache/commons/lang3/CharSet.java +++ b/src/main/java/org/apache/commons/lang3/CharSet.java @@ -263,7 +263,7 @@ public class CharSet implements Serializable { if (obj == this) { return true; } - if (obj instanceof CharSet == false) { + if (!(obj instanceof CharSet)) { return false; } final CharSet other = (CharSet) obj; diff --git a/src/main/java/org/apache/commons/lang3/CharUtils.java b/src/main/java/org/apache/commons/lang3/CharUtils.java index 51b347a96..219dea2a0 100644 --- a/src/main/java/org/apache/commons/lang3/CharUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharUtils.java @@ -218,7 +218,7 @@ public class CharUtils { * @throws IllegalArgumentException if the character is not ASCII numeric */ public static int toIntValue(final char ch) { - if (isAsciiNumeric(ch) == false) { + if (!isAsciiNumeric(ch)) { throw new IllegalArgumentException("The character " + ch + " is not in the range '0' - '9'"); } return ch - 48; @@ -240,7 +240,7 @@ public class CharUtils { * @return the int value of the character */ public static int toIntValue(final char ch, final int defaultValue) { - if (isAsciiNumeric(ch) == false) { + if (!isAsciiNumeric(ch)) { return defaultValue; } return ch - 48; @@ -351,13 +351,11 @@ public class CharUtils { * @return the escaped Unicode string */ public static String unicodeEscaped(final char ch) { - final StringBuilder sb = new StringBuilder(6); - sb.append("\\u"); - sb.append(HEX_DIGITS[(ch >> 12) & 15]); - sb.append(HEX_DIGITS[(ch >> 8) & 15]); - sb.append(HEX_DIGITS[(ch >> 4) & 15]); - sb.append(HEX_DIGITS[(ch) & 15]); - return sb.toString(); + return "\\u" + + HEX_DIGITS[(ch >> 12) & 15] + + HEX_DIGITS[(ch >> 8) & 15] + + HEX_DIGITS[(ch >> 4) & 15] + + HEX_DIGITS[(ch) & 15]; } /** diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index e0b4d7200..c294f67f1 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -607,7 +607,7 @@ public class ClassUtils { * @return {@code true} if assignment possible */ public static boolean isAssignable(Class[] classArray, Class[] toClassArray, final boolean autoboxing) { - if (ArrayUtils.isSameLength(classArray, toClassArray) == false) { + if (!ArrayUtils.isSameLength(classArray, toClassArray)) { return false; } if (classArray == null) { @@ -617,7 +617,7 @@ public class ClassUtils { toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY; } for (int i = 0; i < classArray.length; i++) { - if (isAssignable(classArray[i], toClassArray[i], autoboxing) == false) { + if (!isAssignable(classArray[i], toClassArray[i], autoboxing)) { return false; } } @@ -744,7 +744,7 @@ public class ClassUtils { return true; } if (cls.isPrimitive()) { - if (toClass.isPrimitive() == false) { + if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(cls)) { diff --git a/src/main/java/org/apache/commons/lang3/LocaleUtils.java b/src/main/java/org/apache/commons/lang3/LocaleUtils.java index 51bbf5fcd..cd1178139 100644 --- a/src/main/java/org/apache/commons/lang3/LocaleUtils.java +++ b/src/main/java/org/apache/commons/lang3/LocaleUtils.java @@ -233,7 +233,7 @@ public class LocaleUtils { if (locale.getCountry().length() > 0) { list.add(new Locale(locale.getLanguage(), StringUtils.EMPTY)); } - if (list.contains(defaultLocale) == false) { + if (!list.contains(defaultLocale)) { list.add(defaultLocale); } } @@ -297,10 +297,9 @@ public class LocaleUtils { if (langs == null) { langs = new ArrayList<>(); final List locales = availableLocaleList(); - for (int i = 0; i < locales.size(); i++) { - final Locale locale = locales.get(i); + for (final Locale locale : locales) { if (countryCode.equals(locale.getCountry()) && - locale.getVariant().isEmpty()) { + locale.getVariant().isEmpty()) { langs.add(locale); } } @@ -329,11 +328,10 @@ public class LocaleUtils { if (countries == null) { countries = new ArrayList<>(); final List locales = availableLocaleList(); - for (int i = 0; i < locales.size(); i++) { - final Locale locale = locales.get(i); + for (final Locale locale : locales) { if (languageCode.equals(locale.getLanguage()) && - locale.getCountry().length() != 0 && - locale.getVariant().isEmpty()) { + locale.getCountry().length() != 0 && + locale.getVariant().isEmpty()) { countries.add(locale); } } diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java index 5d8629367..1ec0956f7 100644 --- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java +++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java @@ -251,7 +251,7 @@ public class ObjectUtils { * @return {@code false} if the values of both objects are the same */ public static boolean notEqual(final Object object1, final Object object2) { - return ObjectUtils.equals(object1, object2) == false; + return !ObjectUtils.equals(object1, object2); } /** diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 97a073f6d..4af966e52 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -338,7 +338,7 @@ public class StringUtils { return true; } for (int i = 0; i < strLen; i++) { - if (Character.isWhitespace(cs.charAt(i)) == false) { + if (!Character.isWhitespace(cs.charAt(i))) { return false; } } @@ -4611,8 +4611,7 @@ public class StringUtils { } final Object first = iterator.next(); if (!iterator.hasNext()) { - final String result = Objects.toString(first, ""); - return result; + return Objects.toString(first, ""); } // two or more elements @@ -4656,8 +4655,7 @@ public class StringUtils { } final Object first = iterator.next(); if (!iterator.hasNext()) { - final String result = Objects.toString(first, ""); - return result; + return Objects.toString(first, ""); } // two or more elements @@ -5981,11 +5979,9 @@ public class StringUtils { start = end; end = temp; } - return new StringBuilder(len + start - end + overlay.length() + 1) - .append(str.substring(0, start)) - .append(overlay) - .append(str.substring(end)) - .toString(); + return str.substring(0, start) + + overlay + + str.substring(end); } // Chomping @@ -6927,7 +6923,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isLetter(cs.charAt(i)) == false) { + if (!Character.isLetter(cs.charAt(i))) { return false; } } @@ -6962,7 +6958,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isLetter(cs.charAt(i)) == false && cs.charAt(i) != ' ') { + if (!Character.isLetter(cs.charAt(i)) && cs.charAt(i) != ' ') { return false; } } @@ -6997,7 +6993,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isLetterOrDigit(cs.charAt(i)) == false) { + if (!Character.isLetterOrDigit(cs.charAt(i))) { return false; } } @@ -7032,7 +7028,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isLetterOrDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { + if (!Character.isLetterOrDigit(cs.charAt(i)) && cs.charAt(i) != ' ') { return false; } } @@ -7071,7 +7067,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (CharUtils.isAsciiPrintable(cs.charAt(i)) == false) { + if (!CharUtils.isAsciiPrintable(cs.charAt(i))) { return false; } } @@ -7154,7 +7150,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isDigit(cs.charAt(i)) == false && cs.charAt(i) != ' ') { + if (!Character.isDigit(cs.charAt(i)) && cs.charAt(i) != ' ') { return false; } } @@ -7226,7 +7222,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isWhitespace(cs.charAt(i)) == false) { + if (!Character.isWhitespace(cs.charAt(i))) { return false; } } @@ -7261,7 +7257,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isLowerCase(cs.charAt(i)) == false) { + if (!Character.isLowerCase(cs.charAt(i))) { return false; } } @@ -7296,7 +7292,7 @@ public class StringUtils { } final int sz = cs.length(); for (int i = 0; i < sz; i++) { - if (Character.isUpperCase(cs.charAt(i)) == false) { + if (!Character.isUpperCase(cs.charAt(i))) { return false; } } @@ -7761,12 +7757,9 @@ public class StringUtils { final int startOffset = targetSting/2+targetSting%2; final int endOffset = str.length()-targetSting/2; - final StringBuilder builder = new StringBuilder(length); - builder.append(str.substring(0,startOffset)); - builder.append(middle); - builder.append(str.substring(endOffset)); - - return builder.toString(); + return str.substring(0, startOffset) + + middle + + str.substring(endOffset); } // Difference @@ -9212,7 +9205,7 @@ public class StringUtils { if (str.charAt(0) == wrapChar && str.charAt(str.length() - 1) == wrapChar) { final int startIndex = 0; final int endIndex = str.length() - 1; - if (startIndex != -1 && endIndex != -1) { + if (endIndex != -1) { return str.substring(startIndex + 1, endIndex); } } diff --git a/src/main/java/org/apache/commons/lang3/Validate.java b/src/main/java/org/apache/commons/lang3/Validate.java index fc52cb4d4..0f003fd5a 100644 --- a/src/main/java/org/apache/commons/lang3/Validate.java +++ b/src/main/java/org/apache/commons/lang3/Validate.java @@ -105,7 +105,7 @@ public class Validate { * @see #isTrue(boolean, String, Object...) */ public static void isTrue(final boolean expression, final String message, final long value) { - if (expression == false) { + if (!expression) { throw new IllegalArgumentException(String.format(message, Long.valueOf(value))); } } @@ -130,7 +130,7 @@ public class Validate { * @see #isTrue(boolean, String, Object...) */ public static void isTrue(final boolean expression, final String message, final double value) { - if (expression == false) { + if (!expression) { throw new IllegalArgumentException(String.format(message, Double.valueOf(value))); } } @@ -154,7 +154,7 @@ public class Validate { * @see #isTrue(boolean, String, double) */ public static void isTrue(final boolean expression, final String message, final Object... values) { - if (expression == false) { + if (!expression) { throw new IllegalArgumentException(String.format(message, values)); } } @@ -179,7 +179,7 @@ public class Validate { * @see #isTrue(boolean, String, Object...) */ public static void isTrue(final boolean expression) { - if (expression == false) { + if (!expression) { throw new IllegalArgumentException(DEFAULT_IS_TRUE_EX_MESSAGE); } } @@ -803,7 +803,7 @@ public class Validate { * @since 3.0 */ public static void validState(final boolean expression) { - if (expression == false) { + if (!expression) { throw new IllegalStateException(DEFAULT_VALID_STATE_EX_MESSAGE); } } @@ -825,7 +825,7 @@ public class Validate { * @since 3.0 */ public static void validState(final boolean expression, final String message, final Object... values) { - if (expression == false) { + if (!expression) { throw new IllegalStateException(String.format(message, values)); } } @@ -850,7 +850,7 @@ public class Validate { */ public static void matchesPattern(final CharSequence input, final String pattern) { // TODO when breaking BC, consider returning input - if (Pattern.matches(pattern, input) == false) { + if (!Pattern.matches(pattern, input)) { throw new IllegalArgumentException(String.format(DEFAULT_MATCHES_PATTERN_EX, input, pattern)); } } @@ -874,7 +874,7 @@ public class Validate { */ public static void matchesPattern(final CharSequence input, final String pattern, final String message, final Object... values) { // TODO when breaking BC, consider returning input - if (Pattern.matches(pattern, input) == false) { + if (!Pattern.matches(pattern, input)) { throw new IllegalArgumentException(String.format(message, values)); } } @@ -1259,7 +1259,7 @@ public class Validate { */ public static void isInstanceOf(final Class type, final Object obj) { // TODO when breaking BC, consider returning obj - if (type.isInstance(obj) == false) { + if (!type.isInstance(obj)) { throw new IllegalArgumentException(String.format(DEFAULT_IS_INSTANCE_OF_EX_MESSAGE, type.getName(), obj == null ? "null" : obj.getClass().getName())); } @@ -1284,7 +1284,7 @@ public class Validate { */ public static void isInstanceOf(final Class type, final Object obj, final String message, final Object... values) { // TODO when breaking BC, consider returning obj - if (type.isInstance(obj) == false) { + if (!type.isInstance(obj)) { throw new IllegalArgumentException(String.format(message, values)); } } @@ -1310,7 +1310,7 @@ public class Validate { */ public static void isAssignableFrom(final Class superType, final Class type) { // TODO when breaking BC, consider returning type - if (superType.isAssignableFrom(type) == false) { + if (!superType.isAssignableFrom(type)) { throw new IllegalArgumentException(String.format(DEFAULT_IS_ASSIGNABLE_EX_MESSAGE, type == null ? "null" : type.getName(), superType.getName())); } @@ -1335,7 +1335,7 @@ public class Validate { */ public static void isAssignableFrom(final Class superType, final Class type, final String message, final Object... values) { // TODO when breaking BC, consider returning type - if (superType.isAssignableFrom(type) == false) { + if (!superType.isAssignableFrom(type)) { throw new IllegalArgumentException(String.format(message, values)); } } diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java index 4a0a1d11b..0884543b2 100644 --- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java @@ -600,7 +600,7 @@ public class CompareToBuilder implements Builder { if (lhs == rhs) { return this; } - if (lhs == false) { + if (!lhs) { comparison = -1; } else { comparison = +1; diff --git a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java index 12e410df9..c59fcecff 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java @@ -806,7 +806,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder { public void setUpToClass(final Class clazz) { if (clazz != null) { final Object object = getObject(); - if (object != null && clazz.isInstance(object) == false) { + if (object != null && !clazz.isInstance(object)) { throw new IllegalArgumentException("Specified class is not a superclass of the object"); } } diff --git a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java index 375efb783..f40ecce36 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java +++ b/src/main/java/org/apache/commons/lang3/builder/ToStringStyle.java @@ -422,7 +422,7 @@ public abstract class ToStringStyle implements Serializable { * toString for. */ public void appendEnd(final StringBuffer buffer, final Object object) { - if (this.fieldSeparatorAtEnd == false) { + if (!this.fieldSeparatorAtEnd) { removeLastFieldSeparator(buffer); } appendContentEnd(buffer); @@ -2607,7 +2607,7 @@ public abstract class ToStringStyle implements Serializable { * @param value the value to append. */ private void appendValueAsString(final StringBuffer buffer, final String value) { - buffer.append("\"" + value + "\""); + buffer.append('"').append(value).append('"'); } @Override diff --git a/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java b/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java index 1cc9eeb7a..b40213e9b 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java @@ -405,8 +405,7 @@ public class EventCountCircuitBreaker extends AbstractCircuitBreaker { * @throws CircuitBreakingException if the strategy cannot be resolved */ private static StateStrategy stateStrategy(final State state) { - final StateStrategy strategy = STRATEGY_MAP.get(state); - return strategy; + return STRATEGY_MAP.get(state); } /** diff --git a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java index 8fc750b4b..f1a7f877e 100644 --- a/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java +++ b/src/main/java/org/apache/commons/lang3/exception/ExceptionUtils.java @@ -278,7 +278,7 @@ public class ExceptionUtils { */ public static List getThrowableList(Throwable throwable) { final List list = new ArrayList<>(); - while (throwable != null && list.contains(throwable) == false) { + while (throwable != null && !list.contains(throwable)) { list.add(throwable); throwable = ExceptionUtils.getCause(throwable); } @@ -527,9 +527,7 @@ public class ExceptionUtils { } else { frames.add(WRAPPED_MARKER + throwables[i].toString()); } - for (int j = 0; j < trace.size(); j++) { - frames.add(trace.get(j)); - } + frames.addAll(trace); } return frames.toArray(new String[frames.size()]); } diff --git a/src/main/java/org/apache/commons/lang3/math/Fraction.java b/src/main/java/org/apache/commons/lang3/math/Fraction.java index e59789d66..0ce5bedbf 100644 --- a/src/main/java/org/apache/commons/lang3/math/Fraction.java +++ b/src/main/java/org/apache/commons/lang3/math/Fraction.java @@ -827,7 +827,7 @@ public final class Fraction extends Number implements Comparable { if (obj == this) { return true; } - if (obj instanceof Fraction == false) { + if (!(obj instanceof Fraction)) { return false; } final Fraction other = (Fraction) obj; diff --git a/src/main/java/org/apache/commons/lang3/mutable/MutableBoolean.java b/src/main/java/org/apache/commons/lang3/mutable/MutableBoolean.java index 1aec693f7..af135167c 100644 --- a/src/main/java/org/apache/commons/lang3/mutable/MutableBoolean.java +++ b/src/main/java/org/apache/commons/lang3/mutable/MutableBoolean.java @@ -126,7 +126,7 @@ public class MutableBoolean implements Mutable, Serializable, Comparabl * @since 2.5 */ public boolean isTrue() { - return value == true; + return value; } /** @@ -136,7 +136,7 @@ public class MutableBoolean implements Mutable, Serializable, Comparabl * @since 2.5 */ public boolean isFalse() { - return value == false; + return !value; } //----------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java index aa2287a18..c4ccccab7 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java @@ -24,6 +24,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -215,9 +216,7 @@ public class FieldUtils { Class currentClass = cls; while (currentClass != null) { final Field[] declaredFields = currentClass.getDeclaredFields(); - for (final Field field : declaredFields) { - allFields.add(field); - } + Collections.addAll(allFields, declaredFields); currentClass = currentClass.getSuperclass(); } return allFields; diff --git a/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java b/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java index db801fc5c..cef7ebdca 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java +++ b/src/main/java/org/apache/commons/lang3/reflect/TypeLiteral.java @@ -99,7 +99,7 @@ public abstract class TypeLiteral implements Typed { if (obj == this) { return true; } - if (obj instanceof TypeLiteral == false) { + if (!(obj instanceof TypeLiteral)) { return false; } final TypeLiteral other = (TypeLiteral) obj; diff --git a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java index f9fb6dcb6..e32193492 100644 --- a/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java +++ b/src/main/java/org/apache/commons/lang3/text/StrTokenizer.java @@ -17,6 +17,7 @@ package org.apache.commons.lang3.text; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.ListIterator; @@ -445,9 +446,7 @@ public class StrTokenizer implements ListIterator, Cloneable { public List getTokenList() { checkTokenized(); final List list = new ArrayList<>(tokens.length); - for (final String element : tokens) { - list.add(element); - } + list.addAll(Arrays.asList(tokens)); return list; } diff --git a/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java b/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java index b85993283..7d26f8cc2 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDateFormat.java @@ -632,7 +632,7 @@ public class FastDateFormat extends Format implements DateParser, DatePrinter { */ @Override public boolean equals(final Object obj) { - if (obj instanceof FastDateFormat == false) { + if (!(obj instanceof FastDateFormat)) { return false; } final FastDateFormat other = (FastDateFormat) obj; diff --git a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java index b603fac78..6a392d232 100644 --- a/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java +++ b/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java @@ -627,7 +627,7 @@ public class FastDatePrinter implements DatePrinter, Serializable { */ @Override public boolean equals(final Object obj) { - if (obj instanceof FastDatePrinter == false) { + if (!(obj instanceof FastDatePrinter)) { return false; } final FastDatePrinter other = (FastDatePrinter) obj; diff --git a/src/main/java/org/apache/commons/lang3/tuple/Pair.java b/src/main/java/org/apache/commons/lang3/tuple/Pair.java index 3414d04a5..dcf09222d 100644 --- a/src/main/java/org/apache/commons/lang3/tuple/Pair.java +++ b/src/main/java/org/apache/commons/lang3/tuple/Pair.java @@ -157,7 +157,7 @@ public abstract class Pair implements Map.Entry, Comparable