public static String buildURIFromPattern(String pattern, List<Parameter> parameters) {
      if (parameters != null) {
         // Browse parameters and choose between template or query one.
         for (Parameter parameter : parameters) {
            String wadlTemplate = "{" + parameter.getName() + "}";
            String swaggerTemplate = "/:" + parameter.getName();
            if (pattern.contains(wadlTemplate)) {
               // It's a template parameter.
               pattern = pattern.replace(wadlTemplate, encodePath(parameter.getValue()));
            } else if (pattern.contains(swaggerTemplate)) {
               // It's a template parameter.
               pattern = pattern.replace(":" + parameter.getName(), encodePath(parameter.getValue()));
            } else {
               // It's a query parameter, ensure we have started delimiting them.
               if (!pattern.contains("?")) {
                  pattern += "?";
               }
               if (pattern.contains("=")) {
                  pattern += "&";
               }
               pattern += parameter.getName() + "=" + encodeValue(parameter.getValue());
            }
         }
      }
      return pattern;
   }
@Test
   void testBuildURIFromPatternWithMapWithParamsArray() {
      // Prepare a bunch of parameters.
      Multimap<String, String> parameters = ArrayListMultimap.create();
      parameters.put("year", "2018");
      parameters.put("month", "05");
      parameters.put("status", "published");
      parameters.put("status", "proofred");
      parameters.put("page", "0");

      // Test with old wadl like template format.
      String pattern = "http://localhost:8080/blog/{year}/{month}";
      String uri = URIBuilder.buildURIFromPattern(pattern, parameters);
      assertTrue("http://localhost:8080/blog/2018/05?page=0&status=published&status=proofred".equals(uri)
            || "http://localhost:8080/blog/2018/05?status=published&status=proofred&page=0".equals(uri));

      // Test with new swagger like template format.
      pattern = "http://localhost:8080/blog/:year/:month";
      uri = URIBuilder.buildURIFromPattern(pattern, parameters);
      assertTrue("http://localhost:8080/blog/2018/05?page=0&status=published&status=proofred".equals(uri)
            || "http://localhost:8080/blog/2018/05?status=published&status=proofred&page=0".equals(uri));
   }