Class Parser


  • public class Parser
    extends Object
    Parser that works with classes annotated with RegexBinding and fields annotated with CaptureGroup. This utility will parse an input against any number of annotated classes, and will create an instance of each of the class types where its defined regular expression matches one line of that input string.
    Author:
    Keivan Khalichi
    See Also:
    RegexBinding, CaptureGroup
    • Method Detail

      • of

        @SafeVarargs
        public static Parser of​(@Nonnull
                                Class<? extends Serializable>... theTypes)
        Factory method to create an instance of this utility.
        Parameters:
        theTypes - serializable class types annotated with RegexBinding
        Returns:
        a parser instance
      • parse

        public List<Serializable> parse​(@Nonnull
                                        String theInput)
        Parses the input against the class types provided in the of(Class[]) method. This method is thread-safe.
        Parameters:
        theInput - the input to be parsed 1 line at a time
        Returns:
        instances of types provided, with one instance per match within the input
      • parse

        public Stream<Serializable> parse​(@Nonnull
                                          Stream<String> theInput)
        Parses the input stream of strings against the class types provided in the of(Class[]) method, in a stream. This method is thread-safe, and the provided parameter stream can be a parrallel stream.
        Parameters:
        theInput - the input to be parsed as a stream of strings wherein 1 string is parsed against library of possible RegexBinding POJOs
        Returns:
        stream of instances of types provided, with one instance per match within the input
        Throws:
        ParseException - if any fields of the types POJOs are not accessible