code: private void generatePermutationsQueryVariables(
        ArrayList<HashMap<String, String[]>> result, Set<String> keys,
        HashMap<String, String[]> queryVariables) {
      if (keys != null && !keys.isEmpty()) {
        Set<String> newKeys = new HashSet<>();
        Iterator<String> it = keys.iterator();
        String key = it.next();
        String[] value = queryVariables.get(key);
        if (result.isEmpty()) {
          HashMap<String, String[]> newItem;
          if (value == null || value.length == 0) {
            newItem = new HashMap<>();
            newItem.put(key, value);
            result.add(newItem);
          } else {
            for (int j = 0; j < value.length; j++) {
              newItem = new HashMap<>();
              newItem.put(key, new String[] { value[j] });
              result.add(newItem);
            }
          }
        } else {
          ArrayList<HashMap<String, String[]>> newResult = new ArrayList<>();
          for (int i = 0; i < result.size(); i++) {
            HashMap<String, String[]> newItem;
            if (value == null || value.length == 0) {
              newItem = (HashMap<String, String[]>) result.get(i).clone();
              newItem.put(key, value);
              newResult.add(newItem);
            } else {
              for (int j = 0; j < value.length; j++) {
                newItem = (HashMap<String, String[]>) result.get(i).clone();
                newItem.put(key, new String[] { value[j] });
                newResult.add(newItem);
              }
            }
          }
          result.clear();
          result.addAll(newResult);
        }
        while (it.hasNext()) {
          newKeys.add(it.next());
        }
        generatePermutationsQueryVariables(result, newKeys, queryVariables);
      }
    }
docs: Generate permutations query variables.
  
  @param result the result
  @param keys the keys
  @param queryVariables the query variables