<commit_before>package com.wizzardo.servlet;

import com.wizzardo.http.ChainUrlMapping;
import com.wizzardo.http.Path;
import com.wizzardo.http.UrlMapping;
import com.wizzardo.tools.misc.UncheckedThrow;

import javax.servlet.*;
import javax.servlet.descriptor.JspConfigDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: wizzardo
 * Date: 31.10.14
 */
public class Context implements ServletContext {
    private static final int MAJOR_SERVLET_VERSION = 3;
    private static final int MINOR_SERVLET_VERSION = 0;

    protected String host;
    protected int port;
    protected String contextPath;
    protected File contextDir;
    protected UrlMapping<ServletHolder> servletsMapping = new UrlMapping<>();
    protected ChainUrlMapping<Filter> filtersMapping = new ChainUrlMapping<>();
    protected List<Servlet> servletsToDestroy = new ArrayList<>();
    protected List<Filter> filtersToDestroy = new ArrayList<>();
    protected List<ServletContextListener> contextListeners = new ArrayList<>();
    protected Map<String, Object> attributes = new ConcurrentHashMap<>();
    protected Map<String, String> initParams = new ConcurrentHashMap<>();
    protected Map<String, ServletHolder> servlets = new ConcurrentHashMap<>();
    protected boolean initialized = false;

    public Context(String host, int port, String contextPath) {
        this.host = host;
        this.port = port;
        this.contextPath = contextPath;
    }

    void setContextDir(File contextDir) {
        this.contextDir = contextDir;
    }

    public String getContextPath() {
        return contextPath;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public boolean isSecure() {
        return false;
    }

    public ChainUrlMapping<Filter> getFiltersMapping() {
        return filtersMapping;
    }

    public void addServletHolder(String path, ServletHolder servletHolder) {
        servletsMapping.append(path, servletHolder);
        servlets.put(servletHolder.name, servletHolder);
    }

    public ServletHolder getServletHolder(HttpRequest request, Path path) {
        return servletsMapping.get(request, path);
    }

    public String createAbsoluteUrl(String path) {
        StringBuilder sb = new StringBuilder();
        if (isSecure())
            sb.append("https://");
        else
            sb.append("http://");

        sb.append(host);
        if ((!isSecure() && port != 80) || (isSecure() && port != 443))
            sb.append(":").append(port);

        sb.append(path);
        return sb.toString();
    }

    protected void onInit() {
        ServletContextEvent event = new ServletContextEvent(this);
        for (ServletContextListener listener : contextListeners)
            listener.contextInitialized(event);
        initialized = true;
    }

    protected void addServletToDestroy(Servlet servlet) {
        servletsToDestroy.add(servlet);
    }

    protected void addFilterToDestroy(Filter filter) {
        filtersToDestroy.add(filter);
    }

    protected void onDestroy() {
        for (Servlet servlet : servletsToDestroy)
            servlet.destroy();

        for (Filter filter : filtersToDestroy)
            filter.destroy();

        ServletContextEvent event = new ServletContextEvent(this);
        for (int i = contextListeners.size() - 1; i >= 0; i--)
            contextListeners.get(i).contextDestroyed(event);
    }

    @Override
    public ServletContext getContext(String uripath) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public int getMajorVersion() {
        return MAJOR_SERVLET_VERSION;
    }

    @Override
    public int getMinorVersion() {
        return MINOR_SERVLET_VERSION;
    }

    @Override
    public int getEffectiveMajorVersion() {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public int getEffectiveMinorVersion() {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public String getMimeType(String file) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public Set<String> getResourcePaths(String path) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public URL getResource(String path) throws MalformedURLException {
        throw new UnsupportedOperationException("Not implemented yet.");
    }<commit_msg>add versions<commit_after>package com.wizzardo.servlet;

import com.wizzardo.http.ChainUrlMapping;
import com.wizzardo.http.Path;
import com.wizzardo.http.UrlMapping;
import com.wizzardo.tools.misc.UncheckedThrow;

import javax.servlet.*;
import javax.servlet.descriptor.JspConfigDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: wizzardo
 * Date: 31.10.14
 */
public class Context implements ServletContext {
    private static final int MAJOR_SERVLET_VERSION = 3;
    private static final int MINOR_SERVLET_VERSION = 0;

    protected String host;
    protected int port;
    protected String contextPath;
    protected File contextDir;
    protected UrlMapping<ServletHolder> servletsMapping = new UrlMapping<>();
    protected ChainUrlMapping<Filter> filtersMapping = new ChainUrlMapping<>();
    protected List<Servlet> servletsToDestroy = new ArrayList<>();
    protected List<Filter> filtersToDestroy = new ArrayList<>();
    protected List<ServletContextListener> contextListeners = new ArrayList<>();
    protected Map<String, Object> attributes = new ConcurrentHashMap<>();
    protected Map<String, String> initParams = new ConcurrentHashMap<>();
    protected Map<String, ServletHolder> servlets = new ConcurrentHashMap<>();
    protected boolean initialized = false;

    public Context(String host, int port, String contextPath) {
        this.host = host;
        this.port = port;
        this.contextPath = contextPath;
    }

    void setContextDir(File contextDir) {
        this.contextDir = contextDir;
    }

    public String getContextPath() {
        return contextPath;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public boolean isSecure() {
        return false;
    }

    public ChainUrlMapping<Filter> getFiltersMapping() {
        return filtersMapping;
    }

    public void addServletHolder(String path, ServletHolder servletHolder) {
        servletsMapping.append(path, servletHolder);
        servlets.put(servletHolder.name, servletHolder);
    }

    public ServletHolder getServletHolder(HttpRequest request, Path path) {
        return servletsMapping.get(request, path);
    }

    public String createAbsoluteUrl(String path) {
        StringBuilder sb = new StringBuilder();
        if (isSecure())
            sb.append("https://");
        else
            sb.append("http://");

        sb.append(host);
        if ((!isSecure() && port != 80) || (isSecure() && port != 443))
            sb.append(":").append(port);

        sb.append(path);
        return sb.toString();
    }

    protected void onInit() {
        ServletContextEvent event = new ServletContextEvent(this);
        for (ServletContextListener listener : contextListeners)
            listener.contextInitialized(event);
        initialized = true;
    }

    protected void addServletToDestroy(Servlet servlet) {
        servletsToDestroy.add(servlet);
    }

    protected void addFilterToDestroy(Filter filter) {
        filtersToDestroy.add(filter);
    }

    protected void onDestroy() {
        for (Servlet servlet : servletsToDestroy)
            servlet.destroy();

        for (Filter filter : filtersToDestroy)
            filter.destroy();

        ServletContextEvent event = new ServletContextEvent(this);
        for (int i = contextListeners.size() - 1; i >= 0; i--)
            contextListeners.get(i).contextDestroyed(event);
    }

    @Override
    public ServletContext getContext(String uripath) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public int getMajorVersion() {
        return MAJOR_SERVLET_VERSION;
    }

    @Override
    public int getMinorVersion() {
        return MINOR_SERVLET_VERSION;
    }

    @Override
    public int getEffectiveMajorVersion() {
        return getMajorVersion();
    }

    @Override
    public int getEffectiveMinorVersion() {
        return getMinorVersion();
    }

    @Override
    public String getMimeType(String file) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public Set<String> getResourcePaths(String path) {
        throw new UnsupportedOperationException("Not implemented yet.");
    }

    @Override
    public URL getResource(String path) throws MalformedURLException {
        throw new UnsupportedOperationException("Not implemented yet.");
    }
{'fraction_non_alphanumeric': 0.09513674576992658, 'fraction_numerical': 0.0031925082473129723, 'mean_word_length': 3.1075174825174825, 'pattern_counts': {'":': 2, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970908', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2447, 'n_words': 633}