javax.validation.constraints.DecimalMax Java Examples
The following examples show how to use
javax.validation.constraints.DecimalMax.
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 |
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 |
/** * 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 #3
Source File: OpenApiClientGenerator.java From spring-openapi with MIT License | 6 votes |
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 #4
Source File: OpenApiTransformer.java From spring-openapi with MIT License | 5 votes |
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 #5
Source File: BeanValidationProcessor.java From AngularBeans with GNU Lesser General Public License v3.0 | 5 votes |
@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 #6
Source File: JavaxValidationModule.java From jsonschema-generator with Apache License 2.0 | 5 votes |
/** * 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 #7
Source File: DecimalMaxPostProcessor.java From RestDoc with Apache License 2.0 | 5 votes |
@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 #8
Source File: OpenApiTransformer.java From spring-openapi with MIT License | 5 votes |
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 #9
Source File: SchemaGeneratorHelper.java From spring-openapi with MIT License | 5 votes |
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: FeaturesConfig.java From presto with Apache License 2.0 | 4 votes |
@DecimalMin("0.0") @DecimalMax("1.0") public double getMemoryRevokingTarget() { return memoryRevokingTarget; }
Example #11
Source File: OrcWriterConfig.java From presto with Apache License 2.0 | 4 votes |
@DecimalMin("0.0") @DecimalMax("100.0") public double getValidationPercentage() { return validationPercentage; }
Example #12
Source File: FeaturesConfig.java From presto with Apache License 2.0 | 4 votes |
@DecimalMin("0.0") @DecimalMax("1.0") public double getMemoryRevokingThreshold() { return memoryRevokingThreshold; }
Example #13
Source File: FailureDetectorConfig.java From presto with Apache License 2.0 | 4 votes |
@DecimalMin("0.0") @DecimalMax("1.0") public double getFailureRatioThreshold() { return failureRatioThreshold; }
Example #14
Source File: JavaxValidationModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@DecimalMin(value = "10.1", groups = Test.class) @DecimalMax(value = "20.2", groups = Test.class) public Integer getTenToTwentyInclusiveOnGetterInteger() { return tenToTwentyInclusiveOnGetterInteger; }
Example #15
Source File: JavaxValidationModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@DecimalMin(value = "10.1", inclusive = false, groups = Test.class) @DecimalMax(value = "20.2", inclusive = false, groups = Test.class) public Integer getTenToTwentyExclusiveOnGetterInteger() { return tenToTwentyExclusiveOnGetterInteger; }
Example #16
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 4 votes |
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 #17
Source File: RamlInterpreterTest.java From springmvc-raml-plugin with Apache License 2.0 | 4 votes |
@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 #18
Source File: DecimalMaxPropertyValidator.java From dolphin-platform with Apache License 2.0 | 4 votes |
@Override public void initialize(final DecimalMax maxValue) { this.maxValue = new BigDecimal(maxValue.value() ); this.inclusive = maxValue.inclusive(); }
Example #19
Source File: HeartbeatProperties.java From spring-cloud-consul with Apache License 2.0 | 4 votes |
public @DecimalMin("0.1") @DecimalMax("0.9") double getIntervalRatio() { return this.intervalRatio; }
Example #20
Source File: HeartbeatProperties.java From spring-cloud-consul with Apache License 2.0 | 4 votes |
public void setIntervalRatio( @DecimalMin("0.1") @DecimalMax("0.9") double intervalRatio) { this.intervalRatio = intervalRatio; }
Example #21
Source File: CsvBeanValidatorTest.java From super-csv-annotation with Apache License 2.0 | 4 votes |
@DecimalMax(value="20", groups=Group3.class) Integer getAge() { return age; }