當前位置: 首頁>>代碼示例>>Java>>正文


Java DecimalMax類代碼示例

本文整理匯總了Java中javax.validation.constraints.DecimalMax的典型用法代碼示例。如果您正苦於以下問題:Java DecimalMax類的具體用法?Java DecimalMax怎麽用?Java DecimalMax使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DecimalMax類屬於javax.validation.constraints包,在下文中一共展示了DecimalMax類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Override
public Object process(AnnotationInfo ctx, Object value) throws Exception {
    if (!ctx.isAnnotationPresent(DecimalMin.class)
            && !ctx.isAnnotationPresent(DecimalMax.class)) {
        return value;
    }
    String minValue = "1";
    if (ctx.isAnnotationPresent(DecimalMin.class)) {
        minValue = ctx.getAnnotation(DecimalMin.class).value();
    }
    String maxValue = "50";
    if (ctx.isAnnotationPresent(DecimalMax.class)) {
        maxValue = ctx.getAnnotation(DecimalMax.class).value();
    }
    return range(minValue, maxValue, value.getClass());
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:17,代碼來源:DecimalMinMaxAnnotationPostProcessor.java

示例2: validate

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Override
public void validate(DecimalMax decimalMaxAnnotation, String name, ValidationContext validationCtx, Errors errors) {
    Object value = validationCtx.value(name);

    if (value == null)
        return;

    if (!(value instanceof BigDecimal))
        errors.add(name, "validation.error.notDecimal", value);

    if (!validateMax(BigDecimal.valueOf(Double.valueOf(decimalMaxAnnotation.value())), value)) {
        errors.add(name, "validation.error.maxDecimal", value, decimalMaxAnnotation.value());
    }
}
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:15,代碼來源:DecimalMaxValidationAdapter.java

示例3: init

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@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));

}
 
開發者ID:bessemHmidi,項目名稱:AngularBeans,代碼行數:9,代碼來源:BeanValidationProcessor.java

示例4: checkJSR303

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Test
  public void checkJSR303() {
  	PojoGenerationConfig jsr303Config = new PojoGenerationConfig().withPackage("com.gen.foo", "").withJSR303Annotations(true);
      assertThat(ramlRoot, is(notNullValue()));
      RamlResource validations = ramlRoot.getResource("/validations");
      
      RamlDataType validationsGetType = validations.getAction(RamlActionType.GET).getResponses().get("200").getBody().get("application/json").getType();
      assertThat(validationsGetType, is(notNullValue()));        
      ApiBodyMetadata validationsGetRequest = RamlTypeHelper.mapTypeToPojo(jsr303Config, jCodeModel, ramlRoot, validationsGetType.getType());
      assertThat(validationsGetRequest, is(notNullValue()));        
      assertThat(validationsGetRequest.getName(), is("Validation"));      
      assertThat(validationsGetRequest.isArray(), is(false)); 
      
JDefinedClass validation = (JDefinedClass) CodeModelHelper.findFirstClassBySimpleName(jCodeModel, "Validation");

checkIfFieldContainsAnnotation(true, validation, NotNull.class, "lastname", "pattern", "length", "id", "anEnum", "anotherEnum");
checkIfFieldContainsAnnotation(false, validation, NotNull.class, "firstname", "minLength");
checkIfFieldContainsAnnotation(true, validation, Size.class, "length", "minLength");
checkIfFieldContainsAnnotation(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.AnEnum")); 

JFieldVar anotherEnum = getField(validation, "anotherEnum");
assertThat(anotherEnum.type().fullName(), is("com.gen.foo.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\")")); 
  }
 
開發者ID:phoenixnap,項目名稱:springmvc-raml-plugin,代碼行數:41,代碼來源:RamlInterpreterTest.java

示例5: mapBeanValidationParameter

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
private static void mapBeanValidationParameter(Annotation annotation, InstanceDescriptor element) {
  	SimpleTypeDescriptor typeDescriptor = (SimpleTypeDescriptor) element.getLocalType(false);
if (annotation instanceof AssertFalse)
  		typeDescriptor.setTrueQuota(0.);
  	else if (annotation instanceof AssertTrue)
  		typeDescriptor.setTrueQuota(1.);
  	else if (annotation instanceof DecimalMax)
  		typeDescriptor.setMax(String.valueOf(DescriptorUtil.convertType(((DecimalMax) annotation).value(), typeDescriptor)));
  	else if (annotation instanceof DecimalMin)
  		typeDescriptor.setMin(String.valueOf(DescriptorUtil.convertType(((DecimalMin) annotation).value(), typeDescriptor)));
  	else if (annotation instanceof Digits) {
  		Digits digits = (Digits) annotation;
	typeDescriptor.setGranularity(String.valueOf(Math.pow(10, - digits.fraction())));
  	} else if (annotation instanceof Future)
       typeDescriptor.setMin(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.tomorrow()));
      else if (annotation instanceof Max)
	typeDescriptor.setMax(String.valueOf(((Max) annotation).value()));
      else if (annotation instanceof Min)
  		typeDescriptor.setMin(String.valueOf(((Min) annotation).value()));
  	else if (annotation instanceof NotNull) {
  		element.setNullable(false);
  		element.setNullQuota(0.);
  	} else if (annotation instanceof Null) {
  		element.setNullable(true);
  		element.setNullQuota(1.);
  	} else if (annotation instanceof Past)
       typeDescriptor.setMax(new SimpleDateFormat("yyyy-MM-dd").format(TimeUtil.yesterday()));
      else if (annotation instanceof Pattern)
  		typeDescriptor.setPattern(String.valueOf(((Pattern) annotation).regexp()));
  	else if (annotation instanceof Size) {
  		Size size = (Size) annotation;
  		typeDescriptor.setMinLength(size.min());
  		typeDescriptor.setMaxLength(size.max());
  	}
  }
 
開發者ID:raphaelfeng,項目名稱:benerator,代碼行數:36,代碼來源:AnnotationMapper.java

示例6: incudeInValidation

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Override
public boolean incudeInValidation(DecimalMax decimalMaxAnnotation, RequestHandler requestHandler, ValidationContext validationCtx) {
    return true;
}
 
開發者ID:geetools,項目名稱:geeMVC-Java-MVC-Framework,代碼行數:5,代碼來源:DecimalMaxValidationAdapter.java

示例7: getFailureRatioThreshold

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@DecimalMin("0.0")
@DecimalMax("1.0")
public double getFailureRatioThreshold()
{
    return failureRatioThreshold;
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:7,代碼來源:FailureDetectorConfig.java

示例8: initialize

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Override
public void initialize(final DecimalMax maxValue) {
    this.maxValue = new BigDecimal(maxValue.value() );
    this.inclusive = maxValue.inclusive();
}
 
開發者ID:canoo,項目名稱:dolphin-platform,代碼行數:6,代碼來源:DecimalMaxPropertyValidator.java

示例9: shouldAssignFieldValidation

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Test
public void shouldAssignFieldValidation() throws Exception {
    TypeValidationDto intMinValue = new TypeValidationDto("mds.field.validation.minValue", Integer.class.getName());
    TypeValidationDto intMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Integer.class.getName());
    TypeValidationDto intMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
    TypeValidationDto intCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());

    TypeValidationDto decMinValue = new TypeValidationDto("mds.field.validation.minValue", Double.class.getName());
    TypeValidationDto decMaxValue = new TypeValidationDto("mds.field.validation.maxValue", Double.class.getName());
    TypeValidationDto decMustBeInSet = new TypeValidationDto("mds.field.validation.mustBeInSet", String.class.getName());
    TypeValidationDto decCannotBeInSet = new TypeValidationDto("mds.field.validation.cannotBeInSet", String.class.getName());

    TypeValidationDto regex = new TypeValidationDto("mds.field.validation.regex", String.class.getName());
    TypeValidationDto minLength = new TypeValidationDto("mds.field.validation.minLength", Integer.class.getName());
    TypeValidationDto maxLength = new TypeValidationDto("mds.field.validation.maxLength", Integer.class.getName());

    doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMin.class);
    doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), DecimalMax.class);
    doReturn(singletonList(intMustBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), InSet.class);
    doReturn(singletonList(intCannotBeInSet)).when(schemaHolder).findValidations(Integer.class.getName(), NotInSet.class);
    doReturn(singletonList(intMinValue)).when(schemaHolder).findValidations(Integer.class.getName(), Min.class);
    doReturn(singletonList(intMaxValue)).when(schemaHolder).findValidations(Integer.class.getName(), Max.class);

    doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMin.class);
    doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), DecimalMax.class);
    doReturn(singletonList(decMustBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), InSet.class);
    doReturn(singletonList(decCannotBeInSet)).when(schemaHolder).findValidations(Double.class.getName(), NotInSet.class);
    doReturn(singletonList(decMinValue)).when(schemaHolder).findValidations(Double.class.getName(), Min.class);
    doReturn(singletonList(decMaxValue)).when(schemaHolder).findValidations(Double.class.getName(), Max.class);

    doReturn(singletonList(regex)).when(schemaHolder).findValidations(String.class.getName(), Pattern.class);
    doReturn(asList(minLength, maxLength)).when(schemaHolder).findValidations(String.class.getName(), Size.class);
    doReturn(singletonList(minLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMin.class);
    doReturn(singletonList(maxLength)).when(schemaHolder).findValidations(String.class.getName(), DecimalMax.class);

    processor.execute(bundle, schemaHolder);
    Collection<FieldDto> fields = processor.getElements();

    FieldDto pi = findFieldWithName(fields, "pi");
    assertCriterion(pi, "mds.field.validation.minValue", "3");
    assertCriterion(pi, "mds.field.validation.maxValue", "4");
    assertCriterion(pi, "mds.field.validation.mustBeInSet", "3,3.14,4");
    assertCriterion(pi, "mds.field.validation.cannotBeInSet", "1,2,5");

    FieldDto epsilon = findFieldWithName(fields, "epsilon");
    assertCriterion(epsilon, "mds.field.validation.minValue", "0.0");
    assertCriterion(epsilon, "mds.field.validation.maxValue", "1.0");
    assertCriterion(epsilon, "mds.field.validation.mustBeInSet", "1,0.75,0.5,0.25,0");
    assertCriterion(epsilon, "mds.field.validation.cannotBeInSet", "-1,2,3");

    FieldDto random = findFieldWithName(fields, "random");
    assertCriterion(random, "mds.field.validation.minValue", "0");
    assertCriterion(random, "mds.field.validation.maxValue", "10");

    FieldDto gaussian = findFieldWithName(fields, "gaussian");
    assertCriterion(gaussian, "mds.field.validation.minValue", "0.0");
    assertCriterion(gaussian, "mds.field.validation.maxValue", "1.0");

    FieldDto poem = findFieldWithName(fields, "poem");
    assertCriterion(poem, "mds.field.validation.regex", "[A-Z][a-z]{9}");
    assertCriterion(poem, "mds.field.validation.minLength", "10");
    assertCriterion(poem, "mds.field.validation.maxLength", "20");

    FieldDto article = findFieldWithName(fields, "article");
    assertCriterion(article, "mds.field.validation.minLength", "100");
    assertCriterion(article, "mds.field.validation.maxLength", "500");
}
 
開發者ID:motech,項目名稱:motech,代碼行數:68,代碼來源:FieldProcessorTest.java

示例10: getRandomizer

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@Override
public Randomizer<?> getRandomizer(Field field) {
    Class<?> fieldType = field.getType();
    if (ReflectionUtils.isAnnotationPresent(field, DecimalMin.class) || ReflectionUtils
            .isAnnotationPresent(field, DecimalMax.class)) {
        DecimalMax decimalMaxAnnotation = ReflectionUtils
                .getAnnotation(field, DecimalMax.class);
        DecimalMin decimalMinAnnotation = ReflectionUtils
                .getAnnotation(field, DecimalMin.class);

        BigDecimal maxValue = null;
        BigDecimal minValue = null;

        if (decimalMaxAnnotation != null) {
            maxValue = new BigDecimal(decimalMaxAnnotation.value());
        }

        if (decimalMinAnnotation != null) {
            minValue = new BigDecimal(decimalMinAnnotation.value());
        }

        if (fieldType.equals(Byte.TYPE) || fieldType.equals(Byte.class)) {
            return new ByteRangeRandomizer(
                    minValue == null ? null : minValue.byteValue(),
                    maxValue == null ? null : maxValue.byteValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(Short.TYPE) || fieldType.equals(Short.class)) {
            return new ShortRangeRandomizer(
                    minValue == null ? null : minValue.shortValue(),
                    maxValue == null ? null : maxValue.shortValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(Integer.TYPE) || fieldType.equals(Integer.class)) {
            return new IntegerRangeRandomizer(
                    minValue == null ? null : minValue.intValue(),
                    maxValue == null ? null : maxValue.intValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(Long.TYPE) || fieldType.equals(Long.class)) {
            return new LongRangeRandomizer(
                    minValue == null ? null : minValue.longValue(),
                    maxValue == null ? null : maxValue.longValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(BigInteger.class)) {
            return new BigIntegerRangeRandomizer(
                    minValue == null ? null : minValue.intValue(),
                    maxValue == null ? null : maxValue.intValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(BigDecimal.class)) {
            return new BigDecimalRangeRandomizer(
                    minValue == null ? null : minValue.longValue(),
                    maxValue == null ? null : maxValue.longValue(),
                    random.nextLong()
            );
        }
        if (fieldType.equals(String.class)) {
            BigDecimalRangeRandomizer delegate = new BigDecimalRangeRandomizer(
                    minValue == null ? null : minValue.longValue(),
                    maxValue == null ? null : maxValue.longValue(),
                    random.nextLong()
            );
            return new StringDelegatingRandomizer(delegate);
        }
    }
    return null;
}
 
開發者ID:benas,項目名稱:random-beans,代碼行數:75,代碼來源:DecimalMinMaxAnnotationHandler.java

示例11: getAge

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
@DecimalMax(value="20", groups=Group3.class)
Integer getAge() {
    return age;
}
 
開發者ID:mygreen,項目名稱:super-csv-annotation,代碼行數:5,代碼來源:CsvBeanValidatorTest.java

示例12: getLongitude

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
/**
 * The longitude of the point, in decimal degrees (WGS84 datum).
 *
 * <p>
 * The value cannot be null, must be superior or equal to -180.0 and
 * inferior to 180.0 degrees.
 *
 * @return the longitude of the point
 */
@NotNull(message = "{Model.Coordinates.Longitude.NotNull}")
@DecimalMax(value = "180", inclusive = false,
        message = "{Model.Coordinates.Longitude.MaxValue}")
@DecimalMin(value = "-180",
        message = "{Model.Coordinates.Longitude.MinValue}")
Double getLongitude();
 
開發者ID:sosna,項目名稱:pinetrail,代碼行數:16,代碼來源:Coordinates.java

示例13: getElevationDifference

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
/**
 * The difference in elevation (in meters) between this point and the
 * previous point in the trail.
 *
 * @return the difference in elevation (in meters) between this point and
 * the previous point in the trail
 */
@DecimalMin(value = "-9450", message = "{Model.Waypoint.EleDiff.Positive}")
@DecimalMax(value = "9450", message = "{Model.Waypoint.EleDiff.Max}")
Double getElevationDifference();
 
開發者ID:sosna,項目名稱:pinetrail,代碼行數:11,代碼來源:Waypoint.java

示例14: getGrade

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
/**
 * The inclination between this waypoint and the previous one, as an angle
 * of inclination to the horizontal.
 *
 * @return the inclination between this waypoint and the previous one
 */
@DecimalMin(value = "-90", message = "{Model.Waypoint.Grade.MinValue}")
@DecimalMax(value = "90.0", message = "{Model.Waypoint.Grade.MaxValue}")
Double getGrade();
 
開發者ID:sosna,項目名稱:pinetrail,代碼行數:10,代碼來源:Waypoint.java

示例15: getLatitude

import javax.validation.constraints.DecimalMax; //導入依賴的package包/類
/**
 * The latitude of the point, in decimal degrees (WGS84 datum).
 *
 * <p>
 * The latitude of the point, in decimal degrees. The value cannot be null
 * and must be between or equal to -90.0 and 90.0 degrees.
 *
 * @return the latitude of the point
 */
@NotNull(message = "{Model.Coordinates.Latitude.NotNull}")
@DecimalMax(value = "90", message = "{Model.Coordinates.Latitude.MaxValue}")
@DecimalMin(value = "-90",
        message = "{Model.Coordinates.Latitude.MinValue}")
Double getLatitude();
 
開發者ID:sosna,項目名稱:pinetrail,代碼行數:15,代碼來源:Coordinates.java


注:本文中的javax.validation.constraints.DecimalMax類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。