Use Stream.

This commit is contained in:
Gary Gregory 2022-08-21 11:04:41 -04:00
parent f9484a4b96
commit b0b3a46b26
1 changed files with 3 additions and 8 deletions

View File

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