Package org.apache.hadoop.util
Class ConfigurationHelper
java.lang.Object
org.apache.hadoop.util.ConfigurationHelper
Configuration Helper class to provide advanced configuration parsing.
Private; external code MUST use
Configuration instead-
Method Summary
Modifier and TypeMethodDescriptionmapEnumNamesToValues(String prefix, Class<E> enumClass) Given an enum class, build a map of lower case names to values.parseEnumSet(String key, String valueString, Class<E> enumClass, boolean ignoreUnknown) Given a comma separated list of enum values, trim the list, map to enum values in the message (case insensitive) and return the set.static <E extends Enum<E>>
EresolveEnum(Configuration conf, String name, Class<E> enumClass, Function<String, E> fallback) Look up an enum from the configuration option and map it to a value in the supplied enum class.
-
Method Details
-
parseEnumSet
public static <E extends Enum<E>> EnumSet<E> parseEnumSet(String key, String valueString, Class<E> enumClass, boolean ignoreUnknown) throws IllegalArgumentException Given a comma separated list of enum values, trim the list, map to enum values in the message (case insensitive) and return the set. Special handling of "*" meaning: all values.- Type Parameters:
E- enum type- Parameters:
key- Configuration object key -used in error messages.valueString- value from ConfigurationenumClass- class of enumignoreUnknown- should unknown values be ignored?- Returns:
- a mutable set of enum values parsed from the valueString, with any unknown
matches stripped if
ignoreUnknownis true. - Throws:
IllegalArgumentException- if one of the entries was unknown and ignoreUnknown is false, or there are two entries in the enum which differ only by case.
-
mapEnumNamesToValues
public static <E extends Enum<E>> Map<String,E> mapEnumNamesToValues(String prefix, Class<E> enumClass) Given an enum class, build a map of lower case names to values.- Type Parameters:
E- enum type- Parameters:
prefix- prefix (with trailing ".") for path capabilities probeenumClass- class of enum- Returns:
- a mutable map of lower case names to enum values
- Throws:
IllegalArgumentException- if there are two entries which differ only by case.
-
resolveEnum
public static <E extends Enum<E>> E resolveEnum(Configuration conf, String name, Class<E> enumClass, Function<String, E> fallback) Look up an enum from the configuration option and map it to a value in the supplied enum class. If no value is supplied or there is no match for the supplied value, the fallback function is invoked, passing in the trimmed and possibly empty string of the value. Extends {linkConfiguration.getEnum(String, Enum)} by adding case independence and a lambda expression for fallback, rather than a default value.- Type Parameters:
E- enumeration type.- Parameters:
conf- configurationname- property nameenumClass- classname to resolvefallback- fallback supplier- Returns:
- an enum value
- Throws:
IllegalArgumentException- If mapping is illegal for the type provided
-