Filters functions by their quality factors. @param funcs list of functions @param conn HTTP connection
(final List<RestXqFunction> funcs, final HTTPConnection conn)
| 257 | * @param conn HTTP connection |
| 258 | */ |
| 259 | private static void bestQf(final List<RestXqFunction> funcs, final HTTPConnection conn) { |
| 260 | // find the highest matching quality factors |
| 261 | final ArrayList<MediaType> accepts = conn.accepts(); |
| 262 | double cQf = 0, sQf = 0; |
| 263 | for(final RestXqFunction func : funcs) { |
| 264 | for(final MediaType accept : accepts) { |
| 265 | if(func.produces.isEmpty()) { |
| 266 | cQf = Math.max(cQf, qf(accept, "q")); |
| 267 | sQf = 1; |
| 268 | } else { |
| 269 | for(final MediaType produce : func.produces) { |
| 270 | if(produce.matches(accept)) { |
| 271 | cQf = Math.max(cQf, qf(accept, "q")); |
| 272 | sQf = Math.max(sQf, qf(produce, "qs")); |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | bestQf(funcs, accepts, cQf, -1); |
| 279 | if(funcs.size() > 1) bestQf(funcs, accepts, cQf, sQf); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Filters functions by their quality factors. |