javax.validation.constraints.DecimalMax#inclusive ( )源码实例Demo

下面列出了javax.validation.constraints.DecimalMax#inclusive ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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;
}
 
源代码2 项目: RestDoc   文件: DecimalMaxPostProcessor.java
@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;
}
 
/**
 * 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;
}
 
@Override
public void initialize(final DecimalMax maxValue) {
    this.maxValue = new BigDecimal(maxValue.value() );
    this.inclusive = maxValue.inclusive();
}