Package ch.andre601.expressionparser
Class ParseWarnCollector
java.lang.Object
ch.andre601.expressionparser.ParseWarnCollector
Simple class that is used by the
Errors will be collected together and returned using this ParseWarnCollector class. What happens with the collected warnings is up to you to decide.
DefaultExpressionParserEngine
and the
ExpressionTokenizer
for when an issue appears.
Errors will be collected together and returned using this ParseWarnCollector class. What happens with the collected warnings is up to you to decide.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Record used to hold the position of where an issue appeared and the warning itself. -
Constructor Summary
ConstructorDescriptionParseWarnCollector
(String expression) Creates a new instance of the ParseWarnCollector, with the expression it is used on set. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendWarning
(int position, String warning) Adds a new warning with a specific position of where the error appeared.void
appendWarning
(String warning) Adds a new warning without an exact position within the text.void
appendWarningFormatted
(int position, String warning, Object... args) Adds a new warning with a specific position of where the error appeared.void
appendWarningFormatted
(String warning, Object... args) Adds a new warning without an exact position within the text.Returns the Expression that this ParseWarnCollector is holding.Returns a List ofContext instances
which may contain a position and warning.boolean
Returns whether the ParseWarnCollector has collected any warnings.
-
Constructor Details
-
ParseWarnCollector
Creates a new instance of the ParseWarnCollector, with the expression it is used on set.- Parameters:
expression
- Not-null String containing the expression this ParseWarnCollector is used for.- Throws:
IllegalArgumentException
- Should the provided String be null or empty.
-
-
Method Details
-
appendWarningFormatted
Adds a new warning without an exact position within the text. This method uses theformat method
of the String class to replace placeholders within the String.- Parameters:
warning
- The warning to add. It is sent throughString.format(String, Object...)
and may contain compatible placeholders.args
- Optional array of values to sent throughString.format(String, Object...)
.
-
appendWarning
Adds a new warning without an exact position within the text.- Parameters:
warning
- The warning to add.
-
appendWarningFormatted
Adds a new warning with a specific position of where the error appeared. This method uses theformat method
of the String class to replace placeholders within the String.- Parameters:
position
- The position in the expression String for where the issue happened.warning
- The warning to add. It is sent throughString.format(String, Object...)
and may contain compatible placeholders.args
- Optional array of values to sent throughString.format(String, Object...)
.
-
appendWarning
Adds a new warning with a specific position of where the error appeared.- Parameters:
position
- The position in the expression String for where the issue happened.warning
- The warning to add.
-
getExpression
Returns the Expression that this ParseWarnCollector is holding.- Returns:
- The expression used of this ParseWarnCollector instance.
-
hasWarnings
public boolean hasWarnings()Returns whether the ParseWarnCollector has collected any warnings.- Returns:
- True if ParseWarnCollector has any warnings, false otherwise.
-
getWarnings
Returns a List ofContext instances
which may contain a position and warning.- Returns:
- Possibly-empty List of Context instances.
-