Examples of Digits


Examples of interfaces.Digits

 
  @JExercise(
      tests="Digits(int,int)",
      description="The value starts at zero.")
  public void testDigit() {
    digit = new Digits(10,2);
    assertEquals(0, digit.toInt());
  }
View Full Code Here

Examples of interfaces.Digits

    digit = new Digits(10,2);
    assertEquals(0, digit.toInt());
  }
 
  private void testIncrement(int base, boolean checkValue, boolean checkToString) {
    digit = new Digits(base, 2);
    int i = 0;
    String digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    while (i < base) {
      if (checkValue) {
        assertEquals(i % base,  digit.toInt());
View Full Code Here

Examples of javax.validation.constraints.Digits

        }
        final Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(method)[paramNum];

        for (final Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof Digits) {
                Digits digitsAnnotation = (Digits) parameterAnnotation;
                FacetUtil.addFacet(create(digitsAnnotation, processParameterContext.getFacetHolder()));
                return;
            }
        }
    }
View Full Code Here

Examples of javax.validation.constraints.Digits

        if (BigDecimal.class != processMethodContext.getMethod().getReturnType()) {
            return;
        }

        final Digits annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Digits.class);
        if (annotation == null) {
            return;
        }
        FacetUtil.addFacet(create(processMethodContext, annotation));
    }
View Full Code Here

Examples of javax.validation.constraints.Digits

        }
        final Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(method)[paramNum];

        for (final Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof Digits) {
                Digits digitsAnnotation = (Digits) parameterAnnotation;
                FacetUtil.addFacet(create(digitsAnnotation, processParameterContext.getFacetHolder()));
                return;
            }
        }
    }
View Full Code Here

Examples of javax.validation.constraints.Digits

            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Digits) {
            // The annotated element must be a number within accepted range Supported types are: BigDecimal BigInteger
            // String byte, short, int, long, and their respective wrapper types
            // null elements are considered valid
            Digits digits = (Digits) annotation;
            if (digits.fraction() == 0) {
                sb.append("digits: true, \n");
                sb.append("maxlength: ").append(digits.integer());
            } else {
                // Something like /^\d{1,5}(\.\d{1,2})?$/
                sb.append("pattern: /^\\d{1,").append(digits.integer()).append("}(\\.\\d{1,").append(digits.fraction()).append("})?$/ ");
            }
        } else if (annotation instanceof Digits.List) {
            // Defines several @Digits annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Future) {
View Full Code Here

Examples of javax.validation.constraints.Digits

            DecimalMax a = (DecimalMax) helper.getAnnotation(element, DecimalMax.class);
            DecimalMaxFacet facet = new DecimalMaxFacet(a.value(), a.inclusive());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Digits.class)) {
            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

Examples of javax.validation.constraints.Digits

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 5 );
    descriptor.setValue( "fraction", 2 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here

Examples of javax.validation.constraints.Digits

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", -1 );
    descriptor.setValue( "fraction", 1 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForCharSequence constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here

Examples of javax.validation.constraints.Digits

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 1 );
    descriptor.setValue( "fraction", -1 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForCharSequence constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.