Class GenericParser<U>

  • Type Parameters:
    U - the type of the objects to parse
    Direct Known Subclasses:
    StringParser

    public class GenericParser<U>
    extends Object
    Utility class to parse various types from other values.
    Since:
    16184
    • Constructor Detail

      • GenericParser

        public GenericParser()
        Creates an empty GenericParser
      • GenericParser

        public GenericParser​(GenericParser<U> parser)
        Creates a new GenericParser by deeply copying parser
        Parameters:
        parser - the parser to copy
      • GenericParser

        protected GenericParser​(Map<Class<?>,​Function<U,​?>> parsers)
        Creates a new GenericParser with the same parsers as the specified map
        Parameters:
        parsers - the parsers
    • Method Detail

      • supports

        public boolean supports​(Class<?> type)
        Determines whether type can be parsed
        Parameters:
        type - the type
        Returns:
        true if type can be parsed
      • parse

        public <T> T parse​(Class<T> type,
                           U value)
        Parses the given value as type and returns the result
        Type Parameters:
        T - the type
        Parameters:
        type - the type class
        value - the value to parse
        Returns:
        the parsed value for string as type type
        Throws:
        UnsupportedOperationException - if type is not supported
        UncheckedParseException - when the parsing fails
      • tryParse

        public <T> Optional<T> tryParse​(Class<T> type,
                                        U value)
        Tries to parse the given value as type and returns the result.
        Type Parameters:
        T - the type
        Parameters:
        type - the type class
        value - the value to parse
        Returns:
        the parsed value for value as type type, or Optional.empty() (if parsing fails, or the type is not supported)