Enum Class FSValidators

java.lang.Object
java.lang.Enum<FSValidators>
com.jk.core.validation.builtin.FSValidators
All Implemented Interfaces:
Validator, Serializable, Comparable<FSValidators>, Constable

public enum FSValidators extends Enum<FSValidators> implements Validator
This enum provides a set of predefined validation rules for various types of data.

These validation rules can be used to validate strings or other data types according to specific criteria.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Enum Constant Details

    • REQUIRE_NON_EMPTY_STRING

      public static final FSValidators REQUIRE_NON_EMPTY_STRING
      Ensures that the input string is not empty. It checks if the string has at least one character.
    • REQUIRE_VALID_FILENAME

      public static final FSValidators REQUIRE_VALID_FILENAME
      Validates that the input string can be used as a valid filename. It checks for characters that are not allowed in filenames.
    • REQUIRE_VALID_INTEGER

      public static final FSValidators REQUIRE_VALID_INTEGER
      Validates that the input string represents a valid integer number.
    • REQUIRE_NON_NEGATIVE_NUMBER

      public static final FSValidators REQUIRE_NON_NEGATIVE_NUMBER
      Ensures that the input number is non-negative (greater than or equal to zero).
    • REQUIRE_VALID_NUMBER

      public static final FSValidators REQUIRE_VALID_NUMBER
      Validates that the input string represents a valid number, including both integers and decimals.
    • REQUIRE_JAVA_IDENTIFIER

      public static final FSValidators REQUIRE_JAVA_IDENTIFIER
      Validates that the provided input string is a valid Java identifier.
    • VALID_HEXADECIMAL_NUMBER

      public static final FSValidators VALID_HEXADECIMAL_NUMBER
      Validates that the input string represents a valid hexadecimal number.
    • NO_WHITESPACE

      public static final FSValidators NO_WHITESPACE
      Checks that the input string does not contain any whitespace characters.
    • FILE_MUST_EXIST

      public static final FSValidators FILE_MUST_EXIST
      Validates that a file with the provided filename exists in the file system.
    • FILE_MUST_BE_FILE

      public static final FSValidators FILE_MUST_BE_FILE
      Validates that the provided path represents an existing file.
    • FILE_MUST_BE_DIRECTORY

      public static final FSValidators FILE_MUST_BE_DIRECTORY
      Validates that the provided path represents an existing directory.
    • URL_MUST_BE_VALID

      public static final FSValidators URL_MUST_BE_VALID
      Validates that the provided string is a valid URL.
    • IP_ADDRESS

      public static final FSValidators IP_ADDRESS
      Validates that the provided string is a valid IP address.
    • HOST_NAME

      public static final FSValidators HOST_NAME
      Validates that the provided string is a valid host name.
    • HOST_NAME_OR_IP_ADDRESS

      public static final FSValidators HOST_NAME_OR_IP_ADDRESS
      Validates that the provided string is either a valid host name or a valid IP address.
    • MAY_NOT_START_WITH_DIGIT

      public static final FSValidators MAY_NOT_START_WITH_DIGIT
      Validates that the provided string does not start with a digit.
    • EMAIL_ADDRESS

      public static final FSValidators EMAIL_ADDRESS
      Validates that the provided string is a valid email address.
    • CHARACTER_SET_NAME

      public static final FSValidators CHARACTER_SET_NAME
      Validates that the provided string is a valid character set name.
    • JAVA_PACKAGE_NAME

      public static final FSValidators JAVA_PACKAGE_NAME
      Validates that the provided string is a valid Java package name.
    • FILE_MUST_NOT_EXIST

      public static final FSValidators FILE_MUST_NOT_EXIST
      Validates that a file with the provided filename does not exist in the file system.
  • Method Details

    • values

      public static FSValidators[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static FSValidators valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • disallowChars

      public static Validator<String> disallowChars(char[] chars, boolean trim)
      This method creates a validator that disallows specified characters.
      Parameters:
      chars - Specifies the characters to disallow.
      trim - Specifies if the input should be trimmed before validation.
      Returns:
      the validator disallowing the specified characters.
    • encodableInCharset

      public static Validator<String> encodableInCharset(String charsetName)
      This method creates a validator that checks if a string can be encoded in a specified charset.
      Parameters:
      charsetName - Specifies the name of the charset to validate against.
      Returns:
      the validator for charset encoding.
    • forFormat

      public static Validator<String> forFormat(Format fmt)
      This method creates a validator that checks if a given input string conforms to the specified format.
      Parameters:
      fmt - Specifies the Format object representing the desired format for validation.
      Returns:
      the validator that validates strings based on the specified format.
    • maxLength

      public static Validator<String> maxLength(int length)
      This method creates a validator that checks if the length of a given input string does not exceed a specified maximum length.
      Parameters:
      length - Specifies the maximum allowed length for the input string.
      Returns:
      the validator that ensures the input string's length does not exceed the specified maximum.
    • merge

      public static Validator<String> merge(boolean trim, Validator<String>... validators)
      This method creates a validator by merging multiple validators together.
      Parameters:
      trim - Indicates whether to trims the input string before validation or not.
      validators - Specifies the array of validators to merge.
      Returns:
      the merged validator that applies all specified validators to the input string.
    • merge

      public static <T> Validator<T> merge(Validator<T>... validators)
      This method creates a validator by merging multiple validators together.
      Type Parameters:
      T - Specifies the type of input the validators accept.
      Parameters:
      validators - Specifies the list of validators to merge.
      Returns:
      the merged validator that applies all specified validators to the input.
    • minLength

      public static Validator<String> minLength(int length)
      This method creates a validator that checks if a string has a minimum length.
      Parameters:
      length - Specifies the minimum length that the string must have.
      Returns:
      the validator that ensures the input string has at least the specified minimum length.
    • numberRange

      public static Validator<String> numberRange(Number min, Number max)
      This method creates a validator that checks if a number falls within a specified range.
      Parameters:
      min - Specifies the minimum value of the range (inclusive).
      max - Specifies the maximum value of the range (inclusive).
      Returns:
      the validator that ensures the input number is within the specified range.
    • regexp

      public static Validator<String> regexp(String regexp, String message, boolean acceptPartialMatches)
      This method creates a validator that checks if a string matches a regular expression pattern.
      Parameters:
      regexp - Specifies the regular expression pattern to match against.
      message - Specifies the error message to display if the validation fails.
      acceptPartialMatches - Specifies whether partial matches are considered valid.
      Returns:
      the validator that checks if the input string matches the given regular expression pattern.
    • splitString

      public static Validator<String> splitString(String regexp, Validator<String> other)
      This method creates a validator that splits a string using a regular expression and validates each resulting substring using the provided validator.
      Parameters:
      regexp - Specifies the regular expression pattern used to split the input string.
      other - Specifies the validator to apply to each substring resulting from the split.
      Returns:
      the validator that splits the input string and validates each substring using the provided validator.
    • trimString

      public static Validator<String> trimString(Validator<String>... others)
      This method creates a validator that trims the input string and then validates it using the provided validators.
      Parameters:
      others - Specifies the validators to apply to the trimmed input string.
      Returns:
      the validator that trims the input string and then validates it using the provided validators.
    • validNumber

      public static Validator<String> validNumber()
      This method creates a validator for ensuring that the input string represents a valid number.
      Returns:
      the validator that checks whether the input string represents a valid number.
    • forString

      public Validator forString(boolean trim)
      This method creates a validator for strings based on the specified validation rule.
      Parameters:
      trim - Specifies whether the created validator will also trim the input string before validation.
      Returns:
      the validator for strings based on the specified validation rule.
    • trim

      public Validator<String> trim()
      This method creates a validator for strings that trims the input string before validation.
      Returns:
      the validator for strings that trims the input string before validation.
    • validate

      public boolean validate(Problems problems, String compName, Object model)
      This method validates the given model and populates the provided `Problems` object with any validation issues.
      Specified by:
      validate in interface Validator
      Parameters:
      problems - Specifies the `Problems` object to store validation problems.
      compName - Specifies the name or identifier of the component being validated.
      model - Specifies the model to be validated.
      Returns:
      true, if validation succeeded without problems, false otherwise.