Java Code Examples for javax.validation.constraints.Size#min()

The following examples show how to use javax.validation.constraints.Size#min() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultModelPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
private String resolveSize(Field field) {
	Size size = field.getAnnotation(Size.class);
	if (size != null) {
		if (size.min() == 0) {
			return StrUtil.concat("长度不能大于", String.valueOf(size.max()));
		} else {
			return StrUtil.concat("长度不能小于", String.valueOf(size.min()), "且不能大于", String.valueOf(size.max()));
		}
	}
	Length length = field.getAnnotation(Length.class);
	if (length != null) {
		if (length.min() == 0) {
			return StrUtil.concat("长度不能大于", String.valueOf(length.max()));
		} else {
			return StrUtil.concat("长度不能小于", String.valueOf(length.min()), "且不能大于", String.valueOf(length.max()));
		}
	}
	return null;
}
 
Example 2
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Determine a given array type's minimum number of items.
 *
 * @param member the field or method to check
 * @return specified minimum number of array items (or null)
 * @see Size
 */
protected Integer resolveArrayMinItems(MemberScope<?, ?> member) {
    if (member.isContainerType()) {
        Size sizeAnnotation = this.getAnnotationFromFieldOrGetter(member, Size.class, Size::groups);
        if (sizeAnnotation != null && sizeAnnotation.min() > 0) {
            // minimum length greater than the default 0 was specified
            return sizeAnnotation.min();
        }
        if (this.getAnnotationFromFieldOrGetter(member, NotEmpty.class, NotEmpty::groups) != null) {
            return 1;
        }
    }
    return null;
}
 
Example 3
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Determine a given text type's minimum number of characters.
 *
 * @param member the field or method to check
 * @return specified minimum number of characters (or null)
 * @see Size
 * @see NotEmpty
 * @see NotBlank
 */
protected Integer resolveStringMinLength(MemberScope<?, ?> member) {
    if (member.getType().isInstanceOf(CharSequence.class)) {
        Size sizeAnnotation = this.getAnnotationFromFieldOrGetter(member, Size.class, Size::groups);
        if (sizeAnnotation != null && sizeAnnotation.min() > 0) {
            // minimum length greater than the default 0 was specified
            return sizeAnnotation.min();
        }
        if (this.getAnnotationFromFieldOrGetter(member, NotEmpty.class, NotEmpty::groups) != null
                || this.getAnnotationFromFieldOrGetter(member, NotBlank.class, NotBlank::groups) != null) {
            return 1;
        }
    }
    return null;
}
 
Example 4
Source File: SizeConstraints.java    From rest-schemagen with Apache License 2.0 4 votes vote down vote up
public SizeConstraints(Size size) {
    this(size.max(), size.min());
}
 
Example 5
Source File: SizePropertyValidator.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Size constraintAnnotation) {
    this.minSizeValue = constraintAnnotation.min();
    this.maxSizeValue = constraintAnnotation.max();
}