Package io.helidon.common
Class Errors
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.AbstractSequentialList<E>
-
- java.util.LinkedList<Errors.ErrorMessage>
-
- io.helidon.common.Errors
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Errors.ErrorMessage>
,Collection<Errors.ErrorMessage>
,Deque<Errors.ErrorMessage>
,List<Errors.ErrorMessage>
,Queue<Errors.ErrorMessage>
public final class Errors extends LinkedList<Errors.ErrorMessage>
Errors utility used to file processing messages (e.g. validation, provider, resource building errors, hint).Use
collector()
to collect message through methodsErrors.Collector.hint(String)
,Errors.Collector.warn(String)
, andErrors.Collector.fatal(String)
and their counterparts with source object (e.g.Errors.Collector.fatal(Object, String)
. Once all messages are processed, return validation result fromErrors.Collector.collect()
. The consumer of validation messages can then check result withisValid()
to get simple boolean,checkValid()
to throw exception if not valid and other methods for fine-grained access. This class also extends aLinkedList
ofErrorMessages
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Errors.Collector
A collector ofErrors.ErrorMessage
s.static class
Errors.ErrorMessage
Error message with a severity and a source.static class
Errors.ErrorMessagesException
Exception used bycheckValid()
thrown in case there are fatal messages.
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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(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).-
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, 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, toString
-
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 Detail
-
collector
public static Errors.Collector 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
public boolean log(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).- Parameters:
logger
- Util logger to log messages into- Returns:
true
if there are no fatal issues present in the collection,false
otherwise.
-
isValid
public boolean isValid()
Check if these messages are a valid result.- Returns:
- true if there is NO message in
Severity.FATAL
severity
-
checkValid
public void checkValid() throws Errors.ErrorMessagesException
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
-
-