public final class Errors extends java.util.LinkedList<Errors.ErrorMessage>
Use collector() to collect message through methods Errors.Collector.hint(String), Errors.Collector.warn(String),
and Errors.Collector.fatal(String) and their counterparts with source object (e.g. Errors.Collector.fatal(Object, String).
Once all messages are processed, return validation result from Errors.Collector.collect().
The consumer of validation messages can then check result with isValid() to get simple boolean,
checkValid() to throw exception if not valid and other methods for fine-grained access.
This class also extends a LinkedList of ErrorMessages to give you full access to
all reported messages.
Example:
Errors.Collector collector = Errors.collector();
if (field == null) {
collector.fatal(this, "Field 'field' is null");
}
doOtherValidations(collector);
Errors errors = collector.collect();
if (errors.isValid()) {
return Response.VALID;
} else {
return Response.builder().errors(errors).build();
}
| Modifier and Type | Class and Description |
|---|---|
static class |
Errors.Collector
A collector of
Errors.ErrorMessages. |
static class |
Errors.ErrorMessage
Error message with a severity and a source.
|
static class |
Errors.ErrorMessagesException
Exception used by
checkValid() thrown in case there are fatal messages. |
| Modifier and Type | Method and Description |
|---|---|
void |
checkValid()
Check if these messages are a valid result, throws exception if not.
|
static Errors.Collector |
collector()
Create a new message collector.
|
boolean |
hasFatal()
Check if a fatal message is part of these messages.
|
boolean |
hasHint()
Check if a hint message is part of these messages.
|
boolean |
hasWarning()
Check if a warning message is part of these messages.
|
boolean |
isValid()
Check if these messages are a valid result.
|
boolean |
log(java.util.logging.Logger logger)
Log supplied errors and return a status flag indicating whether the result
is OK or not (will return true for valid, false if
Severity.FATAL is present). |
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, descendingIterator, element, get, getFirst, getLast, indexOf, lastIndexOf, listIterator, offer, offerFirst, offerLast, peek, peekFirst, peekLast, poll, pollFirst, pollLast, pop, push, remove, remove, remove, removeFirst, removeFirstOccurrence, removeLast, removeLastOccurrence, set, size, spliterator, toArray, toArrayequals, hashCode, listIterator, removeRange, subListcontainsAll, isEmpty, removeAll, retainAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitpublic static Errors.Collector collector()
public boolean hasFatal()
Severity.FATALpublic boolean hasWarning()
Severity.WARNpublic boolean hasHint()
Severity.HINTpublic boolean log(java.util.logging.Logger logger)
Severity.FATAL is present).logger - Util logger to log messages intotrue if there are no fatal issues present in the collection, false
otherwise.public boolean isValid()
Severity.FATAL severitypublic void checkValid()
throws Errors.ErrorMessagesException
Errors.ErrorMessagesException - in case there is at least one Severity.FATAL severity messageCopyright © 2018, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.