- 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
Modifier and TypeClassDescriptionstatic class
A collector ofErrors.ErrorMessage
s.static class
Error message with a severity and a source.static final class
Exception used bycheckValid()
thrown in case there are fatal messages. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check if these messages are a valid result, throws exception if not.static Errors.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
Check if a warning message is part of these messages.boolean
isValid()
Check if these messages are a valid result.boolean
log
(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.FATAL
is 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, toArray
Methods inherited from class java.util.AbstractSequentialList
iterator
Methods inherited from class java.util.AbstractList
equals, hashCode, listIterator, removeRange, subList
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, removeAll, retainAll
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods 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.FATAL
is present).- Parameters:
logger
- Util logger to log messages into- Returns:
true
if there are no fatal issues present in the collection,false
otherwise.
-
toString
- Overrides:
toString
in classAbstractCollection<Errors.ErrorMessage>
-
isValid
public boolean isValid()Check if these messages are a valid result.- Returns:
- true if there is NO message in
Severity.FATAL
severity
-
checkValid
Check if these messages are a valid result, throws exception if not.- Throws:
Errors.ErrorMessagesException
- in case there is at least oneSeverity.FATAL
severity message
-