Class DataValidator

java.lang.Object
org.conical.common.bbl.util.DataValidator

public abstract class DataValidator extends Object
Abstract class which can serve as a parent to any classes that need to validate input data. (e.g. when processing form input). Typically a child class will want to call the validator methods using a label with the first letter capitalized, since the validation messages generally start with the label.
Author:
rdoherty
  • Constructor Details

    • DataValidator

      public DataValidator()
  • Method Details

    • isFieldEmpty

      public static boolean isFieldEmpty(Object value)
      Returns whether the field is empty, regardless of type.
      Parameters:
      value - value to be evaluated
      Returns:
      true if value is null, or if, after conversion to a String, value contains no characters
    • addValidationError

      protected void addValidationError(String errorStr)
      Adds a validation error or warning to the message list
      Parameters:
      errorStr - error/warning text
    • getErrors

      public List<String> getErrors()
      Returns a list of validation errors/warnings encountered while validating
      Returns:
      list of validation errors/warnings
    • isRequiredSize

      protected boolean isRequiredSize(String label, String value, int maxLength)
      Returns true if the passed value is <= maxLength, or if value is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.
      Parameters:
      label - name of the value passed
      value - value to be validated
      maxLength - maximum valid length of the value
      Returns:
      true if value is blank or valid, else false
    • isRequiredSize

      protected boolean isRequiredSize(String label, String value, int minLength, int maxLength)
      Returns true if the passed value is <= maxLength and >= minLength, or if value is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.
      Parameters:
      label - name of the value passed
      value - value to be validated
      minLength - minimum valid length of the value
      maxLength - maximum valid length of the value
      Returns:
      true if value is blank or valid, else false
    • isIntegerAsRequired

      protected boolean isIntegerAsRequired(String label, String value)
      Returns true if the passed value is plain integer (only made up of digits), or is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.
      Parameters:
      label - name of the value passed
      value - value to be validated
      Returns:
      true if value is blank or valid, else false
    • isFloatAsRequired

      protected boolean isFloatAsRequired(String label, String value)
      Returns true if the passed value can be evaluated to be a number, or is null or empty. Otherwise returns false. If false is returned, an error message is added detailing the validation failure.
      Parameters:
      label - name of the value passed
      value - value to be validated
      Returns:
      true if value is blank or valid, else false
    • isRequiredFieldEmpty

      protected boolean isRequiredFieldEmpty(String label, Object value)
      Returns true if the passed value is null or empty. Otherwise returns false. If true is returned, an error message is added detailing the validation failure.
      Parameters:
      label - name of the value passed
      value - value to be validated
      Returns:
      true if value is null or blank, else false