Java 类javax.validation.constraints.Null 实例源码

项目:nest-old    文件:TestObject.java   
@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.");
    }
}
项目:geomajas-project-server    文件:BeanDefinitionDtoConverterServiceImpl.java   
/**
 * 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();
                }
            }
        }
    }
}
项目:beanvalidation-benchmark    文件:Jsr303Annotator.java   
/**
 * @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;
}
项目:randomito-all    文件:NullAnnotationPostProcessor.java   
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
    if (!ctx.isAnnotationPresent(Null.class)) {
        return value;
    }
    return null;
}
项目:holdmail    文件:MessageService.java   
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);
    }
项目:apex-malhar    文件:NegateExpression.java   
/**
 * @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 + ")";
  }
}
项目:dwoss    文件:StockTransaction.java   
@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;
}
项目:dwoss    文件:Product.java   
/**
 * 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);
}
项目:dwoss    文件:ProductSpec.java   
/**
 * 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);
}
项目: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());
    }
  }
项目:school-express-delivery    文件:Assert.java   
public static void checkNotEqual(@Null Object type, @NotNull Object target, ErrorCode errorCode) {
    if (!target.equals(type)) {
        throw new SedException(errorCode);
    }
}
项目:geeMVC-Java-MVC-Framework    文件:NullValidationAdapter.java   
@Override
public boolean incudeInValidation(Null nullAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
    return true;
}
项目:geeMVC-Java-MVC-Framework    文件:NullValidationAdapter.java   
@Override
public void validate(Null nullAnnotation, String name, ValidationContext validationCtx, Errors e) {
    if (validationCtx.value(name) != null)
        e.add(name, nullAnnotation.message());
}
项目:sam    文件:Server.java   
@Null(groups = { Create.class, Update.class })
public String getId() {
  return id;
}
项目:sam    文件:Server.java   
@Null(groups = { Create.class, Update.class })
public String getName() {
  return name;
}
项目:ValidateFX    文件:NullObservableValueValidator.java   
@Override
public void initialize(Null constraintAnnotation) {
}
项目:dolphin-platform    文件:NullPropertyValidator.java   
@Override
public void initialize(Null constraintAnnotation) {
}
项目:dwoss    文件:ProductSeries.java   
/**
 * 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;
}
项目:dwoss    文件:Display.java   
@Null(message = "ViolationMessage is not null, but '${validatedValue}'")
public String getValidationViolations() {
    if ( resolution.ordinal() > size.getMaxResolution().ordinal() ) return "resolution > size.maxResolution";
    return null;
}
项目:putnami-web-toolkit    文件:ModelCreator.java   
private void appendNullValidator(SourceWriter w, JField field) {
    Null nullAnnotation = field.getAnnotation(Null.class);
    if (nullAnnotation != null) {
        w.println(", new NullValidator(\"%s\")", nullAnnotation.message());
    }
}
项目:pexel-platform    文件:InventoryImpl.java   
@Override
public void setSlotContents(final int slot, @Null final ItemStack itemStack) {
    this.slots[slot] = itemStack;
}
项目:gbif-api    文件:Download.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Download.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
public Date getModified() {
  return modified;
}
项目:gbif-api    文件:GbifUser.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Integer getKey() {
  return key;
}
项目:gbif-api    文件:Identifier.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Min(1)
public Integer getKey() {
  return key;
}
项目:gbif-api    文件:Identifier.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Endpoint.java   
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
@Min(1)
public Integer getKey() {
  return key;
}
项目:gbif-api    文件:Endpoint.java   
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Endpoint.java   
@Null(groups = PrePersist.class)
@NotNull(groups = PostPersist.class)
public Date getModified() {
  return modified;
}
项目:gbif-api    文件:Contact.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Integer getKey() {
  return key;
}
项目:gbif-api    文件:Contact.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Contact.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Date getModified() {
  return modified;
}
项目:gbif-api    文件:NetworkEntity.java   
@Nullable
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
UUID getKey();
项目:gbif-api    文件:NetworkEntity.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
Date getCreated();
项目:gbif-api    文件:NetworkEntity.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Nullable
Date getModified();
项目:gbif-api    文件:Tag.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Min(1)
public Integer getKey() {
  return key;
}
项目:gbif-api    文件:Tag.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Installation.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Override
public UUID getKey() {
  return key;
}
项目:gbif-api    文件:Installation.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Override
public Date getCreated() {
  return created;
}
项目:gbif-api    文件:Installation.java   
@Null(groups = {PrePersist.class})
@NotNull(groups = {PostPersist.class})
@Override
public Date getModified() {
  return modified;
}