當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。