- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Errors.ErrorMessage>,Collection<Errors.ErrorMessage>,Deque<Errors.ErrorMessage>,List<Errors.ErrorMessage>,Queue<Errors.ErrorMessage>,SequencedCollection<Errors.ErrorMessage>
Errors utility used to file processing messages (e.g. validation, provider, resource building errors, hint).
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();
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA collector ofErrors.ErrorMessages.static classError message with a severity and a source.static final classException used bycheckValid()thrown in case there are fatal messages. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Method Summary
Modifier and TypeMethodDescriptionvoidCheck if these messages are a valid result, throws exception if not.static Errors.CollectorCreate a new message collector.booleanhasFatal()Check if a fatal message is part of these messages.booleanhasHint()Check if a hint message is part of these messages.booleanCheck if a warning message is part of these messages.booleanisValid()Check if these messages are a valid result.booleanlog(System.Logger logger) Log supplied errors and return a status flag indicating whether the result is OK or not (will return true for valid, false ifSeverity.FATALis present).toString()Methods inherited from class java.util.LinkedList
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, reversed, set, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSequentialList
iteratorMethods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subListMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, replaceAll, retainAll, sort, subList
-
Method Details
-
collector
Create a new message collector.- Returns:
- message collector to add messages to
-
hasFatal
public boolean hasFatal()Check if a fatal message is part of these messages.- Returns:
- true if there is at least one message with severity
Severity.FATAL
-
hasWarning
public boolean hasWarning()Check if a warning message is part of these messages.- Returns:
- true if there is at least one message with severity
Severity.WARN
-
hasHint
public boolean hasHint()Check if a hint message is part of these messages.- Returns:
- true if there is at least one message with severity
Severity.HINT
-
log
Log supplied errors and return a status flag indicating whether the result is OK or not (will return true for valid, false ifSeverity.FATALis present).- Parameters:
logger- Util logger to log messages into- Returns:
trueif there are no fatal issues present in the collection,falseotherwise.
-
toString
- Overrides:
toStringin classAbstractCollection<Errors.ErrorMessage>
-
isValid
public boolean isValid()Check if these messages are a valid result.- Returns:
- true if there is NO message in
Severity.FATALseverity
-
checkValid
Check if these messages are a valid result, throws exception if not.- Throws:
Errors.ErrorMessagesException- in case there is at least oneSeverity.FATALseverity message
-