javax.validation.constraints.DecimalMin Java Examples

The following examples show how to use javax.validation.constraints.DecimalMin. 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: ResourceInterfaceGenerator.java    From spring-openapi with MIT License 6 votes vote down vote up
private ParameterSpec.Builder getNumberBasedSchemaParameter(String fieldName, Schema innerSchema) {
	ParameterSpec.Builder fieldBuilder = createNumberBasedParameterWithFormat(fieldName, innerSchema);
	if (innerSchema.getMinimum() != null) {
		fieldBuilder.addAnnotation(AnnotationSpec.builder(DecimalMin.class)
				.addMember("value", "$S", innerSchema.getMinimum().toString())
				.build()
		);
	}
	if (innerSchema.getMaximum() != null) {
		fieldBuilder.addAnnotation(AnnotationSpec.builder(DecimalMax.class)
				.addMember("value", "$S", innerSchema.getMaximum().toString())
				.build()
		);
	}
	return fieldBuilder;
}
 
Example #2
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 6 votes vote down vote up
/**
 * Determine a number type's minimum (inclusive) value.
 *
 * @param member the field or method to check
 * @return specified inclusive minimum value (or null)
 * @see Min
 * @see DecimalMin
 * @see PositiveOrZero
 */
protected BigDecimal resolveNumberInclusiveMinimum(MemberScope<?, ?> member) {
    Min minAnnotation = this.getAnnotationFromFieldOrGetter(member, Min.class, Min::groups);
    if (minAnnotation != null) {
        return new BigDecimal(minAnnotation.value());
    }
    DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
    if (decimalMinAnnotation != null && decimalMinAnnotation.inclusive()) {
        return new BigDecimal(decimalMinAnnotation.value());
    }
    PositiveOrZero positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, PositiveOrZero.class, PositiveOrZero::groups);
    if (positiveAnnotation != null) {
        return BigDecimal.ZERO;
    }
    return null;
}
 
Example #3
Source File: RechargeService.java    From runscore with Apache License 2.0 6 votes vote down vote up
/**
 * 核对订单
 */
@Transactional
public void checkOrder(@NotBlank String orderNo,
		@NotNull @DecimalMin(value = "0", inclusive = false) Double actualPayAmount, @NotNull Date payTime) {
	RechargeOrder order = rechargeOrderRepo.findByOrderNo(orderNo);
	if (order == null) {
		throw new BizException(BizError.充值订单不存在);
	}
	if (Constant.充值订单状态_已支付.equals(order.getOrderState())) {
		return;
	}

	order.updatePayInfo(actualPayAmount, payTime);
	rechargeOrderRepo.save(order);

	if (order.getRechargeAmount().compareTo(actualPayAmount) != 0) {
		log.warn("充值金额跟实际支付金额对不上,无法进行自动结算;充值订单单号为{}", orderNo);
		return;
	}
	ThreadPoolUtils.getRechargeSettlementPool().schedule(() -> {
		redisTemplate.opsForList().leftPush(Constant.充值订单_已支付订单单号, order.getOrderNo());
	}, 1, TimeUnit.SECONDS);
}
 
Example #4
Source File: OpenApiClientGenerator.java    From spring-openapi with MIT License 6 votes vote down vote up
private FieldSpec.Builder getNumberBasedSchemaField(String fieldName, Schema innerSchema, TypeSpec.Builder typeSpecBuilder) {
	FieldSpec.Builder fieldBuilder = createNumberBasedFieldWithFormat(fieldName, innerSchema, typeSpecBuilder);
	if (innerSchema.getMinimum() != null) {
		fieldBuilder.addAnnotation(AnnotationSpec.builder(DecimalMin.class)
				.addMember("value", "$S", innerSchema.getMinimum().toString())
				.build()
		);
	}
	if (innerSchema.getMaximum() != null) {
		fieldBuilder.addAnnotation(AnnotationSpec.builder(DecimalMax.class)
				.addMember("value", "$S", innerSchema.getMaximum().toString())
				.build()
		);
	}
	return fieldBuilder;
}
 
Example #5
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
protected void applyAnnotationDetailsOnParameter(AbstractSerializableParameter schema, Annotation annotation) {
	if (annotation instanceof DecimalMin) {
		schema.setMinimum(new BigDecimal(((DecimalMin) annotation).value()));
	} else if (annotation instanceof DecimalMax) {
		schema.setMaximum(new BigDecimal(((DecimalMax) annotation).value()));
	} else if (annotation instanceof Min) {
		schema.setMinimum(BigDecimal.valueOf(((Min) annotation).value()));
	} else if (annotation instanceof Max) {
		schema.setMaximum(BigDecimal.valueOf(((Max) annotation).value()));
	}
	if (annotation instanceof Pattern) {
		schema.setPattern(((Pattern) annotation).regexp());
	} else if (annotation instanceof Size) {
		schema.setMinLength(((Size) annotation).min());
		schema.setMaxLength(((Size) annotation).max());
	} else if (annotation instanceof Deprecated) {
		schema.setVendorExtension("x-deprecated", true);
	}
}
 
Example #6
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
protected void applyNumberAnnotationDetails(AbstractNumericProperty schema, Annotation annotation) {
	if (annotation instanceof DecimalMin) {
		schema.setMinimum(new BigDecimal(((DecimalMin) annotation).value()));
	} else if (annotation instanceof DecimalMax) {
		schema.setMaximum(new BigDecimal(((DecimalMax) annotation).value()));
	} else if (annotation instanceof Min) {
		schema.setMinimum(BigDecimal.valueOf(((Min) annotation).value()));
	} else if (annotation instanceof Max) {
		schema.setMaximum(BigDecimal.valueOf(((Max) annotation).value()));
	} else if (annotation instanceof Deprecated) {
		schema.setVendorExtension("x-deprecated", true);
	}
}
 
Example #7
Source File: ConstraintReaderImplTest.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
public void exec(
        @NotNull
        @Min(value = 1, groups = Create.class)
        @Max(value = 2, groups = Update.class) Integer count,
        @NotBlank
        @OneOf({"all", "single"}) String type,
        Enum1 enumeration,
        Optional<Enum1> optionalEnum,
        @DecimalMin(value = "0.1", message = "Must exceed ${value}") BigDecimal min) {
}
 
Example #8
Source File: DecimalMinPostProcessor.java    From RestDoc with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyModel postProcessInternal(PropertyModel propertyModel) {
    DecimalMin minAnno = propertyModel.getPropertyItem().getAnnotation(DecimalMin.class);
    if (minAnno == null) return propertyModel;

    String hint = "";
    if (minAnno.inclusive())
        hint += " (值大于等于" + minAnno.value() + ")";
    else
        hint += " (值大于" + minAnno.value() + ")";
    propertyModel.setDescription(
            TextUtils.combine(propertyModel.getDescription(), hint)
    );
    return propertyModel;
}
 
Example #9
Source File: SchemaGeneratorHelper.java    From spring-openapi with MIT License 5 votes vote down vote up
protected void applyNumberAnnotation(Schema<?> schema, Annotation annotation) {
    if (annotation instanceof DecimalMin) {
        schema.setMinimum(new BigDecimal(((DecimalMin) annotation).value()));
    } else if (annotation instanceof DecimalMax) {
        schema.setMaximum(new BigDecimal(((DecimalMax) annotation).value()));
    } else if (annotation instanceof Min) {
        schema.setMinimum(BigDecimal.valueOf(((Min) annotation).value()));
    } else if (annotation instanceof Max) {
        schema.setMaximum(BigDecimal.valueOf(((Max) annotation).value()));
    }
}
 
Example #10
Source File: JavaxValidationModule.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Determine a number type's minimum (exclusive) value.
 *
 * @param member the field or method to check
 * @return specified exclusive minimum value (or null)
 * @see DecimalMin
 * @see Positive
 */
protected BigDecimal resolveNumberExclusiveMinimum(MemberScope<?, ?> member) {
    DecimalMin decimalMinAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMin.class, DecimalMin::groups);
    if (decimalMinAnnotation != null && !decimalMinAnnotation.inclusive()) {
        return new BigDecimal(decimalMinAnnotation.value());
    }
    Positive positiveAnnotation = this.getAnnotationFromFieldOrGetter(member, Positive.class, Positive::groups);
    if (positiveAnnotation != null) {
        return BigDecimal.ZERO;
    }
    return null;
}
 
Example #11
Source File: BeanValidationProcessor.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
@PostConstruct
public void init() {
	validationAnnotations = new HashSet<>();
	validationAnnotations.addAll(Arrays.asList(NotNull.class, Size.class,
			Pattern.class, DecimalMin.class, DecimalMax.class, Min.class,
			Max.class));

}
 
Example #12
Source File: HeartbeatProperties.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
public void setIntervalRatio(
		@DecimalMin("0.1") @DecimalMax("0.9") double intervalRatio) {
	this.intervalRatio = intervalRatio;
}
 
Example #13
Source File: HeartbeatProperties.java    From spring-cloud-consul with Apache License 2.0 4 votes vote down vote up
public @DecimalMin("0.1") @DecimalMax("0.9") double getIntervalRatio() {
	return this.intervalRatio;
}
 
Example #14
Source File: DecimalMinPropertyValidator.java    From dolphin-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(DecimalMin minValue) {
    this.minValue = new BigDecimal(minValue.value() );
    this.inclusive = minValue.inclusive();
}
 
Example #15
Source File: RamlInterpreterTest.java    From springmvc-raml-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void checkJSR303() {
	TestConfig.setBasePackage("com.gen.foo");
	TestConfig.setIncludeJsr303Annotations(true);

	assertThat(AbstractRuleTestBase.RAML, is(notNullValue()));
	RamlResource validations = AbstractRuleTestBase.RAML.getResource("/validations");

	RamlDataType validationsGetType = validations.getAction(RamlActionType.GET).getResponses().get("200").getBody()
			.get("application/json").getType();
	assertThat(validationsGetType, is(notNullValue()));
	ApiBodyMetadata validationsGetRequest = RamlTypeHelper.mapTypeToPojo(jCodeModel, AbstractRuleTestBase.RAML,
			validationsGetType.getType());
	assertThat(validationsGetRequest, is(notNullValue()));
	assertThat(validationsGetRequest.getName(), is("Validation"));
	assertThat(validationsGetRequest.isArray(), is(false));

	JDefinedClass validation = (JDefinedClass) CodeModelHelper.findFirstClassBySimpleName(jCodeModel, "Validation");

	checkIfGetterContainsAnnotation(true, validation, NotNull.class, "lastname", "pattern", "length", "id", "anEnum", "anotherEnum");
	checkIfGetterContainsAnnotation(false, validation, NotNull.class, "firstname", "minLength");
	checkIfGetterContainsAnnotation(true, validation, Size.class, "length", "minLength");
	checkIfGetterContainsAnnotation(true, validation, Pattern.class, "pattern");

	checkIfAnnotationHasParameter(validation, Size.class, "length", "min");
	checkIfAnnotationHasParameter(validation, Size.class, "length", "max");
	checkIfAnnotationHasParameter(validation, Size.class, "minLength", "min");
	checkIfAnnotationHasParameter(validation, Pattern.class, "pattern", "regexp");

	checkIfAnnotationHasParameter(validation, DecimalMin.class, "id", "value");
	checkIfAnnotationHasParameter(validation, DecimalMax.class, "id", "value");

	JFieldVar anEnum = getField(validation, "anEnum");
	assertThat(anEnum.type().fullName(), is("com.gen.foo.model.AnEnum"));

	JFieldVar anotherEnum = getField(validation, "anotherEnum");
	assertThat(anotherEnum.type().fullName(), is("com.gen.foo.model.EnumChecks"));

	JDefinedClass enumChecks = (JDefinedClass) CodeModelHelper.findFirstClassBySimpleName(jCodeModel, "EnumChecks");
	String elementAsString = CodeModelHelper.getElementAsString(enumChecks);
	assertThat(elementAsString, not(containsString("(\"value_with_underscore\", \"value_with_underscore\")")));
	assertThat(elementAsString, containsString("FEE(\"fee\")"));
	assertThat(elementAsString, containsString("TESTFEE(\"testfee\")"));
}
 
Example #16
Source File: ImageRecognitionProcessorProperties.java    From tensorflow with Apache License 2.0 4 votes vote down vote up
@NotNull
@DecimalMin("1")
public int getResponseSize() {
	return responseSize;
}
 
Example #17
Source File: DefaultModelPlugin.java    From BlogManagePlatform with Apache License 2.0 4 votes vote down vote up
private String resolveRange(Field field) {
	String min = Optional.ofNullable(field.getAnnotation(Min.class)).map((item) -> String.valueOf(item.value())).orElse(null);
	if (min == null) {
		min = Optional.ofNullable(field.getAnnotation(DecimalMin.class)).map(DecimalMin::value).orElse(null);
	}
	if (field.isAnnotationPresent(PositiveOrZero.class)) {
		if (min == null || new BigDecimal(min).compareTo(BigDecimal.ZERO) < 0) {
			min = "非负数";
		}
	}
	if (field.isAnnotationPresent(Positive.class)) {
		if (min == null || new BigDecimal(min).compareTo(BigDecimal.ZERO) <= 0) {
			min = "正数";
		}
	}
	min = min == null ? null : StrUtil.concat("最小值为", min);
	if (field.isAnnotationPresent(DecimalMin.class)) {
		if (!field.getAnnotation(DecimalMin.class).inclusive()) {
			min = min == null ? null : StrUtil.concat(min, "且不能等于最小值");
		}
	}
	String max = Optional.ofNullable(field.getAnnotation(Max.class)).map((item) -> String.valueOf(item.value())).orElse(null);
	if (max == null) {
		max = Optional.ofNullable(field.getAnnotation(DecimalMax.class)).map(DecimalMax::value).orElse(null);
	}
	if (field.isAnnotationPresent(NegativeOrZero.class)) {
		if (max == null || new BigDecimal(max).compareTo(BigDecimal.ZERO) > 0) {
			max = "非正数";
		}
	}
	if (field.isAnnotationPresent(Negative.class)) {
		if (max == null || new BigDecimal(min).compareTo(BigDecimal.ZERO) >= 0) {
			max = "负数";
		}
	}
	max = max == null ? null : StrUtil.concat("最大值为", max);
	if (field.isAnnotationPresent(DecimalMax.class)) {
		if (!field.getAnnotation(DecimalMax.class).inclusive()) {
			min = min == null ? null : StrUtil.concat(min, "且不能等于最大值");
		}
	}
	String digit = Optional.ofNullable(field.getAnnotation(Digits.class)).map((item) -> {
		String integer = String.valueOf(item.integer());
		String fraction = String.valueOf(item.fraction());
		return StrUtil.concat("整数位", integer, ",", "小数位", fraction);
	}).orElse(null);
	if (min == null && max == null && digit == null) {
		return null;
	}
	return StrUtil.join(",", min, max, digit);
}
 
Example #18
Source File: JavaxValidationModuleTest.java    From jsonschema-generator with Apache License 2.0 4 votes vote down vote up
@DecimalMin(value = "10.1", inclusive = false, groups = Test.class)
@DecimalMax(value = "20.2", inclusive = false, groups = Test.class)
public Integer getTenToTwentyExclusiveOnGetterInteger() {
    return tenToTwentyExclusiveOnGetterInteger;
}
 
Example #19
Source File: JavaxValidationModuleTest.java    From jsonschema-generator with Apache License 2.0 4 votes vote down vote up
@DecimalMin(value = "10.1", groups = Test.class)
@DecimalMax(value = "20.2", groups = Test.class)
public Integer getTenToTwentyInclusiveOnGetterInteger() {
    return tenToTwentyInclusiveOnGetterInteger;
}
 
Example #20
Source File: OrcWriterConfig.java    From presto with Apache License 2.0 4 votes vote down vote up
@DecimalMin("0.0")
@DecimalMax("100.0")
public double getValidationPercentage()
{
    return validationPercentage;
}
 
Example #21
Source File: FeaturesConfig.java    From presto with Apache License 2.0 4 votes vote down vote up
@DecimalMin("0.0")
@DecimalMax("1.0")
public double getMemoryRevokingTarget()
{
    return memoryRevokingTarget;
}
 
Example #22
Source File: FeaturesConfig.java    From presto with Apache License 2.0 4 votes vote down vote up
@DecimalMin("0.0")
@DecimalMax("1.0")
public double getMemoryRevokingThreshold()
{
    return memoryRevokingThreshold;
}
 
Example #23
Source File: FailureDetectorConfig.java    From presto with Apache License 2.0 4 votes vote down vote up
@DecimalMin("0.0")
@DecimalMax("1.0")
public double getFailureRatioThreshold()
{
    return failureRatioThreshold;
}