Class CheckResult
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an error message to this result.voidaddOther(CheckResult anotherResult) Merges the errors of another result into this one.Returns the errors as a numbered string, in insertion order.getErrorAsString(boolean sort) Returns the errors as a numbered string, one error per line.intReturns the number of errors recorded in this result.Returns the errors recorded in this result, in insertion order.Returns the errors as a numbered string, sorted in natural (alphabetical) order.toString()Returns a string representation of this result, including the error count, the raw list of errors and the sorted formatted errors.voidvalidate()Validation when in "Run as Java application" context.
-
Constructor Details
-
CheckResult
public CheckResult()
-
-
Method Details
-
addError
Adds an error message to this result.The message is trimmed before being stored. A
nullor empty message is silently ignored.- Parameters:
msg- the error message to add, may benull
-
getErrorCount
public int getErrorCount()Returns the number of errors recorded in this result.- Returns:
- the number of errors,
0if no error was recorded
-
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
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
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
Returns the errors as a numbered string, one error per line.Each line has the form
"<n>: <error>\n", wherenstarts at 1. For example:1: First error 2: Second error
When
sortistrue, errors are sorted in natural (alphabetical) order and duplicate messages are removed (aTreeSetis used). Whensortisfalse, errors are listed in insertion order and duplicates are kept.- Parameters:
sort-trueto sort errors (and remove duplicates),falseto 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
WARNlevel; otherwise logs a "No error found" message atINFOlevel.This method does not throw any exception, even if errors were found.
- Since:
- jcms-8.0.3, jcms-9.0.0
-
addOther
Merges the errors of another result into this one.Each error of
anotherResultis appended to this result usingaddError(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 benull- Throws:
NullPointerException- ifanotherResultisnull
-
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.
-