Class ParseWarnCollector

java.lang.Object
ch.andre601.expressionparser.ParseWarnCollector

public class ParseWarnCollector extends Object
Simple class that is used by the 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.
  • Constructor Details

    • ParseWarnCollector

      public ParseWarnCollector(String expression)
      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

      public void appendWarningFormatted(String warning, Object... args)
      Adds a new warning without an exact position within the text. This method uses the format method of the String class to replace placeholders within the String.
      Parameters:
      warning - The warning to add. It is sent through String.format(String, Object...) and may contain compatible placeholders.
      args - Optional array of values to sent through String.format(String, Object...).
    • appendWarning

      public void appendWarning(String warning)
      Adds a new warning without an exact position within the text.
      Parameters:
      warning - The warning to add.
    • appendWarningFormatted

      public void appendWarningFormatted(int position, String warning, Object... args)
      Adds a new warning with a specific position of where the error appeared. This method uses the format 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 through String.format(String, Object...) and may contain compatible placeholders.
      args - Optional array of values to sent through String.format(String, Object...).
    • appendWarning

      public void appendWarning(int position, String warning)
      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

      public String 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

      public List<ParseWarnCollector.Context> getWarnings()
      Returns a List of Context instances which may contain a position and warning.
      Returns:
      Possibly-empty List of Context instances.