class VariantsHandler {

    public Variant handleVariants(ContainerRequest request, List<Variant> variants) {
        List<AcceptMediaType> acceptMediaTypes = createAcceptMediaTypeList(convertToString(request.getRequestHeader(ACCEPT)));
        List<AcceptLanguage> acceptLanguages = createAcceptedLanguageList(convertToString(request.getRequestHeader(ACCEPT_LANGUAGE)));
        List<AcceptToken> acceptCharset = createAcceptedCharsetList(convertToString(request.getRequestHeader(ACCEPT_CHARSET)));
        List<AcceptToken> acceptEncoding = createAcceptedEncodingList(convertToString(request.getRequestHeader(ACCEPT_ENCODING)));

        List<Variant> filteredVariants = new ArrayList<>(variants);

        filteredVariants = filterByMediaType(acceptMediaTypes, filteredVariants);
        filteredVariants = filterByLanguage(acceptLanguages, filteredVariants);
        filteredVariants = filterByCharset(acceptCharset, filteredVariants);
        filteredVariants = filterByEncoding(acceptEncoding, filteredVariants);

        return filteredVariants.isEmpty() ? null : filteredVariants.get(0);
    }

}