注釈型 RequireMatch


@Documented
@Target(FIELD)
@Retention(RUNTIME)
public @interface RequireMatch
An annotation that indicates the value of the field matches the regular expression specified in the expression() or presetExpression() .

Several regular expression presets have already been defined as RegexPreset for this annotation. If you want to use a regular expression preset, specify the RegexPreset element for presetExpression() . The regular expression can also be specified as an arbitrary string instead of RegexPreset . To specify an arbitrary regular expression, specify a regular expression literal for expression() . If a regular expression preset and a regular expression literal are specified in the same annotation at the same time, like @RequireMatch(expression = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", presetExpression = RegexPreset.EMAIL_ADDRESS) , presetExpression() and RegexPreset will be used preferentially in the validation process.

This annotation validation process provides several methods for applying regular expressions as RegexMethod . Each of them provides RegexMethod.FIND , RegexMethod.LOOKING_AT and RegexMethod.MATCHES methods, and the specification is similar to that of Matcher class which is widely known in Java. By specifying RegexMethod element in the annotation, like @RequireMatch(method = RegexMethod.MATCHES) , the regular expression will be applied in the specified method during the validation process.

You can specify any modifier flag by specifying RegexModifier to the annotation like @RequireMatch(modifiers = {RegexModifier.UNIX_LINES, RegexModifier.DOTALL}).

If this annotation is specified for an object of type other than String, UnsupportedOperationException will always be thrown at runtime.

 Specify the expected value for Content Framework:
 
 @ParameterMapping( content = "Parameter" )
 public class ConcreteEntity implements ValidatableEntity, Serializable {

      @RequireMatch
      private String literal;

      @RequireMatch( method = RegexMethod.MATCHES, errorType = ErrorType.UNRECOVERABLE, message = "failed!" )
      private String unrecoverableLiteral;
 }
 
 
 Specify the expected value for the annotation:
 
 public class ConcreteEntity implements ValidatableEntity, Serializable {

      @RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS )
      private String literalWithRegexPreset;

      @RequireMatch( expression = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*" )
      private String literalWithSpesifiedExpression;

      @RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS, method = RegexMethod.MATCHES )
      private String literalWithMatchesMethod;

      @RequireMatch( presetExpression = RegexPreset.EMAIL_ADDRESS, method = RegexMethod.LOOKING_AT, errorType = ErrorType.RECOVERABLE, message = "failed!" )
      private String recoverableLiteral;
 }
 
 
導入されたバージョン:
1.0.2
  • 要素の詳細

    • errorType

      ErrorType errorType
      Returns the error type based on ErrorType , and ErrorType.RUNTIME is set as the default.
      戻り値:
      The error type based on the ErrorType
      デフォルト:
      RUNTIME
    • message

      String message
      Returns the error type based on ErrorType , and empty ("") is set as the default.
      戻り値:
      The message
      デフォルト:
      ""
    • expression

      String expression
      Returns the regular expression of String data type, and empty ("") is set as the default.
      戻り値:
      The regular expression
      デフォルト:
      ""
    • presetExpression

      RegexPreset presetExpression
      Returns the preset of regular expression based on RegexPreset , and RegexPreset.NONE is set as the default.
      戻り値:
      The preset of regular expression based on RegexPreset
      デフォルト:
      NONE
    • modifiers

      RegexModifier[] modifiers
      Returns the array of regex modifiers based on RegexModifier , and an enmpty array is set as the default.
      戻り値:
      The array of regex modifiers based on RegexModifier
      デフォルト:
      {}
    • method

      RegexMethod method
      Returns the method used to apply regular expression based on RegexMethod , and RegexMethod.MATCHES is set as the default.
      戻り値:
      The method used to apply regular expression based on RegexMethod
      デフォルト:
      MATCHES