class DefaultWebApplicationRequestMapper implements WebApplicationRequestMapper {

    @Override
    public Set<String> addServletMapping(String servletName, String... urlPatterns) {
        // Servlet:JAVADOC:696.3 - if urlPatterns is null or empty throw IllegalArgumentException
        if (isEmpty(urlPatterns)) {
            throw new IllegalArgumentException("Mappings for " + servletName + " cannot be empty");
        }

        // Servlet:JAVADOC:696.1 - If any of the specified URL patterns are already mapped to a different Servlet, no updates will be performed.
        Set<String> mappedToOtherServlet = stream(urlPatterns)
            .filter(servletMappings::containsKey)
            .filter(urlPattern -> !servletMappings.get(urlPattern).equals(servletName))
            .collect(toSet());

        if (!mappedToOtherServlet.isEmpty()) {
            return mappedToOtherServlet;
        }

        for (String urlPattern : urlPatterns) {
            servletMappings.put(urlPattern, servletName);
        }

        return emptySet();
    }

}