Java Code Examples for javax.validation.constraints.DecimalMax#inclusive()

The following examples show how to use javax.validation.constraints.DecimalMax#inclusive() . 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: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Determine a number type's maximum (inclusive) value.
 *
 * @param member the field or method to check
 * @return specified inclusive maximum value (or null)
 * @see Max
 * @see DecimalMax#inclusive()
 * @see NegativeOrZero
 */
protected BigDecimal resolveNumberInclusiveMaximum(MemberScope<?, ?> member) {
    Max maxAnnotation = this.getAnnotationFromFieldOrGetter(member, Max.class, Max::groups);
    if (maxAnnotation != null) {
        return new BigDecimal(maxAnnotation.value());
    }
    DecimalMax decimalMaxAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMax.class, DecimalMax::groups);
    if (decimalMaxAnnotation != null && decimalMaxAnnotation.inclusive()) {
        return new BigDecimal(decimalMaxAnnotation.value());
    }
    NegativeOrZero negativeAnnotation = this.getAnnotationFromFieldOrGetter(member, NegativeOrZero.class, NegativeOrZero::groups);
    if (negativeAnnotation != null) {
        return BigDecimal.ZERO;
    }
    return null;
}
 
Example 2
Source File: DecimalMaxPostProcessor.java    From RestDoc with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyModel postProcessInternal(PropertyModel propertyModel) {
    DecimalMax maxAnno = propertyModel.getPropertyItem().getAnnotation(DecimalMax.class);
    if (maxAnno == null) return propertyModel;

    String hint = "";
    if (maxAnno.inclusive())
        hint += " (值小于等于" + maxAnno.value() + ")";
    else
        hint += " (值小于" + maxAnno.value() + ")";
    propertyModel.setDescription(
            TextUtils.combine(propertyModel.getDescription(), hint)
    );
    return propertyModel;
}
 
Example 3
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Determine a number type's maximum (exclusive) value.
 *
 * @param member the field or method to check
 * @return specified exclusive maximum value (or null)
 * @see DecimalMax#inclusive()
 * @see Negative
 */
protected BigDecimal resolveNumberExclusiveMaximum(MemberScope<?, ?> member) {
    DecimalMax decimalMaxAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMax.class, DecimalMax::groups);
    if (decimalMaxAnnotation != null && !decimalMaxAnnotation.inclusive()) {
        return new BigDecimal(decimalMaxAnnotation.value());
    }
    Negative negativeAnnotation = this.getAnnotationFromFieldOrGetter(member, Negative.class, Negative::groups);
    if (negativeAnnotation != null) {
        return BigDecimal.ZERO;
    }
    return null;
}
 
Example 4
Source File: DecimalMaxPropertyValidator.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(final DecimalMax maxValue) {
    this.maxValue = new BigDecimal(maxValue.value() );
    this.inclusive = maxValue.inclusive();
}