當前位置: 首頁>>代碼示例>>Java>>正文


Java Null類代碼示例

本文整理匯總了Java中javax.validation.constraints.Null的典型用法代碼示例。如果您正苦於以下問題:Java Null類的具體用法?Java Null怎麽用?Java Null使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Null類屬於javax.validation.constraints包,在下文中一共展示了Null類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAssertNull

import javax.validation.constraints.Null; //導入依賴的package包/類
@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.");
	}
}
 
開發者ID:bradwoo8621,項目名稱:nest-old,代碼行數:17,代碼來源:TestObject.java

示例2: validate

import javax.validation.constraints.Null; //導入依賴的package包/類
/**
 * 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();
				}
			}
		}
	}
}
 
開發者ID:geomajas,項目名稱:geomajas-project-server,代碼行數:27,代碼來源:BeanDefinitionDtoConverterServiceImpl.java

示例3: buildRefFieldAnnotations

import javax.validation.constraints.Null; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:hibernate,項目名稱:beanvalidation-benchmark,代碼行數:14,代碼來源:Jsr303Annotator.java

示例4: process

import javax.validation.constraints.Null; //導入依賴的package包/類
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
    if (!ctx.isAnnotationPresent(Null.class)) {
        return value;
    }
    return null;
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:8,代碼來源:NullAnnotationPostProcessor.java

示例5: findMessages

import javax.validation.constraints.Null; //導入依賴的package包/類
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);
    }
 
開發者ID:SpartaSystems,項目名稱:holdmail,代碼行數:14,代碼來源:MessageService.java

示例6: NegateExpression

import javax.validation.constraints.Null; //導入依賴的package包/類
/**
 * @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 + ")";
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:11,代碼來源:NegateExpression.java

示例7: getValidationViolations

import javax.validation.constraints.Null; //導入依賴的package包/類
@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;
}
 
開發者ID:gg-net,項目名稱:dwoss,代碼行數:13,代碼來源:StockTransaction.java

示例8: getViolationMessage

import javax.validation.constraints.Null; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:gg-net,項目名稱:dwoss,代碼行數:13,代碼來源:Product.java

示例9: getViolationMessage

import javax.validation.constraints.Null; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:gg-net,項目名稱:dwoss,代碼行數:16,代碼來源:ProductSpec.java

示例10: mapBeanValidationParameter

import javax.validation.constraints.Null; //導入依賴的package包/類
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());
  	}
  }
 
開發者ID:raphaelfeng,項目名稱:benerator,代碼行數:36,代碼來源:AnnotationMapper.java

示例11: checkNotEqual

import javax.validation.constraints.Null; //導入依賴的package包/類
public static void checkNotEqual(@Null Object type, @NotNull Object target, ErrorCode errorCode) {
    if (!target.equals(type)) {
        throw new SedException(errorCode);
    }
}
 
開發者ID:aollio,項目名稱:school-express-delivery,代碼行數:6,代碼來源:Assert.java

示例12: incudeInValidation

import javax.validation.constraints.Null; //導入依賴的package包/類
@Override
public boolean incudeInValidation(Null nullAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
    return true;
}
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:5,代碼來源:NullValidationAdapter.java

示例13: validate

import javax.validation.constraints.Null; //導入依賴的package包/類
@Override
public void validate(Null nullAnnotation, String name, ValidationContext validationCtx, Errors e) {
    if (validationCtx.value(name) != null)
        e.add(name, nullAnnotation.message());
}
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:6,代碼來源:NullValidationAdapter.java

示例14: getId

import javax.validation.constraints.Null; //導入依賴的package包/類
@Null(groups = { Create.class, Update.class })
public String getId() {
  return id;
}
 
開發者ID:atgse,項目名稱:sam,代碼行數:5,代碼來源:Server.java

示例15: getName

import javax.validation.constraints.Null; //導入依賴的package包/類
@Null(groups = { Create.class, Update.class })
public String getName() {
  return name;
}
 
開發者ID:atgse,項目名稱:sam,代碼行數:5,代碼來源:Server.java


注:本文中的javax.validation.constraints.Null類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。