<commit_before>package org.lodder.subtools.multisubdownloader.framework;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.prefs.Preferences;

import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProvider;
import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProviderComparator;
import org.lodder.subtools.multisubdownloader.settings.model.Settings;
import org.lodder.subtools.sublibrary.Manager;
import org.lodder.subtools.sublibrary.logging.Logger;
import org.reflections.Reflections;

public class Bootstrapper {

  private final Container app;
  private final Settings settings;
  private final Preferences preferences;
  private final Manager manager;

  public Bootstrapper(Container app, Settings settings, Preferences preferences, Manager manager) {
    this.app = app;
    this.settings = settings;
    this.preferences = preferences;
    this.manager = manager;
  }

  public void initialize() {
    /* Bind Settings to IoC Container */
    this.app.bind("Settings", new Resolver() {
      @Override
      public Object resolve() {
        return settings;
      }
    });
    
    /* Bind Preferences to IoC Container */
    this.app.bind("Preferences", new Resolver() {
      @Override
      public Object resolve() {
        return preferences;
      }
    });
    
    /* Bind Manager to IoC Container */
    this.app.bind("Manager", new Resolver() {
      @Override
      public Object resolve() {
        return manager;
      }
    });

    // Collect ServiceProviders
    List<ServiceProvider> providers = this.getProviders();

    // Sort according to priority
    Collections.sort(providers, new ServiceProviderComparator());

    // Register ServiceProviders
    this.registerProviders(providers);
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public List<ServiceProvider> getProviders() {

    Reflections reflections = new Reflections("org.lodder.subtools.multisubdownloader");
    Set<Class<? extends ServiceProvider>> providerClasses = reflections.getSubTypesOf(ServiceProvider.class);

    List<ServiceProvider> providers = new ArrayList<>();

    // Intantieer alle serviceproviders
    for (Class serviceProviderClass : providerClasses) {
      ServiceProvider serviceProvider = null;

      try {
        Constructor constructor = serviceProviderClass.getConstructor();
        serviceProvider = (ServiceProvider) constructor.newInstance();
      } catch (Exception e) {
        Logger.instance.error(
          "ServiceProvider: '" + serviceProviderClass.getClass().getName() + "' failed to create instance.");
      }

      if (serviceProvider == null)
        continue;

      providers.add(serviceProvider);
    }
    return providers;
  }

  public void registerProviders(List<ServiceProvider> providers) {
    // Register serviceproviders
    for (ServiceProvider provider : providers) {
      provider.register(this.app);

      Logger.instance.debug("ServiceProvider: '" + provider.getClass().getName() + "' registered.");
    }
  }
}
<commit_msg>Convert Bootstrapper from old logger to new LOGGER slf4j<commit_after>package org.lodder.subtools.multisubdownloader.framework;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.prefs.Preferences;

import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProvider;
import org.lodder.subtools.multisubdownloader.framework.service.providers.ServiceProviderComparator;
import org.lodder.subtools.multisubdownloader.settings.model.Settings;
import org.lodder.subtools.sublibrary.Manager;
import org.reflections.Reflections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Bootstrapper {

  private static final Logger LOGGER = LoggerFactory.getLogger(Bootstrapper.class);

  private final Container app;
  private final Settings settings;
  private final Preferences preferences;
  private final Manager manager;

  public Bootstrapper(Container app, Settings settings, Preferences preferences, Manager manager) {
    this.app = app;
    this.settings = settings;
    this.preferences = preferences;
    this.manager = manager;
  }

  public void initialize() {
    /* Bind Settings to IoC Container */
    this.app.bind("Settings", new Resolver() {
      @Override
      public Object resolve() {
        return settings;
      }
    });

    /* Bind Preferences to IoC Container */
    this.app.bind("Preferences", new Resolver() {
      @Override
      public Object resolve() {
        return preferences;
      }
    });

    /* Bind Manager to IoC Container */
    this.app.bind("Manager", new Resolver() {
      @Override
      public Object resolve() {
        return manager;
      }
    });

    // Collect ServiceProviders
    List<ServiceProvider> providers = this.getProviders();

    // Sort according to priority
    Collections.sort(providers, new ServiceProviderComparator());

    // Register ServiceProviders
    this.registerProviders(providers);
  }

  @SuppressWarnings({"rawtypes", "unchecked"})
  public List<ServiceProvider> getProviders() {

    Reflections reflections = new Reflections("org.lodder.subtools.multisubdownloader");
    Set<Class<? extends ServiceProvider>> providerClasses =
        reflections.getSubTypesOf(ServiceProvider.class);

    List<ServiceProvider> providers = new ArrayList<>();

    // Intantieer alle serviceproviders
    for (Class serviceProviderClass : providerClasses) {
      ServiceProvider serviceProvider = null;

      try {
        Constructor constructor = serviceProviderClass.getConstructor();
        serviceProvider = (ServiceProvider) constructor.newInstance();
      } catch (Exception e) {
        LOGGER.error("ServiceProvider: '{}' failed to create instance.", serviceProviderClass
            .getClass().getName());
      }

      if (serviceProvider == null) continue;

      providers.add(serviceProvider);
    }
    return providers;
  }

  public void registerProviders(List<ServiceProvider> providers) {
    // Register serviceproviders
    for (ServiceProvider provider : providers) {
      provider.register(this.app);
      LOGGER.debug("ServiceProvider: '{}' registered.", provider.getClass().getName());
    }
  }
}

{'fraction_non_alphanumeric': 0.10165263486124103, 'fraction_numerical': 0.0004677268475210477, 'mean_word_length': 3.6451846488052135, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1379141', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1682, 'n_words': 392}