Class IdValidator

  • All Implemented Interfaces:
    Validator

    @Immutable
    public final class IdValidator
    extends Object
    implements Validator
    Instances of this class can be used to validate a specified ID against the provided regular expression.
    • Method Detail

      • newInstance

        public static IdValidator newInstance​(@Nullable
                                              CharSequence id,
                                              String regex)
        Creates a new IdValidator instance.
        Parameters:
        id - the ID to be validated.
        regex - the regular expression to be validated against.
        Returns:
        a new IdValidator object.
        Throws:
        NullPointerException - if regex is null.
      • isValid

        public boolean isValid()
        Validates the ID which was provided to the static factory method of this class. Validation ensures that the ID complies to the provided regular expression.
        Specified by:
        isValid in interface Validator
        Returns:
        true if the checked Thing ID is valid, false else.
        See Also:
        Validator.getReason()
      • getReason

        public Optional<String> getReason()
        Description copied from interface: Validator
        Returns the reason why the validation failed. The returned Optional only contains a reason if Validator.isValid() evaluates to false.
        Specified by:
        getReason in interface Validator
        Returns:
        the reason for validation failure.