Class EnumParser<E extends Enum<E>>

  • Type Parameters:
    E - the enumerated type to be parsed

    @Internal
    @ReturnValuesAreNonnullByDefault
    public class EnumParser<E extends Enum<E>>
    extends Object
    Extracts a lookup map from an enumerated type.
    • Constructor Detail

      • EnumParser

        public EnumParser​(Class<E> enumClass,
                          Function<E,​String> keyExtractor)
        Create a parser for an enumerated type.
        Parameters:
        enumClass - the enumerated type
        keyExtractor - a function to extract the lookup key from an instance of enumClass. The keyExtractor must 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 the keyExtractor return key as the value.
        Parameters:
        key - the key value to resolve
        Returns:
        the matching enumerated value
        Throws:
        AdfException.UnsupportedEnumValue - if key is null or does not match any of the extracted key values
      • parseAllowNull

        @Nullable
        public E parseAllowNull​(@Nullable
                                String key)
        Find the enumerated value for which the keyExtractor return key as the value, with null values tolerated.
        Parameters:
        key - the key value to resolve, or null
        Returns:
        the matching enumerated value, or null if key was null
        Throws:
        IllegalArgumentException - if key does not match any of the extracted key values