@Test public void qualityFactor3() { String type = new AcceptHeader("text/xml;q=0.5, application/json;q=0.1, text/html;q=0.1").select("application/json", "text/xml"); Assert.assertNotNull(type); Assert.assertEquals(type, "text/xml"); }
public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; }
AcceptHeader { public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; } }
AcceptHeader { public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; } AcceptHeader(String ranges); }
AcceptHeader { public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; } AcceptHeader(String ranges); String select(Iterable<String> supported); String select(String... supported); @Override String toString(); }
AcceptHeader { public String select(Iterable<String> supported) { float bestQ = 0; String best = null; for (String s : supported) { Atom a = match(s); if (a!= null && a.q > bestQ) { bestQ = a.q; best = s; } } if (best==null) throw HttpResponses.error(HttpServletResponse.SC_NOT_ACCEPTABLE, "Requested MIME types '" + ranges + "' didn't match any of the available options "+supported); return best; } AcceptHeader(String ranges); String select(Iterable<String> supported); String select(String... supported); @Override String toString();  }