Class ParsingConfiguration

java.lang.Object
io.github.hashadex.naturaldateinput.ParsingConfiguration
Direct Known Subclasses:
ENParsingConfiguration

public abstract class ParsingConfiguration extends Object
Base abstract class for parsing configurations. A parsing configuration is a set of multiple Parsers, that allows you to easily parse a string with multiple parsers at once. ParsedComponents returned by parsers during the parsing operation are combined into a single ParseResult.
Since:
1.0.0
Author:
hashadex
  • Constructor Details

    • ParsingConfiguration

      public ParsingConfiguration(Set<Parser> parsers)
      Constructs a ParsingConfiguration containing the specified Set of Parsers. Parser set must not contain null elements.
      Parameters:
      parsers - Parser set, not null
      Throws:
      NullPointerException - if parsers is null or contains null elements
      Since:
      1.0.0
  • Method Details

    • parse

      public final ParsingConfiguration.ParseResult parse(String input, LocalDateTime reference)
      Parses the provided string using all Parsers in the configuration and combines returned ParsedComponents into a single ParsingConfiguration.ParseResult.

      Only up to last (by occurrence in text) two ParsedComponents are used for the ParseResult date and time fields. Meaning, if there are multiple ParsedComponents containing a date returned by the parsers, then only the last component is used for the date field in the ParseResult.

      Use the parse(String) method to automatically use LocalDateTime.now() as reference datetime.

      Parameters:
      input - String to be parsed
      reference - LocalDateTime that serves as a reference point for parsers that deal with relative date/time expressions, such as ENRelativeWordParser
      Returns:
      ParseResult composed from all returned ParsedComponents. Might be empty.
      Since:
      1.0.0
    • parse

      public final ParsingConfiguration.ParseResult parse(String input)
      Parses the provided string using LocalDateTime.now() as reference datetime with all Parsers in the configuration and combines returned ParsedComponents into a single ParsingConfiguration.ParseResult.

      Only up to last (by occurrence in text) two ParsedComponents are used for the ParseResult date and time fields. Meaning, if there are multiple ParsedComponents containing a date returned by the parsers, then only the last component is used for the date field in the ParseResult.

      Use the parse(String, LocalDateTime) method to use a different LocalDateTime as reference.

      Parameters:
      input - String to be parsed
      Returns:
      ParseResult composed from all returned ParsedComponents. Might be empty.
      Since:
      1.0.0