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

tech.jhipster.lite.shared.error.domain.MissingMandatoryValueException Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package tech.jhipster.lite.shared.error.domain;

public final class MissingMandatoryValueException extends AssertionException {

  private MissingMandatoryValueException(String field, String message) {
    super(field, message);
  }

  public static MissingMandatoryValueException forBlankValue(String field) {
    return new MissingMandatoryValueException(field, defaultMessage(field, "blank"));
  }

  public static MissingMandatoryValueException forNullValue(String field) {
    return new MissingMandatoryValueException(field, defaultMessage(field, "null"));
  }

  public static MissingMandatoryValueException forEmptyValue(String field) {
    return new MissingMandatoryValueException(field, defaultMessage(field, "empty"));
  }

  private static String defaultMessage(String field, String reason) {
    return new StringBuilder()
      .append("The field \"")
      .append(field)
      .append("\" is mandatory and wasn't set")
      .append(" (")
      .append(reason)
      .append(")")
      .toString();
  }

  @Override
  public AssertionErrorType type() {
    return AssertionErrorType.MISSING_MANDATORY_VALUE;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy