Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -170,7 +170,7 @@ public abstract class ObjectUtils {
|
||||
/**
|
||||
* Check whether the given array of enum constants contains a constant with the given name,
|
||||
* ignoring case when determining a match.
|
||||
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
|
||||
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
|
||||
* @param constant the constant name to find (must not be null or empty string)
|
||||
* @return whether the constant has been found in the given array
|
||||
*/
|
||||
@@ -180,15 +180,14 @@ public abstract class ObjectUtils {
|
||||
|
||||
/**
|
||||
* Check whether the given array of enum constants contains a constant with the given name.
|
||||
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
|
||||
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
|
||||
* @param constant the constant name to find (must not be null or empty string)
|
||||
* @param caseSensitive whether case is significant in determining a match
|
||||
* @return whether the constant has been found in the given array
|
||||
*/
|
||||
public static boolean containsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive) {
|
||||
for (Enum<?> candidate : enumValues) {
|
||||
if (caseSensitive ?
|
||||
candidate.toString().equals(constant) :
|
||||
if (caseSensitive ? candidate.toString().equals(constant) :
|
||||
candidate.toString().equalsIgnoreCase(constant)) {
|
||||
return true;
|
||||
}
|
||||
@@ -199,7 +198,7 @@ public abstract class ObjectUtils {
|
||||
/**
|
||||
* Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
|
||||
* @param <E> the concrete Enum type
|
||||
* @param enumValues the array of all Enum constants in question, usually per Enum.values()
|
||||
* @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()}
|
||||
* @param constant the constant to get the enum value of
|
||||
* @throws IllegalArgumentException if the given constant is not found in the given array
|
||||
* of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
|
||||
@@ -210,9 +209,8 @@ public abstract class ObjectUtils {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
String.format("constant [%s] does not exist in enum type %s",
|
||||
constant, enumValues.getClass().getComponentType().getName()));
|
||||
throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " +
|
||||
enumValues.getClass().getComponentType().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -635,7 +634,7 @@ public abstract class ReflectionUtils {
|
||||
for (Method ifcMethod : ifc.getMethods()) {
|
||||
if (!Modifier.isAbstract(ifcMethod.getModifiers())) {
|
||||
if (result == null) {
|
||||
result = new LinkedList<Method>();
|
||||
result = new ArrayList<Method>();
|
||||
}
|
||||
result.add(ifcMethod);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user