MediaTypeSet extends AbstractSet<MediaType> { @Nullable public MediaType matchHeaders(Iterable<? extends CharSequence> acceptHeaders) { requireNonNull(acceptHeaders, "acceptHeaders"); final List<MediaType> ranges = new ArrayList<>(4); for (CharSequence acceptHeader : acceptHeaders) { addRanges(ranges, acceptHeader); } return match(ranges); } private  MediaTypeSet(Iterable<MediaType> mediaTypes); static MediaTypeSet of(MediaType... mediaTypes); static MediaTypeSet of(Iterable<MediaType> mediaTypes); @Override boolean contains(Object o); @Override Iterator<MediaType> iterator(); @Override int size(); @Nullable MediaType matchHeaders(Iterable<? extends CharSequence> acceptHeaders); @Nullable MediaType matchHeaders(CharSequence... acceptHeaders); @Nullable MediaType match(MediaType range); @Nullable MediaType match(MediaType first, MediaType... rest); @Nullable MediaType match(Iterable<MediaType> ranges);  }
@Test void matchHeaders() { final MediaTypeSet set = MediaTypeSet.of(HTML_UTF_8, PLAIN_TEXT_UTF_8); assertThat(set.matchHeaders()).isNull(); assertThat(set.matchHeaders("")).isNull(); assertThat(set.matchHeaders(ImmutableList.of())).isNull(); assertThat(set.matchHeaders("text/html; q=0.5, text/plain")).isEqualTo(PLAIN_TEXT_UTF_8); assertThat(set.matchHeaders(ImmutableList.of("text/html, text/plain; q=0.5"))) .isEqualTo(HTML_UTF_8); assertThat(set.matchHeaders("audio*")).isEqualTo(HTML_UTF_8); assertThat(set.matchHeaders("video/webm")).isNull(); }