private <E extends Enum<E>> E getEnum(List<String> keyAliases, E defaultValue, Class<E> klazz, Function<String, E> converter) {
        AliasValueEntry candidate = getValue(keyAliases);
        if (candidate == null || StringUtils.isBlank(candidate.value)) {
            return defaultValue;
        }

        boolean notRecognised = false;
        E convertedEnum = null;
        try {
            convertedEnum = converter.apply(candidate.value);
        } catch (IllegalArgumentException iae) {
            notRecognised = true;
        }

        if (notRecognised || convertedEnum == null) {
            throw InvalidOptionConfigurationException.constraintFailure(
                 candidate.alias,
                 "enum",
                 candidate.value,
                 "Valid inputs are: " + Arrays.toString(klazz.getEnumConstants())
             );
        } else {
            return convertedEnum;
        }
    }
Parse an enum from the options using the key aliases.

@param keyAliases the key aliases
@param defaultValue the default value
@param converter a converter function to transform from String to Enum
@param <E> target enum type
@return the parsed enum, or the default value if none provided.
common/config/src/main/java/io/apiman/common/config/options/GenericOptionsParser.java