<commit_before>package com.icegreen.greenmail.webapp;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.icegreen.greenmail.Managers;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.user.UserException;
import com.icegreen.greenmail.util.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Automatically starts and stops GreenMail server upon deployment/undeployment.
 *
 * @author mm
 */
public class GreenMailListener implements ServletContextListener {
    private Logger log = LoggerFactory.getLogger(GreenMailListener.class);
    private Managers managers;
    private List<Service> services;
    private Configuration configuration;

    public void contextInitialized(final ServletContextEvent sce) {
        log.info("Initializing GreenMail");

        managers = new Managers();
        ServletContext ctx = sce.getServletContext();
        configuration = ConfigurationFactory.create(extractParameters(ctx));
        services = ServiceFactory.create(configuration, managers);

        for (Configuration.User user : configuration.getUsers()) {
            GreenMailUser greenMailUser = managers.getUserManager().getUser(user.email);
            if (null == greenMailUser) {
                try {
                    greenMailUser = managers.getUserManager().createUser(
                            user.email, user.login, user.password);
                    greenMailUser.setPassword(<PASSWORD>);
                } catch (UserException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        for (Service s : services) {
            log.info("Starting GreenMail service: " + s.toString());
            s.startService(null);
        }
    }

    public void contextDestroyed(final ServletContextEvent sce) {
        log.info("Destroying GreenMail WebApp");
        for (Service s : services) {
            log.info("Stopping GreenMail service: " + s.toString());
            s.stopService(null);
        }
    }

    private Map extractParameters(ServletContext pServletContext) {
        Enumeration names = pServletContext.getInitParameterNames();
        Map<String, String> parameterMap = new HashMap<String, String>();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            parameterMap.put(name, pServletContext.getInitParameter(name));
        }
        return parameterMap;
    }
<commit_msg>Generify and other beautification<commit_after>package com.icegreen.greenmail.webapp;

import com.icegreen.greenmail.Managers;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.user.UserException;
import com.icegreen.greenmail.util.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Automatically starts and stops GreenMail server upon deployment/undeployment.
 *
 * @author mm
 */
public class GreenMailListener implements ServletContextListener {
    private Logger log = LoggerFactory.getLogger(GreenMailListener.class);
    private Managers managers;
    private List<Service> services;
    private Configuration configuration;

    public void contextInitialized(final ServletContextEvent sce) {
        log.info("Initializing GreenMail");

        managers = new Managers();
        ServletContext ctx = sce.getServletContext();
        configuration = ConfigurationFactory.create(extractParameters(ctx));
        services = ServiceFactory.create(configuration, managers);

        for (Configuration.User user : configuration.getUsers()) {
            GreenMailUser greenMailUser = managers.getUserManager().getUser(user.email);
            if (null == greenMailUser) {
                try {
                    greenMailUser = managers.getUserManager().createUser(
                            user.email, user.login, user.password);
                    greenMailUser.setPassword(<PASSWORD>);
                } catch (UserException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        for (Service s : services) {
            log.info("Starting GreenMail service: " + s.toString());
            s.startService(null);
        }
    }

    public void contextDestroyed(final ServletContextEvent sce) {
        log.info("Destroying GreenMail WebApp");
        for (Service s : services) {
            log.info("Stopping GreenMail service: " + s.toString());
            s.stopService(null);
        }
    }

    private Map<String, String> extractParameters(ServletContext pServletContext) {
        Enumeration names = pServletContext.getInitParameterNames();
        Map<String, String> parameterMap = new HashMap<String, String>();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            parameterMap.put(name, pServletContext.getInitParameter(name));
        }
        return parameterMap;
    }

{'fraction_non_alphanumeric': 0.09485500467726847, 'fraction_numerical': 0.0007483629560336763, 'mean_word_length': 2.851585014409222, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, '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': '3144500', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1341, 'n_words': 296}