Class Parser.ParsedComponent
- Enclosing class:
Parser
Note: A ParsedComponent will always contain a date
or a time. A case when both date() and time() methods
return empty Optionals is not possible.
Objects of this class can only be created by Parsers
by using the protected Parser.ParsedComponentBuilder.
- Since:
- 1.0.0
- Author:
- hashadex
-
Method Summary
Modifier and TypeMethodDescriptiondate()Returns the parsed date if the parser was able to parse a date from the regex match.intendIndex()Returns the end index of the regex match from which the date/time were parsed.booleanCompares thisParsedComponentto the specified object.inthashCode()Returns the hash code for thisParsedComponent.intlength()Returns the length of the regex match from which the date/time were parsed.Returns the reference datetime used by the parser, which is usually the datetime when the string was parsed.source()Returns the source string in which the parser had found and successfully parsed a certain date/time format.intReturns the start index of the regex match from which the date/time were parsed.text()Returns the text of the regex match from which the date/time were parsed.time()Returns the parsed time if the parser was able to parse a time from the regex match.toString()Returns a string representation of thisParsedComponent.
-
Method Details
-
reference
Returns the reference datetime used by the parser, which is usually the datetime when the string was parsed.For example,
ENRelativeWordParseruses the reference datetime to parse words like "today" and "tomorrow".- Returns:
- Reference datetime
- Since:
- 1.0.0
-
source
Returns the source string in which the parser had found and successfully parsed a certain date/time format.- Returns:
- Source string
- Since:
- 1.0.0
-
startIndex
public int startIndex()Returns the start index of the regex match from which the date/time were parsed.Use the
text()method to get the substring of the source string containing the regex match text.- Returns:
- Start index
- Since:
- 1.0.0
- See Also:
-
endIndex
public int endIndex()Returns the end index of the regex match from which the date/time were parsed.Use the
text()method to get the substring of the source string containing the regex match text.- Returns:
- End index
- Since:
- 1.0.0
- See Also:
-
length
public int length()Returns the length of the regex match from which the date/time were parsed.- Returns:
- Length, calculated with
endIndex - startIndex - Since:
- 1.0.0
- See Also:
-
text
Returns the text of the regex match from which the date/time were parsed.Example:
ENRelativeWordParser parser = new ENRelativeWordParser(); ParsedComponent result = parser.parse("Meeting tomorrow").findAny().get(); System.out.println(result.text()); // -> "tomorrow"- Returns:
- Substring of the source string beginning at
startIndex()and ending atendIndex() - Since:
- 1.0.0
- See Also:
-
date
Returns the parsed date if the parser was able to parse a date from the regex match.Note: a
ParsedComponentwill always contain a date and/or a time. Therefore, a case when bothdate()andtime()return emptyOptionalsis not possible.- Returns:
Optionalthat may contain the parsedLocalDate- Since:
- 1.0.0
- See Also:
-
time
Returns the parsed time if the parser was able to parse a time from the regex match.Note: a
ParsedComponentwill always contain a date and/or a time. Therefore, a case when bothdate()andtime()return emptyOptionalsis not possible.- Returns:
Optionalthat may contain the parsedLocalTime- Since:
- 1.0.0
- See Also:
-
equals
Compares thisParsedComponentto the specified object.Returns
trueif the specified object is aParsedComponentand all fields (reference, source string, start index, end index, date, time) are equal. -
hashCode
public int hashCode()Returns the hash code for thisParsedComponent. -
toString
Returns a string representation of thisParsedComponent.
-