Package javax.validation.constraints

Examples of javax.validation.constraints.Max


            return minMax == null ? null : minMax[0];
        }

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


        } else if (annotation instanceof Future.List) {
            // Defines several @Future annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Max) {
            // The annotated element must be a number whose value must be lower or equal to the specified maximum.
            Max max = (Max) annotation;
            sb.append("number: true, \n");
            sb.append("max: ").append(max.value());
        } 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.
View Full Code Here

       
        Annotation constraint = constraintDescriptor.getAnnotation();
       
        if (!isMaxlenghtSet(input)) {
            if (constraint.annotationType().equals(Max.class)) {
                Max max = (Max) constraint;
                if (max.value() > 0) {
                    setMaxlength(input, Long.valueOf(max.value()).intValue());
                }
            }
            else if (constraint.annotationType().equals(Size.class)) {
                Size size = (Size) constraint;
                if (size.max() > 0) {
View Full Code Here

            Digits a = (Digits) helper.getAnnotation(element, Digits.class);
            DigitsFacet facet = new DigitsFacet(a.integer(), a.fraction());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Max.class)) {
            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 minMax == null ? null : minMax[0];
        }

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

  public void testIsValidMax() {

    AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class );
    descriptor.setValue( "value", 15L );
    descriptor.setValue( "message", "{validator.max}" );
    Max m = AnnotationFactory.create( descriptor );

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

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

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

  @TestForIssue(jiraKey = "HV-102")
  public void testRecursiveMessageInterpolation() {
    AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class );
    descriptor.setValue( "message", "{replace.in.user.bundle1}" );
    descriptor.setValue( "value", 10L );
    Max max = AnnotationFactory.create( descriptor );

    ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(
        new ConstraintHelper(),
        null,
        max,
        java.lang.annotation.ElementType.FIELD
    );

    interpolator = new ResourceBundleMessageInterpolator(
        new TestResourceBundleLocator()
    );
    MessageInterpolator.Context messageInterpolatorContext = createMessageInterpolatorContext( constraintDescriptor );

    String expected = "{replace.in.default.bundle2}";
    String actual = interpolator.interpolate( max.message(), messageInterpolatorContext );
    assertEquals(
        actual, expected, "Within default bundle replacement parameter evaluation should not be recursive!"
    );
  }
View Full Code Here

  public void testCorrectMessageInterpolationIfParameterCannotBeReplaced() {
    AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class );
    String message = "Message should stay unchanged since {fubar} is not replaceable";
    descriptor.setValue( "message", message );
    descriptor.setValue( "value", 10L );
    Max max = AnnotationFactory.create( descriptor );

    ConstraintDescriptorImpl<Max> constraintDescriptor = new ConstraintDescriptorImpl<Max>(
        new ConstraintHelper(),
        null,
        max,
        java.lang.annotation.ElementType.FIELD
    );

    interpolator = new ResourceBundleMessageInterpolator(
        new TestResourceBundleLocator()
    );

    MessageInterpolator.Context messageInterpolatorContext = createMessageInterpolatorContext( constraintDescriptor );

    String actual = interpolator.interpolate( max.message(), messageInterpolatorContext );
    assertEquals(
        actual, message, "The message should not have changed."
    );
  }
View Full Code Here

            return minMax == null ? null : minMax[0];
        }

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

TOP

Related Classes of javax.validation.constraints.Max

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.