test_class.file: rawhttp-cli/src/test/java/rawhttp/cli/util/MediaTypeUtilTest.java
test_class.identifier: MediaTypeUtilTest
test_case.body: @SuppressWarnings("unchecked")
      @Test
      public void canSplitupAcceptHeadersIntoPreferredMediaTypes() {
          List[] examples = new List[]{
                  emptyList(), emptyList(),
                  singletonList(""), emptyList(),
                  singletonList("*/*"), singletonList("*/*"),
                  asList("xml", "json"), asList("xml", "json"),
                  singletonList("json; q=0.4, xml"), asList("xml", "json"),
                  singletonList("json; q=0.4, xml; q=0.5"), asList("xml", "json"),
                  singletonList("json; q=0.8, xml; q=0.1"), asList("json", "xml"),
                  singletonList("json; q=0.4;x=1, xml;a=20;q=0.5"), asList("xml", "json"),
                  singletonList("json; q=0.8, xml; q=0.1"), asList("json", "xml"),
                  asList("text/plain; q=0.5, text/html",
                          "text/x-dvi; q=0.8, text/x-c"), asList("text/html", "text/x-c", "text/x-dvi", "text/plain"),
          };
  
          for (int i = 0; i < examples.length; i += 2) {
              List<String> accept = examples[i];
              List<String> expectedSortedAccepts = examples[i + 1];
              List<String> result = MediaTypeUtil.getSortedAcceptableMediaTypes(accept);
              assertEquals("Example index: " + (i / 2), expectedSortedAccepts, result);
          }
      }
test_case.class_method_signature: MediaTypeUtilTest.canSplitupAcceptHeadersIntoPreferredMediaTypes()
test_case.full_signature: @SuppressWarnings("unchecked") @Test public void canSplitupAcceptHeadersIntoPreferredMediaTypes()
test_case.identifier: canSplitupAcceptHeadersIntoPreferredMediaTypes
test_case.invocations: emptyList emptyList singletonList emptyList singletonList singletonList asList asList singletonList asList singletonList asList singletonList asList singletonList asList singletonList asList asList asList getSortedAcceptableMediaTypes assertEquals
test_case.modifiers: @SuppressWarnings("unchecked") @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void canSplitupAcceptHeadersIntoPreferredMediaTypes()
focal_class.file: rawhttp-cli/src/main/java/rawhttp/cli/util/MediaTypeUtil.java
focal_class.identifier: MediaTypeUtil
focal_class.class_method_signature: MediaTypeUtil.getSortedAcceptableMediaTypes(List<String> accept)
focal_class.full_signature: public static List<String> getSortedAcceptableMediaTypes(List<String> accept)
focal_class.identifier: getSortedAcceptableMediaTypes
focal_class.modifiers: public static
focal_class.parameters: (List<String> accept)
focal_class.return: List<String>
focal_class.signature: List<String> getSortedAcceptableMediaTypes(List<String> accept)
focal_method.body: public static List<String> getSortedAcceptableMediaTypes(List<String> accept) {
          List<Item> result = new ArrayList<>(accept.size() + 1);
          for (String acceptItem : accept) {
              String[] subItems = acceptItem.split(",");
  
              for (String subItem : subItems) {
                  String[] itemPlusParams = subItem.split(";");
                  String item = itemPlusParams[0].trim();
                  if (item.isEmpty()) continue;
  
                  float weight = 1.0f;
  
                  // use the 'q' parameter if possible to set the weight
                  for (int i = 1; i < itemPlusParams.length; i++) {
                      String[] param = itemPlusParams[i].split("=", 2);
                      String paramName = param[0].trim();
                      if (param.length == 2 && paramName.equalsIgnoreCase("q")) {
                          try {
                              weight = Float.parseFloat(param[1].trim());
                          } catch (NumberFormatException e) {
                              // ignore
                          }
                          break; // 'q' param found, break out
                      }
                  }
                  result.add(new Item(item, weight));
              }
          }
          return result.stream().sorted().map(i -> i.value).collect(Collectors.toList());
      }
focal_method.class_method_signature: MediaTypeUtil.getSortedAcceptableMediaTypes(List<String> accept)
focal_method.full_signature: public static List<String> getSortedAcceptableMediaTypes(List<String> accept)
focal_method.identifier: getSortedAcceptableMediaTypes
focal_method.invocations: size split split trim isEmpty split trim equalsIgnoreCase parseFloat trim add collect map sorted stream toList
focal_method.modifiers: public static
focal_method.parameters: (List<String> accept)
focal_method.return: List<String>
focal_method.signature: List<String> getSortedAcceptableMediaTypes(List<String> accept)