vertx/src/main/java/eu/internetofus/common/vertx/OpenAPIValidator.java
/**
   * Validate that the value is a valid number.
   *
   * @param promise     to inform of the validation.
   * @param environment to use for the validation.
   *
   * @return the future that says if the number is valid or not.
   */
Validate that the value is a valid number.
@param promise     to inform of the validation.
@param environment to use for the validation.

@return the future that says if the number is valid or not.
Validate that the value is a valid number . @param promise to inform of the validation . @param environment to use for the validation . @return the future that says if the number is valid or not .
static Future<ValueEnvironment> validateNumberValue(@NotNull final Promise<ValueEnvironment> promise,
      @NotNull final ValueEnvironment environment) {
    if (environment.value instanceof Number) {
      final var value = (Number) environment.value;
      var error = false;
      final var bigValue = new BigDecimal(value.doubleValue());
      final var min = environment.specification.getNumber("minimum", null);
      if (min != null) {
        final var bigMin = new BigDecimal(min.doubleValue());
        final var compare = bigValue.compareTo(bigMin);
        final var excludeMin = environment.specification.getBoolean("exclusiveMinimum", false);
        if (excludeMin && compare < 1) {
          promise.fail(environment.notValid("The value must be greater than the minimum."));
          error = true;
        } else if (!excludeMin && compare < 0) {
          promise.fail(environment.notValid("The value must be equals or greater than the minimum."));
          error = true;
        }
      }
      final var max = environment.specification.getNumber("maximum", null);
      if (max != null) {
        final var bigMax = new BigDecimal(max.doubleValue());
        final var compare = bigValue.compareTo(bigMax);
        final var excludeMax = environment.specification.getBoolean("exclusiveMaximum", false);
        if (excludeMax && compare > -1) {
          promise.tryFail(environment.notValid("The value must be less than the maximum."));
          error = true;
        } else if (!excludeMax && compare > 0) {
          promise.tryFail(environment.notValid("The value must be equals or less than the maximum."));
          error = true;
        }
      }
      final var multipleOf = environment.specification.getNumber("multipleOf", null);
      if (multipleOf != null) {
        final var bigMultipleOf = new BigDecimal(multipleOf.doubleValue());
        final var remainder = bigValue.remainder(bigMultipleOf);
        final var precision = new BigDecimal(0.000000001);
        if (remainder.abs().max(precision).compareTo(precision) > 0) {
          promise.tryFail(environment.notValid("The value must be a multiple of '" + multipleOf + "'."));
          error = true;
        }
      }
      if (!error) {
        environment.match = true;
      }
    } else {
      promise.fail(environment.notValid("Expecting a 'number' value."));
    }
    return promise.future();
  }
static Future < ValueEnvironment > validateNumberValue ( @ NotNull final Promise < ValueEnvironment > promise , @ NotNull final ValueEnvironment environment ) { if ( environment . value instanceof Number ) { final var value = ( Number ) environment . value ; var error = false ; final var bigValue = new BigDecimal ( value . doubleValue ( ) ) ; final var min = environment . specification . getNumber ( "minimum" , null ) ; if ( min != null ) { final var bigMin = new BigDecimal ( min . doubleValue ( ) ) ; final var compare = bigValue . compareTo ( bigMin ) ; final var excludeMin = environment . specification . getBoolean ( "exclusiveMinimum" , false ) ; if ( excludeMin && compare < 1 ) { promise . fail ( environment . notValid ( "The value must be greater than the minimum." ) ) ; error = true ; } else if ( ! excludeMin && compare < 0 ) { promise . fail ( environment . notValid ( "The value must be equals or greater than the minimum." ) ) ; error = true ; } } final var max = environment . specification . getNumber ( "maximum" , null ) ; if ( max != null ) { final var bigMax = new BigDecimal ( max . doubleValue ( ) ) ; final var compare = bigValue . compareTo ( bigMax ) ; final var excludeMax = environment . specification . getBoolean ( "exclusiveMaximum" , false ) ; if ( excludeMax && compare > - 1 ) { promise . tryFail ( environment . notValid ( "The value must be less than the maximum." ) ) ; error = true ; } else if ( ! excludeMax && compare > 0 ) { promise . tryFail ( environment . notValid ( "The value must be equals or less than the maximum." ) ) ; error = true ; } } final var multipleOf = environment . specification . getNumber ( "multipleOf" , null ) ; if ( multipleOf != null ) { final var bigMultipleOf = new BigDecimal ( multipleOf . doubleValue ( ) ) ; final var remainder = bigValue . remainder ( bigMultipleOf ) ; final var precision = new BigDecimal ( 0.000000001 ) ; if ( remainder . abs ( ) . max ( precision ) . compareTo ( precision ) > 0 ) { promise . tryFail ( environment . notValid ( "The value must be a multiple of '" + multipleOf + "'." ) ) ; error = true ; } } if ( ! error ) { environment . match = true ; } } else { promise . fail ( environment . notValid ( "Expecting a 'number' value." ) ) ; } return promise . future ( ) ; }
Validate that the value is a valid number.
Validate that the value is a valid number .
// it is not a multiple of