public static Result accept(Map<String, ? extends Result> results) {
        Context context = Context.CONTEXT.get();
        if (context == null) {
            throw new IllegalStateException("Negotiation cannot be achieved outside of a request");
        }
        Collection<MediaType> accepted = context.request().mediaTypes();
        // accepted cannot be empty, if the header is missing text/* is added.
        for (MediaType media : accepted) {
            // Do we have a matching key.
            for (Map.Entry<String, ? extends Result> entry : results.entrySet()) {
                MediaType input = MediaType.parse(entry.getKey());
                if (input.is(media)) {
                    return entry.getValue().with(HeaderNames.VARY, HeaderNames.ACCEPT);
                }
            }
        }
        return Results.status(Status.NOT_ACCEPTABLE);
    }
public static Result accept ( Map < String , ? extends Result > results ) { Context context = Context . CONTEXT . get ( ) ; if ( context == null ) { throw new IllegalStateException ( "Negotiation cannot be achieved outside of a request" ) ; } Collection < MediaType > accepted = context . request ( ) . mediaTypes ( ) ; for ( MediaType media : accepted ) { for ( Map . Entry < String , ? extends Result > entry : results . entrySet ( ) ) { MediaType input = MediaType . parse ( entry . getKey ( ) ) ; if ( input . is ( media ) ) { return entry . getValue ( ) . with ( HeaderNames . VARY , HeaderNames . ACCEPT ) ; } } } return Results . status ( Status . NOT_ACCEPTABLE ) ; }
'Accept' based negotiation.
This method determines the result to send to the client based on the 'Accept' header of the request.
The returned result is enhanced with the 'Vary' header set to {@literal Accept}.
<p/>
This methods retrieves the accepted media type in their preference order and check,
one-by-one if the given results match one of them. So, it ensures we get the most acceptable result.

@param results the set of result structured as follows: mime-type -> result. The mime-type (keys) must be
valid mime type such as 'application/json' or 'text/html'.
@return the selected result, or a result with the status {@link org.wisdom.api.http.Status#NOT_ACCEPTABLE} if
none of the given results match the request.