java类javax.validation.constraints.Null的实例源码

TestObject.java 文件源码 项目:nest-old 阅读 35 收藏 0 点赞 0 评论 0
@Test
public void testAssertNull() {
    Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, Null.class);
    assertNotNull(violations);
    assertEquals(violations.size(), 1);

    if (runPeformance) {
        long time = System.currentTimeMillis();
        for (int index = 0; index < 10000; index++) {
            validator.validate(obj, Null.class);
        }
        long used = System.currentTimeMillis() - time;
        System.out.println("Hibernate Validator [Null] check used " + used + "ms, avg. " + ((double) used) / 10000
                + "ms.");
    }
}
BeanDefinitionDtoConverterServiceImpl.java 文件源码 项目:geomajas-project-server 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Take a stab at fixing validation problems ?
 * 
 * @param object
 */
private void validate(Object object) {
    Set<ConstraintViolation<Object>> viols = validator.validate(object);
    for (ConstraintViolation<Object> constraintViolation : viols) {
        if (Null.class.isAssignableFrom(constraintViolation.getConstraintDescriptor().getAnnotation().getClass())) {
            Object o = constraintViolation.getLeafBean();
            Iterator<Node> iterator = constraintViolation.getPropertyPath().iterator();
            String propertyName = null;
            while (iterator.hasNext()) {
                propertyName = iterator.next().getName();
            }
            if (propertyName != null) {
                try {
                    PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(o.getClass(), propertyName);
                    descriptor.getWriteMethod().invoke(o, new Object[] { null });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Jsr303Annotator.java 文件源码 项目:beanvalidation-benchmark 阅读 30 收藏 0 点赞 0 评论 0
/**
 * @return The list of constraints for fields that reference other beans.
 */
private List<MetaAnnotation> buildRefFieldAnnotations() {
    List<MetaAnnotation> anns = Lists.newArrayList();
    HashMap<String, Object> annotParams;

    annotParams = Maps.newHashMap();
    anns.add(new MetaAnnotation(codeModel, NotNull.class, AnnotationType.JSR_303, annotParams));
    annotParams = Maps.newHashMap();
    anns.add(new MetaAnnotation(codeModel, Null.class, AnnotationType.JSR_303, annotParams));
    return anns;
}
NullAnnotationPostProcessor.java 文件源码 项目:randomito-all 阅读 23 收藏 0 点赞 0 评论 0
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
    if (!ctx.isAnnotationPresent(Null.class)) {
        return value;
    }
    return null;
}
MessageService.java 文件源码 项目:holdmail 阅读 25 收藏 0 点赞 0 评论 0
public MessageList findMessages(@Null @Email String recipientEmail, Pageable pageRequest) {

        List<MessageEntity> entities;

        if (StringUtils.isBlank(recipientEmail)) {
            entities = messageRepository.findAllByOrderByReceivedDateDesc(pageRequest);
        }
        else {
            entities = messageRepository.findAllForRecipientOrderByReceivedDateDesc(recipientEmail, pageRequest);
        }

        return messageListMapper.toMessageList(entities);
    }
NegateExpression.java 文件源码 项目:apex-malhar 阅读 22 收藏 0 点赞 0 评论 0
/**
 * @param column   Name of column value to be negated.
 */
public NegateExpression(@Null String column, String alias)
{
  super(column, alias);
  if (this.alias == null) {
    this.alias = "NEGATE(" + column + ")";
  }
}
StockTransaction.java 文件源码 项目:dwoss 阅读 17 收藏 0 点赞 0 评论 0
@Null(message = "ValidationViolation must be null. ValidationMessage: ${validatedValue}")
public String getValidationViolations() {
    List<StockTransactionStatus> sortedList = new ArrayList<>(getStatusHistory());
    Collections.sort(sortedList);
    List<StockTransactionStatusType> sortedTypeList = new ArrayList<>();
    for (StockTransactionStatus stockTransactionStatus : sortedList) {
        sortedTypeList.add(stockTransactionStatus.getType());
    }

    if ( POSSIBLE_STATUS_TYPES.contains(sortedTypeList) ) return null;
    return "TransactionStatusHistory is in invalid. Statuses=" + sortedList + " AllowedTypes=" + POSSIBLE_STATUS_TYPES;
}
Product.java 文件源码 项目:dwoss 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Returns null if the instance is valid, or a string representing the error.
 * <p>
 * @return null if the instance is valid, or a string representing the error.
 */
@Null(message = "ViolationMessage is not null, but '${validatedValue}'")
public String getViolationMessage() {
    if ( tradeName == null ) return null;
    if ( !tradeName.isBrand() ) return tradeName + " is not a Brand";
    if ( tradeName.getManufacturer().getPartNoSupport() == null ) return null; // No Support, so everything is ok.
    return tradeName.getManufacturer().getPartNoSupport().violationMessages(partNo);
}
ProductSpec.java 文件源码 项目:dwoss 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Returns null if the instance is valid, or a string representing the error.
 * <p>
 * @return null if the instance is valid, or a string representing the error.
 */
@Null(message = "ViolationMessage is not null, but '${validatedValue}'")
public String getViolationMessage() {
    if ( model == null
            || model.getFamily() == null
            || model.getFamily().getSeries() == null
            || model.getFamily().getSeries().getBrand() == null
            || model.getFamily().getSeries().getBrand().getManufacturer().getPartNoSupport() == null )
        return null;
    return model.getFamily().getSeries().getBrand().getManufacturer().getPartNoSupport().violationMessages(partNo);
}
AnnotationMapper.java 文件源码 项目:benerator 阅读 21 收藏 0 点赞 0 评论 0
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());
    }
  }
Assert.java 文件源码 项目:school-express-delivery 阅读 22 收藏 0 点赞 0 评论 0
public static void checkNotEqual(@Null Object type, @NotNull Object target, ErrorCode errorCode) {
    if (!target.equals(type)) {
        throw new SedException(errorCode);
    }
}
NullValidationAdapter.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 20 收藏 0 点赞 0 评论 0
@Override
public boolean incudeInValidation(Null nullAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
    return true;
}
NullValidationAdapter.java 文件源码 项目:geeMVC-Java-MVC-Framework 阅读 17 收藏 0 点赞 0 评论 0
@Override
public void validate(Null nullAnnotation, String name, ValidationContext validationCtx, Errors e) {
    if (validationCtx.value(name) != null)
        e.add(name, nullAnnotation.message());
}
Server.java 文件源码 项目:sam 阅读 20 收藏 0 点赞 0 评论 0
@Null(groups = { Create.class, Update.class })
public String getId() {
  return id;
}
Server.java 文件源码 项目:sam 阅读 34 收藏 0 点赞 0 评论 0
@Null(groups = { Create.class, Update.class })
public String getName() {
  return name;
}
NullObservableValueValidator.java 文件源码 项目:ValidateFX 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void initialize(Null constraintAnnotation) {
}
NullPropertyValidator.java 文件源码 项目:dolphin-platform 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void initialize(Null constraintAnnotation) {
}
ProductSeries.java 文件源码 项目:dwoss 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Instance Validation. Validates: value brand is a brand.
 * <p>
 * @return null if valid, or a error message
 */
@Null(message = "ViolationMessage is not null, but '${validatedValue}'")
public String getViolationMessage() {
    if ( brand != null && !brand.isBrand() ) return brand.getName() + " is not a Brand";
    return null;
}
Display.java 文件源码 项目:dwoss 阅读 23 收藏 0 点赞 0 评论 0
@Null(message = "ViolationMessage is not null, but '${validatedValue}'")
public String getValidationViolations() {
    if ( resolution.ordinal() > size.getMaxResolution().ordinal() ) return "resolution > size.maxResolution";
    return null;
}
ModelCreator.java 文件源码 项目:putnami-web-toolkit 阅读 20 收藏 0 点赞 0 评论 0
private void appendNullValidator(SourceWriter w, JField field) {
    Null nullAnnotation = field.getAnnotation(Null.class);
    if (nullAnnotation != null) {
        w.println(", new NullValidator(\"%s\")", nullAnnotation.message());
    }
}
InventoryImpl.java 文件源码 项目:pexel-platform 阅读 29 收藏 0 点赞 0 评论 0
@Override
public void setSlotContents(final int slot, @Null final ItemStack itemStack) {
    this.slots[slot] = itemStack;
}
Download.java 文件源码 项目:gbif-api 阅读 23 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
public Date getCreated() {
  return created;
}
Download.java 文件源码 项目:gbif-api 阅读 24 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
public Date getModified() {
  return modified;
}
GbifUser.java 文件源码 项目:gbif-api 阅读 22 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Integer getKey() {
  return key;
}
Identifier.java 文件源码 项目:gbif-api 阅读 23 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Min(1)
public Integer getKey() {
  return key;
}
Identifier.java 文件源码 项目:gbif-api 阅读 30 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Date getCreated() {
  return created;
}
Endpoint.java 文件源码 项目:gbif-api 阅读 25 收藏 0 点赞 0 评论 0
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
@Min(1)
public Integer getKey() {
  return key;
}
Endpoint.java 文件源码 项目:gbif-api 阅读 24 收藏 0 点赞 0 评论 0
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
public Date getCreated() {
  return created;
}
Endpoint.java 文件源码 项目:gbif-api 阅读 26 收藏 0 点赞 0 评论 0
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
public Date getModified() {
  return modified;
}
Contact.java 文件源码 项目:gbif-api 阅读 27 收藏 0 点赞 0 评论 0
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Integer getKey() {
  return key;
}


问题


面经


文章

微信
公众号

扫码关注公众号