/*
 * MIT license
 *
 * Copyright (c) 2012 Janick Reynders
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the Software
 * without restriction, including without limitation the rights to use, copy, modify,
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package be.janickreynders.bubblegum;

public class Matchers {

    public static RequestMatcher method(final String httpMethod) {
        return new RequestMatcher() {
            @Override
            public boolean matches(Request req) {
                return httpMethod.equalsIgnoreCase(req.method());
            }
        };
    }

    public static RequestMatcher header(final String headerName, final CharSequence value) {
        return new RequestMatcher() {
            @Override
            public boolean matches(Request req) {
                return req.header(headerName).contains(value);
            }
        };
    }

    public static RequestMatcher accept(CharSequence mimeType) {
        return header("Accept", mimeType);
    }

    public static RequestMatcher contentType(CharSequence contentType) {
        return header("Content-Type", contentType);
    }

    public static RequestMatcher all(final RequestMatcher... matchers) {
        return new RequestMatcher() {
            @Override
            public boolean matches(Request req) {
                for (RequestMatcher matcher : matchers) {
                    if (!matcher.matches(req)) return false;
                }
                return true;
            }
        };
    }

    public static RequestMatcher any(final RequestMatcher... matchers) {
        return new RequestMatcher() {
            @Override
            public boolean matches(Request req) {
                for (RequestMatcher matcher : matchers) {
                    if (matcher.matches(req)) return true;
                }
                return false;
            }
        };
    }

    public static RequestMatcher not(final RequestMatcher matcher) {
        return new RequestMatcher() {
            @Override
            public boolean matches(Request req) {
                return !matcher.matches(req);
            }
        };
    }
}

@@ -1805,16 +1805,22 @@
  accept(
+final 
 CharSequ
@@ -1855,34 +1855,254 @@
 urn 
-header(%22Accept%22, mimeType)
+new RequestMatcher() %7B%0A            @Override%0A            public boolean matches(Request req) %7B%0A                String accept = req.header(%22Accept%22);%0A                return accept.contains(mimeType) %7C%7C accept.equals(%22*/*%22);%0A            %7D%0A        %7D
 ;%0A  

fix Accept header */* match