javax.validation.constraints.DecimalMin的实例源码

项目:randomito-all    文件DecimalMinMaxAnnotationPostProcessor.java   
@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());
}
项目:geeMVC-Java-MVC-Framework    文件DecimalMinValidationAdapter.java   
@Override
public void validate(DecimalMin decimalMinAnnotation,String name,ValidationContext validationCtx,Errors errors) {
    Object value = validationCtx.value(name);

    if (value == null)
        return;

    if (!(value instanceof BigDecimal))
        errors.add(name,decimalMinAnnotation.message(),value);

    if (!validateMin(BigDecimal.valueOf(Double.valueOf(decimalMinAnnotation.value())),value)) {
        errors.add(name,value,decimalMinAnnotation.value());
    }
}
项目:AngularBeans    文件BeanValidationProcessor.java   
@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));

}
项目:springmvc-raml-plugin    文件RamlInterpreterTest.java   
@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,"firstname","minLength");
checkIfFieldContainsAnnotation(true,"pattern");

checkIfAnnotationHasParameter(validation,"min");
checkIfAnnotationHasParameter(validation,"max");
checkIfAnnotationHasParameter(validation,"minLength","regexp");

checkIfAnnotationHasParameter(validation,"value");
checkIfAnnotationHasParameter(validation,"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\")")); 
  }
项目:benerator    文件AnnotationMapper.java   
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());
    }
  }
项目:ServiceServer    文件Movie.java   
@Column(name = "rating",columnDeFinition="decimal(2,1) default 0.0")
@DecimalMin("0.1")
public float getrating() {
    return rating;
}
项目:ServiceServer    文件MovieOnShow.java   
@Column(name = "price",columnDeFinition="decimal(5,2)")
@DecimalMin("0.01")
public Float getPrice() {
    return price;
}
项目:webpedidos    文件Pedido.java   
@NotNull
@DecimalMin("0.0")
@Column(name = "valor_frete",nullable = false,precision = 10,scale = 2)
public BigDecimal getValorFrete() {
    return valorFrete;
}
项目:webpedidos    文件Pedido.java   
@NotNull
@DecimalMin("0.0")
@Column(name = "valor_desconto",scale = 2)
public BigDecimal getValorDesconto() {
    return valorDesconto;
}
项目:webpedidos    文件Pedido.java   
@NotNull
@DecimalMin("0.0")
@Column(name = "valor_total",scale = 2)
public BigDecimal getValorTotal() {
    return valorTotal;
}
项目:geeMVC-Java-MVC-Framework    文件DecimalMinValidationAdapter.java   
@Override
public boolean incudeInValidation(DecimalMin decimalMinAnnotation,RequestHandler requestHandler,ValidationContext validationCtx) {
    return true;
}
项目:presto    文件FailureDetectorConfig.java   
@DecimalMin("0.0")
@DecimalMax("1.0")
public double getFailureRatioThreshold()
{
    return failureRatioThreshold;
}
项目:dolphin-platform    文件DecimalMinPropertyValidator.java   
@Override
public void initialize(DecimalMin minValue) {
    this.minValue = new BigDecimal(minValue.value() );
    this.inclusive = minValue.inclusive();
}
项目:motech    文件FieldProcessorTest.java   
@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,"0.0");
    assertCriterion(epsilon,"1.0");
    assertCriterion(epsilon,0.75,0.5,0.25,0");
    assertCriterion(epsilon,"-1,3");

    FieldDto random = findFieldWithName(fields,"random");
    assertCriterion(random,"0");
    assertCriterion(random,"10");

    FieldDto gaussian = findFieldWithName(fields,"gaussian");
    assertCriterion(gaussian,"0.0");
    assertCriterion(gaussian,"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,"100");
    assertCriterion(article,"500");
}
项目:random-beans    文件DecimalMinMaxAnnotationHandler.java   
@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(),random.nextLong()
            );
        }
        if (fieldType.equals(BigDecimal.class)) {
            return new BigDecimalRangeRandomizer(
                    minValue == null ? null : minValue.longValue(),random.nextLong()
            );
        }
        if (fieldType.equals(String.class)) {
            BigDecimalRangeRandomizer delegate = new BigDecimalRangeRandomizer(
                    minValue == null ? null : minValue.longValue(),random.nextLong()
            );
            return new StringDelegatingRandomizer(delegate);
        }
    }
    return null;
}
项目:pinetrail    文件Coordinates.java   
/**
 * 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();
项目:pinetrail    文件Waypoint.java   
/**
 * The distance in meters between this point and the prevIoUs point in the
 * trail.
 *
 * @return the distance in meters between this point and the prevIoUs point
 * in the trail
 */
@DecimalMin(value = "0",message = "{Model.Waypoint.distance.Positive}")
Double getdistance();
项目:pinetrail    文件Waypoint.java   
/**
 * 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();
项目:pinetrail    文件Waypoint.java   
/**
 * The speed,in km per hours,with which the distance between this point
 * and the prevIoUs point was covered.
 *
 * @return the speed,with which the distance between this
 * point and the prevIoUs point was covered
 */
@DecimalMin(value = "0",message = "{Model.Waypoint.Speed.Positive}")
Double getSpeed();
项目:pinetrail    文件Waypoint.java   
/**
 * 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();
项目:pinetrail    文件Coordinates.java   
/**
 * 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();
项目:jbromo    文件AnnotationUtil.java   
/**
 * Get decimal value from DecimalMin annotation.
 * @param field the field
 * @return the decimal min value
 */
public static BigDecimal getDecimalMin(final Field field) {
    final DecimalMin dm = field.getAnnotation(DecimalMin.class);
    return dm == null ? null : new BigDecimal(dm.value());
}
项目:ocelot    文件ValidationCdiDataService.java   
public void methodWithArgumentDecimalMin(@DecimalMin("50") long lg0) {}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...