Package javax.validation.constraints

Examples of javax.validation.constraints.Min


            return units == null ? inferUnits() : units.units();
        }

        public Long min()
        {
            final Min min = mMethod.getAnnotation(Min.class);
            if (min != null)
            {
                return min.value();
            }
            final long[] minMax = minMaxFromDataType(attribute().dataType());
            return minMax == null ? null : minMax[0];
        }
View Full Code Here


        } else if (annotation instanceof Max.List) {
            // Defines several @Max annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Min) {
            // The annotated element must be a number whose value must be higher or equal to the specified minimum.
            Min min = (Min) annotation;
            sb.append("number: true, \n");
            sb.append("min: ").append(min.value());
        } else if (annotation instanceof Min.List) {
            // Defines several @Min annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof NotNull) {
            // The annotated element must not be null.
View Full Code Here

            }
        }
       
        if (!editableValueHolder.isRequired()) {
            if (constraint.annotationType().equals(Min.class)) {
                Min min = (Min) constraint;
                if (min.value() > 0) {
                    editableValueHolder.setRequired(true);
                }
            }
            else if (constraint.annotationType().equals(Size.class)) {
                Size size = (Size) constraint;
View Full Code Here

            Max a = (Max) helper.getAnnotation(element, Max.class);
            MaxFacet facet = new MaxFacet(a.value());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Min.class)) {
            Min a = (Min) helper.getAnnotation(element, Min.class);
            MinFacet facet = new MinFacet(a.value());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, NotNull.class)) {
            property.setNotNullAnnotated(true);
        }
        if (helper.isAnnotationPresent(element, Pattern.class)) {
            Pattern a = (Pattern) helper.getAnnotation(element, Pattern.class);
            PatternFacet facet = new PatternFacet(a.regexp(), a.flags());
            property.addFacet(facet);
        }
        /* Example:
            @Pattern.List({
                @Pattern(regexp = "first_expression", message = "first.Pattern.message"),
                @Pattern(regexp = "second_expression", message = "second.Pattern.message"),
                @Pattern(regexp = "third_expression", message = "third.Pattern.message")
        }) */
        if (helper.isAnnotationPresent(element, Pattern.List.class)) {
            Pattern.List a = (Pattern.List) helper.getAnnotation(element, Pattern.List.class);
            PatternListFacet facet = new PatternListFacet(new ArrayList<PatternFacet>());
            for (Pattern pat : a.value()) {
                PatternFacet pf = new PatternFacet(pat.regexp(), pat.flags());
                facet.addPattern(pf);
            }
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Size.class)) {
            Size a = (Size) helper.getAnnotation(element, Size.class);
            final int min = a.min();
            final int max = a.max();
            if (min != 0 || max != Integer.MAX_VALUE) { // Fixes generation of an empty facet.
                if ("java.lang.String".equals(property.getType().getName())) { // @Size serves for both length facet and occurs restriction.
                    SizeFacet facet = new SizeFacet(min, max); // For minLength, maxLength.
                    property.addFacet(facet);
                } else { // For minOccurs, maxOccurs.
View Full Code Here

            return units == null ? inferUnits() : units.units();
        }

        public Long min()
        {
            final Min min = mMethod.getAnnotation(Min.class);
            if (min != null)
            {
                return min.value();
            }
            final long[] minMax = minMaxFromDataType(attribute().dataType());
            return minMax == null ? null : minMax[0];
        }
View Full Code Here

  @Test
  public void testIsValidMinValidator() {
    AnnotationDescriptor<Min> descriptor = new AnnotationDescriptor<Min>( Min.class );
    descriptor.setValue( "value", 15L );
    descriptor.setValue( "message", "{validator.min}" );
    Min m = AnnotationFactory.create( descriptor );

    MinValidatorForCharSequence constraint = new MinValidatorForCharSequence();
    constraint.initialize( m );
    testMinValidator( constraint, true );
  }
View Full Code Here

  @Test
  public void testIsValidMinValidator() {
    AnnotationDescriptor<Min> descriptor = new AnnotationDescriptor<Min>( Min.class );
    descriptor.setValue( "value", 15L );
    descriptor.setValue( "message", "{validator.min}" );
    Min m = AnnotationFactory.create( descriptor );

    MinValidatorForNumber constraint = new MinValidatorForNumber();
    constraint.initialize( m );
    testMinValidator( constraint, true );
  }
View Full Code Here

            return units == null ? inferUnits() : units.units();
        }

        public Long min()
        {
            final Min min = mMethod.getAnnotation(Min.class);
            if (min != null)
            {
                return min.value();
            }
            final long[] minMax = minMaxFromDataType(attribute().dataType());
            return minMax == null ? null : minMax[0];
        }
View Full Code Here

TOP

Related Classes of javax.validation.constraints.Min

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.