AcceptHeader { public Representation resolve(Representation... representations) { checkArgument(representations != null && representations.length > 0); int maxIndex = 0; double maxQ = 0.0; for (int i = 0; i < representations.length; i++) { double q = 0.0; MediaType type = registry.normalize(representations[i].getType()); for (MediaRange range : ranges) { q = Math.max(q, range.match(type, registry)); } if (q > maxQ) { maxIndex = i; maxQ = q; } } return representations[maxIndex]; } AcceptHeader(String accept); Representation resolve(Representation... representations);  }
@Test public void testSpecificTypePlusGenericRange() { AcceptHeader ah = new AcceptHeader("application/json, **; q=0.5"); selected = ah.resolve(html, json); assertEquals(html, selected); ah = new AcceptHeader("application/json, */*; q=0.5"); selected = ah.resolve(html, json); assertEquals(json, selected); }