Use Stream.
This commit is contained in:
parent
f9484a4b96
commit
b0b3a46b26
|
@ -339,17 +339,12 @@ public class EnumUtils {
|
||||||
* @return the enum, default enum if not found
|
* @return the enum, default enum if not found
|
||||||
* @since 3.13.0
|
* @since 3.13.0
|
||||||
*/
|
*/
|
||||||
public static <E extends Enum<E>> E getFirstEnumIgnoreCase(final Class<E> enumClass, final String enumName,
|
public static <E extends Enum<E>> E getFirstEnumIgnoreCase(final Class<E> enumClass, final String enumName, final Function<E, String> stringFunction,
|
||||||
final Function<E, String> stringFunction, final E defaultEnum) {
|
final E defaultEnum) {
|
||||||
if (enumName == null || !enumClass.isEnum()) {
|
if (enumName == null || !enumClass.isEnum()) {
|
||||||
return defaultEnum;
|
return defaultEnum;
|
||||||
}
|
}
|
||||||
for (final E each : enumClass.getEnumConstants()) {
|
return Stream.of(enumClass.getEnumConstants()).filter(e -> enumName.equalsIgnoreCase(stringFunction.apply(e))).findFirst().orElse(defaultEnum);
|
||||||
if (enumName.equalsIgnoreCase(stringFunction.apply(each))) {
|
|
||||||
return each;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return defaultEnum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue