本文整理汇总了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());
}