@Test
public void testPast() {
Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj,Past.class);
assertNotNull(violations);
assertEquals(violations.size(),1);
if (runPeformance) {
long time = System.currentTimeMillis();
for (int index = 0; index < 10000; index++) {
validator.validate(obj,Past.class);
}
long used = System.currentTimeMillis() - time;
System.out.println("Hibernate Validator [Past] check used " + used + "ms,avg. " + ((double) used) / 10000
+ "ms.");
}
}
private void convert(MetaDataEntry MetaData,Map<String,Object> result) {
if (NotNull.class.getName().equals(MetaData.getKey())) {
result.put(CommonMetaDataKeys.required.getKey(),Boolean.TRUE);
}
if (Size.class.getName().equals(MetaData.getKey())) {
Size size = (Size) MetaData.getValue();
if (size.max() < Integer.MAX_VALUE) {
result.put(CommonMetaDataKeys.SIZE.getKey(),size.max());
}
}
if (Past.class.getName().equals(MetaData.getKey())) {
result.put(CommonMetaDataKeys.PAST.getKey(),Boolean.TRUE);
}
if (Future.class.getName().equals(MetaData.getKey())) {
result.put(CommonMetaDataKeys.FUTURE.getKey(),Boolean.TRUE);
}
}
private static boolean isValidSimpleConstraint(String cName,String field,Object actual,LinkedList<String> err) {
if ("required".equals(cName) && !required().isValid(actual)) {
err.add(Utils.formatMessage("{0} is required.",field));
return false;
} else if (matches(AssertFalse.class,cName) && !falsy().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be false.",field));
return false;
} else if (matches(AssertTrue.class,cName) && !truthy().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be true.",field));
return false;
} else if (matches(Future.class,cName) && !future().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be in the future.",field));
return false;
} else if (matches(Past.class,cName) && !past().isValid(actual)) {
err.add(Utils.formatMessage("{0} must be in the past.",field));
return false;
} else if (matches(URL.class,cName) && !url().isValid(actual)) {
err.add(Utils.formatMessage("{0} is not a valid URL.",field));
return false;
} else if (matches(Email.class,cName) && !email().isValid(actual)) {
err.add(Utils.formatMessage("{0} is not a valid email.",field));
return false;
}
return true;
}
项目:randomito-all
文件:PastAnnotationPostProcessor.java
@Override
public Object process(AnnotationInfo ctx,Object value) throws Exception {
if (!ctx.isAnnotationPresent(Past.class)) {
return value;
}
return DateUtils.addDays(new Date(),-2);
}
项目:hibernate-demos
文件:PastYearWeekValidator.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:benerator
文件:AnnotationMapper.java
private static void mapBeanValidationParameter(Annotation annotation,InstanceDescriptor element) {
SimpleTypeDescriptor typeDescriptor = (SimpleTypeDescriptor) element.getLocalType(false);
if (annotation instanceof AssertFalse)
typeDescriptor.setTrueQuota(0.);
else if (annotation instanceof AssertTrue)
typeDescriptor.setTrueQuota(1.);
else if (annotation instanceof DecimalMax)
typeDescriptor.setMax(String.valueOf(DescriptorUtil.convertType(((DecimalMax) annotation).value(),typeDescriptor)));
else if (annotation instanceof DecimalMin)
typeDescriptor.setMin(String.valueOf(DescriptorUtil.convertType(((DecimalMin) annotation).value(),typeDescriptor)));
else if (annotation instanceof Digits) {
Digits digits = (Digits) annotation;
typeDescriptor.setGranularity(String.valueOf(Math.pow(10,- digits.fraction())));
} else if (annotation instanceof Future)
typeDescriptor.setMin(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.tomorrow()));
else if (annotation instanceof Max)
typeDescriptor.setMax(String.valueOf(((Max) annotation).value()));
else if (annotation instanceof Min)
typeDescriptor.setMin(String.valueOf(((Min) annotation).value()));
else if (annotation instanceof NotNull) {
element.setNullable(false);
element.setNullQuota(0.);
} else if (annotation instanceof Null) {
element.setNullable(true);
element.setNullQuota(1.);
} else if (annotation instanceof Past)
typeDescriptor.setMax(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.yesterday()));
else if (annotation instanceof Pattern)
typeDescriptor.setPattern(String.valueOf(((Pattern) annotation).regexp()));
else if (annotation instanceof Size) {
Size size = (Size) annotation;
typeDescriptor.setMinLength(size.min());
typeDescriptor.setMaxLength(size.max());
}
}
项目:appng-examples
文件:Person.java
@Past
public Date getBirthDay() {
return birthDay;
}
项目:webpedidos
文件:RelatorioPedidosEmitidosBean.java
/**
* Acessor de leitura para o campo dataInicio
*
* @return o dataInicio
*/
@Past
@NotNull
public Date getDataInicio() {
return dataInicio;
}
项目:webpedidos
文件:RelatorioPedidosEmitidosBean.java
/**
* Acessor de leitura para o campo dataFim
*
* @return o dataFim
*/
@Past
@NotNull
public Date getDataFim() {
return dataFim;
}
项目:geeMVC-Java-MVC-Framework
文件:PastValidationAdapter.java
@Override
public boolean incudeInValidation(Past pastAnnotation,RequestHandler requestHandler,ValidationContext validationCtx) {
return true;
}
项目:geeMVC-Java-MVC-Framework
文件:PastValidationAdapter.java
@Override
public void validate(Past pastAnnotation,String name,ValidationContext validationCtx,Errors errors) {
Object value = validationCtx.value(name);
if (value == null)
return;
if (!(value instanceof Date))
errors.add(name,pastAnnotation.message(),value);
LocalDate inputDate = ((Date) value).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
if (yesterday().isAfter(inputDate) || yesterday().isEqual(inputDate))
errors.add(name,value);
}
项目:rpb
文件:Person.java
@Transient
@Past
public Date getBirthdate() {
return this.birthdate;
}
项目:common-libraries
文件:PastValidatorForLocalDate.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:gwt-bean-validators
文件:PastValidatorForCalendar.java
@Override
public void initialize(final Past constraintAnnotation) {}
项目:gwt-bean-validators
文件:PastValidatorForDate.java
@Override
public void initialize(final Past constraintAnnotation) {}
项目:putnami-web-toolkit
文件:ModelCreator.java
private void appendPastValidator(SourceWriter w,JField field) {
Past pastAnnotation = field.getAnnotation(Past.class);
if (pastAnnotation != null) {
w.println(",new PastValidator(\"%s\")",pastAnnotation.message());
}
}
项目:tdc-2014
文件:PastValidatorForLocalDateTestable.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:tdc-2014
文件:PastValidatorForDate.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:tdc-2014
文件:PastValidatorForLocalDate.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:hibernate-demos
文件:PastYearQuarterValidator.java
@Override
public void initialize(Past constraintAnnotation) {
}
项目:eloquentia
文件:Page.java
@Past
public Date getEdited() {
return edited;
}
项目:eloquentia
文件:Comment.java
@NotNull
@Past
public Date getPosted() {
return posted;
}
项目:extclassgenerator
文件:BeanWithValidation.java
@Past
public Date getPast() {
return this.past;
}
项目:gbif-api
文件:DatasetMetrics.java
/**
* @return date this metric was generated. Roughly equivalent with date of indexing
*/
@NotNull
@Past
public Date getCreated() {
return created;
}
项目:gbif-api
文件:DatasetMetrics.java
/**
* @return date new dataset data was downloaded/harvested last time
*/
@NotNull
@Past
public Date getDownloaded() {
return downloaded;
}
项目:common-libraries
文件:PastValidatorForLocalDateTime.java
@Override
public void initialize(Past past) {
}
项目:pinetrail
文件:Waypoint.java
/**
* The point in time when the coordinates were measured.
*
* <p>
* The timestamp cannot be null and must be in the past (no kidding).
*
* @return the point in time when the coordinates were measured
*/
@Past(message = "{Model.Waypoint.Time.Past}")
@NotNull(message = "{Model.Waypoint.Time.NotNull}")
Instant getTime();
项目:ocelot
文件:ValidationCdiDataService.java
public void methodWithArgumentPast(@Past Date date0) {}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。