当前位置: 首页>>代码示例>>Java>>正文


Java Pattern类代码示例

本文整理汇总了Java中javax.validation.constraints.Pattern的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Pattern类属于javax.validation.constraints包,在下文中一共展示了Pattern类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getProjects

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@CrossOrigin
@RequestMapping(value = "/search", method = RequestMethod.GET)
@ApiOperation(value = "Find ACTIVE project by keyWord or skills", notes = "Returns a collection of active projects")
public Page<ProjectDTO> getProjects(
		@ApiParam(value = "Keyword of the project") @RequestParam(required=false) String keyWord,
        @ApiParam(value = "Job Titles of the project") @RequestParam(required = false)  List<Integer> jobTitles,
        @ApiParam(value = "Skills of the project") @RequestParam(required = false) List<Integer> skills,
        @ApiParam(value = "Status of the project") @Pattern(regexp="[AC]")  @RequestParam(required = false) String status,
		@ApiParam(value = "Location of the project") @Pattern(regexp="[YN]") @RequestParam(required = false) String remote,
		@ApiParam(value = "Results page you want to retrieve (0..N)", required=false) @RequestParam(required=false) Integer page,
		@ApiParam(value = "Number of records per page",required=false) @RequestParam(required=false) Integer size) {
	
	System.out.println("************** ProjectController.getProjects()"
			+ ": keyWord=" + keyWord 
			+ "; jobTitles=" + jobTitles 
			+ "; skills=" + skills 
			+ "; status=" + status 
			+ "; remote=" + remote 
			+ "; page=" + page 
			+ "; size=" + size 
			+ " **************");
	
    return projectService.search(keyWord, jobTitles, skills, status, remote, page, size);
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:25,代码来源:ProjectController.java

示例2: getValidator

import javax.validation.constraints.Pattern; //导入依赖的package包/类
private static Optional<Validator> getValidator(Annotation annotation) {
	Validator validator = null;

	if (isValidable(annotation)) {
		if (annotation instanceof Range || annotation instanceof Length) {
			validator = new RangeValidator(annotation);
		} else if (annotation instanceof Pattern) {
			validator = new PatternValidator(annotation);
		} else {
			validator = new DefaultValidator(annotation);
		}
	}
	return Optional.ofNullable(validator);
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:15,代码来源:ValidatorFactory.java

示例3: getUsers

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@CrossOrigin
 @RequestMapping(value = "/search", method = RequestMethod.GET)
 @ApiOperation(value = "Find a user by keyWord, skills, status, role or publicFlag", notes = "Returns a collection of users")
 public Page<UserDTO> getUsers(
 		@ApiParam(value = "Keyword like name , title, introduction, state, country") @RequestParam(required=false) String keyWord,
         @ApiParam(value = "Job Titles of the user")	@RequestParam(required = false)  List<Integer> jobTitles,
         @ApiParam(value = "Skills of the User") @RequestParam(required = false) List<Integer> skills,
         @ApiParam(value = "Status of the User") @Pattern(regexp="[AD]")  @RequestParam(required = false) String status,
 		@ApiParam(value = "User Role") @Pattern(regexp="[VOA]") @RequestParam(required = false) String role,
@ApiParam(value = "User Public Flag") @Pattern(regexp="[YN]") @RequestParam(required = false) String publishFlag,
@ApiParam(value = "Results page you want to retrieve (0..N)", required=false) @RequestParam(required=false) Integer page,
 		@ApiParam(value = "Number of records per page", required=false) @RequestParam(required=false) Integer size) {
		
 	System.out.println("************** UserController.getUsers()" 
             + ": keyWord=" + keyWord  
             + "; jobTitles=" + jobTitles  
             + "; skills=" + skills  
             + "; status=" + status  
             + "; role=" + role  
             + "; publishFlag=" + publishFlag  
             + "; page=" + page  
             + "; size=" + size                  
             + " **************");
 	
     return userService.search(keyWord, jobTitles, skills, status, role, publishFlag, page, size);
 }
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:27,代码来源:UserController.java

示例4: process

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@Override
    public Object process(AnnotationInfo ctx, Object value) throws Exception {
        if (!ctx.isAnnotationPresent(Pattern.class)) {
            return value;
        }
//        String regexp = ctx.getAnnotation(Pattern.class).regexp();
//        Generex generex = new Generex(regexp);
//        for (int i = 0; i < REGEX_GENERATION_TRY; i++) {
//            try {
//                return generex.random();
//            } catch (StackOverflowError e) {
//                //TODO: fix Generex#prepareRandom() causing stackoverflow
//                // known bug in Generex lib...let's try again.
//            }
//        }
//        System.out.println("failed to generate regex: " + regexp);
        return value;
    }
 
开发者ID:randomito,项目名称:randomito-all,代码行数:19,代码来源:PatternAnnotationPostProcessor.java

示例5: 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());
}
 
开发者ID:geetools,项目名称:geeMVC-Java-MVC-Framework,代码行数:22,代码来源:PatternValidationAdapter.java

示例6: addJsr303Annotations

import javax.validation.constraints.Pattern; //导入依赖的package包/类
private void addJsr303Annotations(final INamedParam parameter,
		final JVar argumentVariable) {
	if (isNotBlank(parameter.getPattern())) {
		JAnnotationUse patternAnnotation = argumentVariable.annotate(Pattern.class);
		patternAnnotation.param("regexp", parameter.getPattern());
	}

	final Integer minLength = parameter.getMinLength();
	final Integer maxLength = parameter.getMaxLength();
	if ((minLength != null) || (maxLength != null)) {
		final JAnnotationUse sizeAnnotation = argumentVariable
				.annotate(Size.class);

		if (minLength != null) {
			sizeAnnotation.param("min", minLength);
		}

		if (maxLength != null) {
			sizeAnnotation.param("max", maxLength);
		}
	}

	final BigDecimal minimum = parameter.getMinimum();
	if (minimum != null) {
		addMinMaxConstraint(parameter, "minimum", Min.class, minimum,
				argumentVariable);
	}

	final BigDecimal maximum = parameter.getMaximum();
	if (maximum != null) {
		addMinMaxConstraint(parameter, "maximum", Max.class, maximum,
				argumentVariable);
	}

	if (parameter.isRequired()) {
		argumentVariable.annotate(NotNull.class);
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:39,代码来源:AbstractGenerator.java

示例7: setCmp

import javax.validation.constraints.Pattern; //导入依赖的package包/类
/**
 * Setter function for compare type. Allowed values are lte, lt, eq, ne, gt, gte<p> *
 */
@Pattern(regexp = "lte|lt|eq|ne|gt|gte", message = "Value has to be one of lte, lt, eq, ne, gt, gte")
public void setCmp(String cmp)
{
  if (cmp.equals("lt")) {
    setTypeLT();
  } else if (cmp.equals("lte")) {
    setTypeLTE();
  } else if (cmp.equals("eq")) {
    setTypeEQ();
  } else if (cmp.equals("ne")) {
    setTypeEQ();
  } else if (cmp.equals("gt")) {
    setTypeGT();
  } else if (cmp.equals("gte")) {
    setTypeGTE();
  } else {
    setTypeEQ();
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:23,代码来源:AbstractBaseMatchOperator.java

示例8: setCmp

import javax.validation.constraints.Pattern; //导入依赖的package包/类
/**
 * Setter function for compare comparator. Allowed values are lte, lt, eq, ne, gt,
 * gte
 * <p>
 * *
 */
@Pattern(regexp = "lte|lt|eq|ne|gt|gte", message = "Value has to be one of lte, lt, eq, ne, gt, gte")
public void setCmp(String cmp)
{
  if (cmp.equals("lt")) {
    setTypeLT();
  } else if (cmp.equals("lte")) {
    setTypeLTE();
  } else if (cmp.equals("eq")) {
    setTypeEQ();
  } else if (cmp.equals("ne")) {
    setTypeEQ();
  } else if (cmp.equals("gt")) {
    setTypeGT();
  } else if (cmp.equals("gte")) {
    setTypeGTE();
  } else {
    setTypeEQ();
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:26,代码来源:BaseMatchOperator.java

示例9: isValidDeploymentGroups

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@ValidationMethod(message="deploymentGroups cannot be null and names can only contain letters, numbers, underscores, dashes or periods")
@JsonIgnore
public boolean isValidDeploymentGroups() {
    if ( deploymentGroups == null )
    {
        return false;
    }
    java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("^[a-zA-Z0-9_\\-.]+$");
    for ( String group : deploymentGroups )
    {
        if ( !pattern.matcher(group).matches() )
        {
            return false;
        }
    }
    return true;
}
 
开发者ID:soabase,项目名称:soabase,代码行数:18,代码来源:SoaConfiguration.java

示例10: getValidationValue

import javax.validation.constraints.Pattern; //导入依赖的package包/类
private String getValidationValue(String displayName, Annotation annotation) {
    String property;

    if (hasProperty(annotation, VALUE)) {
        property = VALUE;
    } else if (annotation instanceof Pattern) {
        property = REGEXP;
    } else if (annotation instanceof Size) {
        switch (displayName) {
            case "mds.field.validation.minLength":
                property = MIN;
                break;
            case "mds.field.validation.maxLength":
                property = MAX;
                break;
            default:
                throw new IllegalArgumentException(
                        "The @Size annotation can be used only on fields with String type."
                );
        }
    } else {
        throw new IllegalArgumentException("Not found correct property in annotation: " + annotation);
    }

    return getAnnotationValue(annotation, property);
}
 
开发者ID:motech,项目名称:motech,代码行数:27,代码来源:FieldProcessor.java

示例11: 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);
    }
  }
}
 
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:20,代码来源:EmailValidator.java

示例12: testMatchPattern

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@Test
public void testMatchPattern() {
	Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, Pattern.class);
	assertNotNull(violations);
	assertEquals(violations.size(), 1);

	if (runPeformance) {
		long time = System.currentTimeMillis();
		for (int index = 0; index < 10000; index++) {
			validator.validate(obj, Pattern.class);
		}
		long used = System.currentTimeMillis() - time;
		System.out.println("Hibernate Validator [MatchPattern] check used " + used + "ms, avg. " + ((double) used)
				/ 10000 + "ms.");
	}
}
 
开发者ID:bradwoo8621,项目名称:nest-old,代码行数:17,代码来源:TestObject.java

示例13: editPostAction

import javax.validation.constraints.Pattern; //导入依赖的package包/类
@POST
@Path("/{id}/edit")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Template(name= "/post/single")
public Response editPostAction(@PathParam("id") int id,
                               @FormParam("title")
                               @Pattern(regexp = "^(?!\\s*$).+", message = "empty string") String title,
                               @FormParam("content")
                               @Pattern(regexp = "^(?!\\s*$).+", message = "empty string") String content){
    Post post=Post.findById(id);
    post.setTitle(title);
    post.setContent(content);
    post.saveIt();
    URI targetURIForRedirection = URI.create(RESOURCE_PATH + post.getId());
    return Response.seeOther(targetURIForRedirection).build();
}
 
开发者ID:autoschool,项目名称:splinter,代码行数:17,代码来源:PostResource.java

示例14: fromAnnotation

import javax.validation.constraints.Pattern; //导入依赖的package包/类
/**
 * Builds a new constraint from the annotation data.
 * @param anno JSR-303 annotation instance
 * @return a new constraint
 */
public static Constraint fromAnnotation(Annotation anno) {
	if (anno instanceof Min) {
		return min(((Min) anno).value());
	} else if (anno instanceof Max) {
		return max(((Max) anno).value());
	} else if (anno instanceof Size) {
		return size(((Size) anno).min(), ((Size) anno).max());
	} else if (anno instanceof Digits) {
		return digits(((Digits) anno).integer(), ((Digits) anno).fraction());
	} else if (anno instanceof Pattern) {
		return pattern(((Pattern) anno).regexp());
	} else {
		return new Constraint(VALIDATORS.get(anno.annotationType()),
				simplePayload(VALIDATORS.get(anno.annotationType()))) {
					public boolean isValid(Object actualValue) {
						return true;
					}
				};
	}
}
 
开发者ID:Erudika,项目名称:para,代码行数:26,代码来源:Constraint.java

示例15: 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 );
	}
}
 
开发者ID:NCIP,项目名称:cananolab,代码行数:19,代码来源:CustomPatternValidator.java


注:本文中的javax.validation.constraints.Pattern类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。