Package com.atlassian.adf.util
Class EnumParser<E extends Enum<E>>
- java.lang.Object
-
- com.atlassian.adf.util.EnumParser<E>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Eparse(String key)Find the enumerated value for which thekeyExtractorreturnkeyas the value.EparseAllowNull(String key)Find the enumerated value for which thekeyExtractorreturnkeyas the value, withnullvalues tolerated.
-
-
-
Constructor Detail
-
EnumParser
public EnumParser(Class<E> enumClass, Function<E,String> keyExtractor)
Create a parser for an enumerated type.- Parameters:
enumClass- the enumerated typekeyExtractor- a function to extract the lookup key from an instance ofenumClass. ThekeyExtractormust return a distinct string for each of the enumerated values.
-
-
Method Detail
-
parse
public E parse(@Nullable String key)
Find the enumerated value for which thekeyExtractorreturnkeyas the value.- Parameters:
key- the key value to resolve- Returns:
- the matching enumerated value
- Throws:
AdfException.UnsupportedEnumValue- ifkeyisnullor does not match any of the extracted key values
-
parseAllowNull
@Nullable public E parseAllowNull(@Nullable String key)
Find the enumerated value for which thekeyExtractorreturnkeyas the value, withnullvalues tolerated.- Parameters:
key- the key value to resolve, ornull- Returns:
- the matching enumerated value, or
nullifkeywasnull - Throws:
IllegalArgumentException- ifkeydoes not match any of the extracted key values
-
-