/** * Adds all messages from the given ValidationResult * to the list of messages that this validation result holds. * * @param validationResult the validation result to add messages from * * @throws NullPointerException if the validation result is {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * * @see #addAll(List) */ public void addAllFrom(ValidationResult validationResult) { assertModifiable(); if (validationResult == null) throw new NullPointerException("The validation result to add must not be null."); addAll(validationResult.messageList); }
/** * Adds a new ValidationMessage to the list of messages. * * @param validationMessage the message to add * * @throws NullPointerException if the message is {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * @throws IllegalArgumentException if the severity is <code>OK</code> * * @see #addError(String) * @see #addWarning(String) */ public void add(ValidationMessage validationMessage) { assertModifiable(); if (validationMessage == null) throw new NullPointerException("The validation message must not be null."); if (validationMessage.severity() == Severity.OK) throw new IllegalArgumentException("You must not add a validation message with severity OK."); messageList.add(validationMessage); }
/** * Adds all messages from the given list to this validation result. * * @param messages the messages to be added * * @throws NullPointerException if the messages list is {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * @throws IllegalArgumentException if the messages list contains * a message with severity <code>OK</code> * * @see #addAllFrom(ValidationResult) */ public void addAll(List<ValidationMessage> messages) { assertModifiable(); if (messages == null) throw new NullPointerException("The messages list must not be null."); for (ValidationMessage message : messages) { if (message.severity() == Severity.OK) { throw new IllegalArgumentException("You must not add a validation message with severity OK."); } } messageList.addAll(messages); }
/** * Creates and adds a warning message to the list of validation messages * using the given text. * * @param text the warning text to add * * @throws NullPointerException if the message text {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * * @see #add(ValidationMessage) * @see #addError(String) */ public void addWarning(String text) { assertModifiable(); if (text == null) throw new NullPointerException("The message text must not be null."); add(new SimpleValidationMessage(text)); }
/** * Creates and adds an error message to the list of validation messages * using the given text. * * @param text the error text to add * * @throws NullPointerException if the message text {@code null} * @throws UnsupportedOperationException if the result is unmodifiable * * @see #add(ValidationMessage) * @see #addWarning(String) */ public void addError(String text) { assertModifiable(); if (text == null) throw new NullPointerException("The message text must not be null."); add(new SimpleValidationMessage(text, Severity.ERROR)); }