public static Variant selectVariant(ContainerRequest r, List<Variant> variants) {
    LinkedList<VariantHolder> vhs = getVariantHolderList(variants);

    Set<String> vary = new HashSet<String>();
    vhs = selectVariants(vhs, HttpHelper.getAccept(r), MEDIA_TYPE_DC, vary);
    vhs = selectVariants(vhs, HttpHelper.getAcceptLanguage(r), LANGUAGE_TAG_DC, vary);
    vhs = selectVariants(vhs, HttpHelper.getAcceptCharset(r), CHARSET_DC, vary);
    vhs = selectVariants(vhs, HttpHelper.getAcceptEncoding(r), ENCODING_DC, vary);

    if (vhs.isEmpty()) {
      return null;
    } else {
      StringBuilder varyHeader = new StringBuilder();
      for (String v : vary) {
        if (varyHeader.length() > 0) {
          varyHeader.append(',');
        }
        varyHeader.append(v);
      }
      r.getProperties().put(ContainerRequest.VARY_HEADER, varyHeader.toString());
      return vhs.iterator().next().v;
    }
  }