本文整理匯總了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.");
}
}
示例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();
}
}
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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 + ")";
}
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例12: incudeInValidation
import javax.validation.constraints.Null; //導入依賴的package包/類
@Override
public boolean incudeInValidation(Null nullAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
return true;
}
示例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());
}
示例14: getId
import javax.validation.constraints.Null; //導入依賴的package包/類
@Null(groups = { Create.class, Update.class })
public String getId() {
return id;
}
示例15: getName
import javax.validation.constraints.Null; //導入依賴的package包/類
@Null(groups = { Create.class, Update.class })
public String getName() {
return name;
}