All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.mnemonic.commons.component.ValidationContext Maven / Gradle / Ivy

There is a newer version: 0.4.25
Show newest version
package no.mnemonic.commons.component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ValidationContext {

  private List warnings = new ArrayList<>();
  private List errors = new ArrayList<>();

  public boolean isValid() {
    return errors.size() == 0;
  }

  /**
   * @param component The component reporting the warning
   * @param msg the warning message
   * @return the context
   */
  public ValidationContext addWarning(Object component, Object msg) {
    warnings.add(component + ": " + msg);
    return this;
  }

  /**
   * @param component The component reporting the error
   * @param msg the error message
   * @return the context
   */
  public ValidationContext addError(Object component, Object msg) {
    errors.add(component + ": " + msg);
    return this;
  }

  /**
   * Clear all errors and warnings
   * @return the context
   */
  public ValidationContext reset() {
    warnings.clear();
    errors.clear();
    return this;
  }

  public List getWarnings() {
    return Collections.unmodifiableList(warnings);
  }

  public List getErrors() {
    return Collections.unmodifiableList(errors);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy