[GitHub] commons-lang pull request #276: IntelliJ IDEA refactorings.

Closes #276.
This commit is contained in:
Jonathan Bluett-Duncan 2017-07-12 00:09:41 -07:00 committed by Gary Gregory
parent a37d19eb45
commit 1571050a19
20 changed files with 67 additions and 83 deletions

View File

@ -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;

View File

@ -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];
}
/**

View File

@ -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)) {

View File

@ -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<Locale> 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<Locale> 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);
}
}

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -600,7 +600,7 @@ public class CompareToBuilder implements Builder<Integer> {
if (lhs == rhs) {
return this;
}
if (lhs == false) {
if (!lhs) {
comparison = -1;
} else {
comparison = +1;

View File

@ -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");
}
}

View File

@ -422,7 +422,7 @@ public abstract class ToStringStyle implements Serializable {
* <code>toString</code> 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

View File

@ -405,8 +405,7 @@ public class EventCountCircuitBreaker extends AbstractCircuitBreaker<Integer> {
* @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);
}
/**

View File

@ -278,7 +278,7 @@ public class ExceptionUtils {
*/
public static List<Throwable> getThrowableList(Throwable throwable) {
final List<Throwable> 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()]);
}

View File

@ -827,7 +827,7 @@ public final class Fraction extends Number implements Comparable<Fraction> {
if (obj == this) {
return true;
}
if (obj instanceof Fraction == false) {
if (!(obj instanceof Fraction)) {
return false;
}
final Fraction other = (Fraction) obj;

View File

@ -126,7 +126,7 @@ public class MutableBoolean implements Mutable<Boolean>, Serializable, Comparabl
* @since 2.5
*/
public boolean isTrue() {
return value == true;
return value;
}
/**
@ -136,7 +136,7 @@ public class MutableBoolean implements Mutable<Boolean>, Serializable, Comparabl
* @since 2.5
*/
public boolean isFalse() {
return value == false;
return !value;
}
//-----------------------------------------------------------------------

View File

@ -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;

View File

@ -99,7 +99,7 @@ public abstract class TypeLiteral<T> implements Typed<T> {
if (obj == this) {
return true;
}
if (obj instanceof TypeLiteral == false) {
if (!(obj instanceof TypeLiteral)) {
return false;
}
final TypeLiteral<?> other = (TypeLiteral<?>) obj;

View File

@ -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<String>, Cloneable {
public List<String> getTokenList() {
checkTokenized();
final List<String> list = new ArrayList<>(tokens.length);
for (final String element : tokens) {
list.add(element);
}
list.addAll(Arrays.asList(tokens));
return list;
}

View File

@ -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;

View File

@ -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;

View File

@ -157,7 +157,7 @@ public abstract class Pair<L, R> implements Map.Entry<L, R>, Comparable<Pair<L,
*/
@Override
public String toString() {
return new StringBuilder().append('(').append(getLeft()).append(',').append(getRight()).append(')').toString();
return "(" + getLeft() + ',' + getRight() + ')';
}
/**