Class CheckResult

java.lang.Object
com.jalios.jcms.tools.CheckResult

public class CheckResult extends Object
A simple class to save the result of a Component Checker.

A CheckResult accumulates error messages reported during a check process. Messages can be added one by one with addError(String), merged from another result with addOther(CheckResult), and then retrieved either as a list (getErrors()) or as a formatted, numbered string (getErrorAsString(boolean)).

This class is not thread-safe.

Since:
jcms-8.0.3, jcms-9.0.0
  • Constructor Details

    • CheckResult

      public CheckResult()
  • Method Details

    • addError

      public void addError(String msg)
      Adds an error message to this result.

      The message is trimmed before being stored. A null or empty message is silently ignored.

      Parameters:
      msg - the error message to add, may be null
    • getErrorCount

      public int getErrorCount()
      Returns the number of errors recorded in this result.
      Returns:
      the number of errors, 0 if no error was recorded
    • getErrors

      public List<String> getErrors()
      Returns the errors recorded in this result, in insertion order.

      The returned list is the internal list of this object (not a copy): any modification made on it is reflected in this result.

      Returns:
      the list of error messages, never null
    • getSortedErrorAsString

      public String getSortedErrorAsString()
      Returns the errors as a numbered string, sorted in natural (alphabetical) order.

      This is a shortcut for getErrorAsString(true).

      Returns:
      the sorted errors, one per line, or an empty string if there is no error
      See Also:
    • getErrorAsString

      public String getErrorAsString()
      Returns the errors as a numbered string, in insertion order.

      This is a shortcut for getErrorAsString(false), kept for legacy behavior.

      Returns:
      the errors, one per line, or an empty string if there is no error
      See Also:
    • getErrorAsString

      public String getErrorAsString(boolean sort)
      Returns the errors as a numbered string, one error per line.

      Each line has the form "<n>: <error>\n", where n starts at 1. For example:

       1: First error
       2: Second error
       

      When sort is true, errors are sorted in natural (alphabetical) order and duplicate messages are removed (a TreeSet is used). When sort is false, errors are listed in insertion order and duplicates are kept.

      Parameters:
      sort - true to sort errors (and remove duplicates), false to keep insertion order
      Returns:
      the formatted errors, or an empty string if there is no error
    • validate

      public void validate()
      Validation when in "Run as Java application" context.

      Logs the outcome of the check: if errors were found, logs their count and their (unsorted) list at WARN level; otherwise logs a "No error found" message at INFO level.

      This method does not throw any exception, even if errors were found.

      Since:
      jcms-8.0.3, jcms-9.0.0
    • addOther

      public void addOther(CheckResult anotherResult)
      Merges the errors of another result into this one.

      Each error of anotherResult is appended to this result using addError(String), in the order of the other result. The other result is not modified.

      Parameters:
      anotherResult - the result whose errors must be added, must not be null
      Throws:
      NullPointerException - if anotherResult is null
    • toString

      public String toString()
      Returns a string representation of this result, including the error count, the raw list of errors and the sorted formatted errors. Intended for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this result
      Since:
      jcms-9.0.1
      See Also: