Gary D. Gregory created CONFIGURATION-789:
---------------------------------------------
Summary: Add ImmutableConfiguration.getEnum methods
Key: CONFIGURATION-789
URL: https://issues.apache.org/jira/browse/CONFIGURATION-789
Project: Commons Configuration
Issue Type: New Feature
Components: Type conversion
Reporter: Gary D. Gregory
Assignee: Gary D. Gregory
Add {{ImmutableConfiguration.getEnum}} methods:
* org.apache.commons.configuration2.ImmutableConfiguration.getEnum(String,
Class<T>)
* org.apache.commons.configuration2.ImmutableConfiguration.getEnum(String,
Class<T>, T)
{code:java}
/**
* Gets an enum associated with the given configuration key.
*
* @param <T> The enum type whose constant is to be returned.
* @param enumType the \{@code Class} object of the enum type from which to
return a constant
* @param key The configuration key.
* @return The associated enum.
*
* @throws org.apache.commons.configuration2.ex.ConversionException is thrown
if the key maps to an object that
* is not a String.
* @since 2.8
*/
default <T extends Enum<T>> T getEnum(String key, Class<T> enumType)
{code}
and
{code:java}
} catch (IllegalArgumentException e) {
throw new ConversionException(e);
}
}
/**
* Gets the enum associated with the given configuration key. If the key
doesn't map to an existing object, the
* default value is returned.
*
* @param <T> The enum type whose constant is to be returned.
* @param key The configuration key.
* @param enumType the \{@code Class} object of the enum type from which to
return a constant
* @param defaultValue The default value.
* @return The associated enum if key is found and has valid format, default
value otherwise.
*
* @throws org.apache.commons.configuration2.ex.ConversionException is thrown
if the key maps to an object that is
* not a Enum.
* @since 2.8
*/
default <T extends Enum<T>> T getEnum(String key, Class<T> enumType, T
defaultValue)
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)