Class Errors

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Errors.ErrorMessage>, Collection<Errors.ErrorMessage>, Deque<Errors.ErrorMessage>, List<Errors.ErrorMessage>, Queue<Errors.ErrorMessage>, SequencedCollection<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 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.


 Errors.Collector collector = Errors.collector();
 if (field == null) {
     collector.fatal(this, "Field 'field' is null");

 Errors errors = collector.collect();
 if (errors.isValid()) {
   return Response.VALID;
 } else {
   return Response.builder().errors(errors).build();
See Also:
  • Method Details

    • collector

      public static Errors.Collector collector()
      Create a new message collector.
      message collector to add messages to
    • hasFatal

      public boolean hasFatal()
      Check if a fatal message is part of these messages.
      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.
      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.
      true if there is at least one message with severity Severity.HINT
    • log

      public 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 if Severity.FATAL is present).
      logger - Util logger to log messages into
      true if there are no fatal issues present in the collection, false otherwise.
    • toString

      public String toString()
      toString in class AbstractCollection<Errors.ErrorMessage>
    • isValid

      public boolean isValid()
      Check if these messages are a valid result.
      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.
      Errors.ErrorMessagesException - in case there is at least one Severity.FATAL severity message