vertx/src/main/java/eu/internetofus/common/vertx/Repository.java
/**
   * Convert a set of values to an object that represents the order to the models
   * to return.
   *
   * @param values     to extract how the query has to be sorted. If has to be
   *                   formed by the name by the key with a prefix than can be
   *                   {@code +} or {-} to order in ascending or descending. If
   *                   you set the key without prefix is order in ascending.
   * @param codePrefix prefix to append to the error code.
   * @param checkKey   function to validate that the key is possible. It receive
   *                   the fields and return the key to sort the field or
   *                   {@code null} if the value is not valid. If it is
   *                   {@code null} it used the current key.
   *
   * @return the object that can be used to sort a query.
   *
   * @throws ValidationErrorException If the values are not right.
   */
Convert a set of values to an object that represents the order to the models
to return.

@param values     to extract how the query has to be sorted. If has to be
formed by the name by the key with a prefix than can be
+ or {-} to order in ascending or descending. If
you set the key without prefix is order in ascending.
@param codePrefix prefix to append to the error code.
@param checkKey   function to validate that the key is possible. It receive
the fields and return the key to sort the field or
null if the value is not valid. If it is
null it used the current key.

@return the object that can be used to sort a query.

@throws ValidationErrorException If the values are not right.
Convert a set of values to an object that represents the order to the models to return . @param values to extract how the query has to be sorted . If has to be formed by the name by the key with a prefix than can be + or { - } to order in ascending or descending . If you set the key without prefix is order in ascending . @param codePrefix prefix to append to the error code . @param checkKey function to validate that the key is possible . It receive the fields and return the key to sort the field or null if the value is not valid . If it is null it used the current key . @return the object that can be used to sort a query . @throws ValidationErrorException If the values are not right .
public static JsonObject queryParamToSort(final Iterable<String> values, final String codePrefix,
      final Function<String, String> checkKey) throws ValidationErrorException {
    if (values == null) {
      return null;
    } else {
      final var iter = values.iterator();
      if (!iter.hasNext()) {
        return null;
      } else {
        var sort = new JsonObject();
        for (var i = 0; iter.hasNext(); i++) {
          var value = iter.next();
          if (value == null) {
            throw new ValidationErrorException(codePrefix + "[" + i + "]", "An order item can not be 'null'.");
          } else {
            value = value.trim();
            var order = 1;
            if (value.startsWith("+")) {
              value = value.substring(1);
            } else if (value.startsWith("-")) {
              order = -1;
              value = value.substring(1);
            }
            if (value.length() == 0) {
              throw new ValidationErrorException(codePrefix + "[" + i + "]",
                  "You must to define a field in '" + value + "'.");
            } else {
              var key = value;
              if (checkKey != null) {
                key = checkKey.apply(value);
                if (key == null) {
                  throw new ValidationErrorException(codePrefix + "[" + i + "]",
                      "The field '" + value + "' is not valid.");
                }
              }
              if (sort.containsKey(key)) {
                throw new ValidationErrorException(codePrefix + "[" + i + "]",
                    "The '" + value + "' that represents the fields '" + key + "' is already defined.");
              } else {
                sort = sort.put(key, order);
              }
            }
          }
        }
        return sort;
      }
    }
  }
public static JsonObject queryParamToSort ( final Iterable < String > values , final String codePrefix , final Function < String , String > checkKey ) throws ValidationErrorException { if ( values == null ) { return null ; } else { final var iter = values . iterator ( ) ; if ( ! iter . hasNext ( ) ) { return null ; } else { var sort = new JsonObject ( ) ; for ( var i = 0 ; iter . hasNext ( ) ; i ++ ) { var value = iter . next ( ) ; if ( value == null ) { throw new ValidationErrorException ( codePrefix + "[" + i + "]" , "An order item can not be 'null'." ) ; } else { value = value . trim ( ) ; var order = 1 ; if ( value . startsWith ( "+" ) ) { value = value . substring ( 1 ) ; } else if ( value . startsWith ( "-" ) ) { order = - 1 ; value = value . substring ( 1 ) ; } if ( value . length ( ) == 0 ) { throw new ValidationErrorException ( codePrefix + "[" + i + "]" , "You must to define a field in '" + value + "'." ) ; } else { var key = value ; if ( checkKey != null ) { key = checkKey . apply ( value ) ; if ( key == null ) { throw new ValidationErrorException ( codePrefix + "[" + i + "]" , "The field '" + value + "' is not valid." ) ; } } if ( sort . containsKey ( key ) ) { throw new ValidationErrorException ( codePrefix + "[" + i + "]" , "The '" + value + "' that represents the fields '" + key + "' is already defined." ) ; } else { sort = sort . put ( key , order ) ; } } } } return sort ; } } }
Convert a set of values to an object that represents the order to the models
 to return.
Convert a set of values to an object that represents the order to the models to return .