本文整理匯總了Java中javax.validation.constraints.Pattern.Flag方法的典型用法代碼示例。如果您正苦於以下問題:Java Pattern.Flag方法的具體用法?Java Pattern.Flag怎麽用?Java Pattern.Flag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.validation.constraints.Pattern
的用法示例。
在下文中一共展示了Pattern.Flag方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validate
import javax.validation.constraints.Pattern; //導入方法依賴的package包/類
@Override
public void validate(Pattern patternAnnotation, String name, ValidationContext validationCtx, Errors e) {
Object value = validationCtx.value(name);
if (value == null || Str.isEmpty(patternAnnotation.regexp()))
return;
String pattern = patternAnnotation.regexp();
Pattern.Flag[] flags = patternAnnotation.flags();
int flagBits = 0;
for (Pattern.Flag flag : flags) {
flagBits |= flag.getValue();
}
java.util.regex.Pattern regexPattern = java.util.regex.Pattern.compile(pattern, flagBits);
Matcher m = regexPattern.matcher(String.valueOf(value));
if (!m.matches())
e.add(name, patternAnnotation.message());
}
示例2: initialize
import javax.validation.constraints.Pattern; //導入方法依賴的package包/類
@Override
public void initialize(final Email emailAnnotation) {
super.initialize(emailAnnotation);
final Pattern.Flag[] flags = emailAnnotation.flags();
final StringBuilder flagString = new StringBuilder();
for (final Pattern.Flag flag : flags) {
flagString.append(this.toString(flag));
}
// we only apply the regexp if there is one to apply
if (!".*".equals(emailAnnotation.regexp()) || emailAnnotation.flags().length > 0) {
try {
this.pattern = RegExp.compile(emailAnnotation.regexp(), flagString.toString());
} catch (final RuntimeException e) {
throw LOG.getInvalidRegularExpressionException(e);
}
}
}
示例3: initialize
import javax.validation.constraints.Pattern; //導入方法依賴的package包/類
public void initialize(PatternMatchIfNotNullNotEmpty parameters) {
Pattern.Flag flags[] = parameters.flags();
int intFlag = 0;
for ( Pattern.Flag flag : flags ) {
intFlag = intFlag | flag.getValue();
}
String regexp = resolveRegexp(parameters);
messageSource = parameters.messageSource();
messageKey = parameters.messageKey();
try {
pattern = java.util.regex.Pattern.compile(regexp, intFlag );
}
catch ( PatternSyntaxException e ) {
throw new IllegalArgumentException( "Invalid regular expression.", e );
}
}
示例4: combineFlags
import javax.validation.constraints.Pattern; //導入方法依賴的package包/類
/**
* Combines a given set of javax.validation.constraints.Pattern.Flag instances into one bitmask suitable for
* java.util.regex.Pattern consumption.
*
* @param flags - list of javax.validation.constraints.Pattern.Flag instances to combine
* @return combined bitmask for regex flags
*/
private int combineFlags(final Pattern.Flag[] flags) {
int combined = 0;
for (Pattern.Flag f : flags) {
combined |= f.getValue();
}
return combined;
}
示例5: initialize
import javax.validation.constraints.Pattern; //導入方法依賴的package包/類
@Override
public void initialize(final Pattern parameters) {
final Pattern.Flag[] flags = parameters.flags();
final StringBuilder flagString = new StringBuilder();
for (final Pattern.Flag flag : flags) {
flagString.append(this.toString(flag));
}
try {
this.pattern = RegExp.compile(parameters.regexp(), flagString.toString());
} catch (final RuntimeException e) {
throw LOG.getInvalidRegularExpressionException(e);
}
this.escapedRegexp = InterpolationHelper.escapeMessageParameter(parameters.regexp());
}