<commit_before>package de.learnlib.alex.core.learner;

import de.learnlib.alex.core.entities.LearnerConfiguration;
import de.learnlib.alex.core.entities.LearnerResult;
import de.learnlib.alex.core.entities.LearnerResumeConfiguration;
import de.learnlib.alex.core.entities.Project;
import de.learnlib.alex.core.entities.Symbol;
import de.learnlib.alex.core.entities.learnlibproxies.eqproxies.SampleEQOracleProxy;
import de.learnlib.alex.core.learner.connectors.ConnectorContextHandler;
import de.learnlib.alex.core.learner.connectors.ConnectorContextHandlerFactory;
import de.learnlib.alex.core.learner.connectors.ConnectorManager;
import de.learnlib.alex.exceptions.LearnerException;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * Basic class to control and monitor a learn process.
 * This class is a high level abstraction of the LearnLib.
 */
public class Learner {

    /** Factory to create a new ContextHandler. */
    private ConnectorContextHandlerFactory contextHandlerFactory;

    /** The current ContextHandler. */
    private ConnectorContextHandler contextHandler;

    /** Factory to create the {@link LearnerThread LearnerThreads}. */
    private LearnerThreadFactory learnThreadFactory;

    /** The current learning thread. Could be null. */
    private LearnerThread learnThread;

    /**
     * Constructor which only set the thread factory.
     * This constructor creates a new ConnectorContextHandlerFactory for internal use.
     *
     * @param threadFactory
     *         The thread factory to use.
     */
    public Learner(LearnerThreadFactory threadFactory) {
        this(threadFactory, new ConnectorContextHandlerFactory());
    }

    /**
     * Constructor that initialises only the LearnerThreadFactory.
     *
     * @param learnThreadFactory
     *         The thread factory to use.
     * @param contextHandlerFactory
     *         The factory that will be used to create new context handler.
     */
    public Learner(LearnerThreadFactory learnThreadFactory, ConnectorContextHandlerFactory contextHandlerFactory) {
        this.learnThreadFactory = learnThreadFactory;
        this.contextHandlerFactory = contextHandlerFactory;
    }

    /**
     * Start a learning process by activating a LearningThread.
     *
     * @param project
     *         The project the learning process runs in.
     * @param configuration
     *         The configuration to use for the learning process.
     * @throws IllegalArgumentException
     *         If the configuration was invalid.
     * @throws IllegalStateException
     *         If a learning process is already active.
     */
    public void start(Project project, LearnerConfiguration configuration)
            throws IllegalArgumentException, IllegalStateException {
        if (isActive()) {
            throw new IllegalStateException("You can only start the learning if no other learning is active");
        }

        // TODO: make it nicer than this instanceof stuff, because you have to somehow tell the eq oracle that the
        //       learner started and not resumed
        if (configuration.getEqOracle() instanceof SampleEQOracleProxy) {
            SampleEQOracleProxy oracle = (SampleEQOracleProxy) configuration.getEqOracle();
            if (!oracle.getCounterExamples().isEmpty()) {
                throw new IllegalStateException("You cannot start with predefined counterexamples");
            }
        } else {
            configuration.checkConfiguration(); // throws IllegalArgumentException if something is wrong
        }

        contextHandler = contextHandlerFactory.createContext(project);
        learnThread = learnThreadFactory.createThread(contextHandler, project, configuration);
        Thread thread = Executors.defaultThreadFactory().newThread(learnThread);
        thread.start();
    }<commit_msg>fixed wrong exception being thrown #lastCommit<commit_after>package de.learnlib.alex.core.learner;

import de.learnlib.alex.core.entities.LearnerConfiguration;
import de.learnlib.alex.core.entities.LearnerResult;
import de.learnlib.alex.core.entities.LearnerResumeConfiguration;
import de.learnlib.alex.core.entities.Project;
import de.learnlib.alex.core.entities.Symbol;
import de.learnlib.alex.core.entities.learnlibproxies.eqproxies.SampleEQOracleProxy;
import de.learnlib.alex.core.learner.connectors.ConnectorContextHandler;
import de.learnlib.alex.core.learner.connectors.ConnectorContextHandlerFactory;
import de.learnlib.alex.core.learner.connectors.ConnectorManager;
import de.learnlib.alex.exceptions.LearnerException;

import java.util.List;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * Basic class to control and monitor a learn process.
 * This class is a high level abstraction of the LearnLib.
 */
public class Learner {

    /** Factory to create a new ContextHandler. */
    private ConnectorContextHandlerFactory contextHandlerFactory;

    /** The current ContextHandler. */
    private ConnectorContextHandler contextHandler;

    /** Factory to create the {@link LearnerThread LearnerThreads}. */
    private LearnerThreadFactory learnThreadFactory;

    /** The current learning thread. Could be null. */
    private LearnerThread learnThread;

    /**
     * Constructor which only set the thread factory.
     * This constructor creates a new ConnectorContextHandlerFactory for internal use.
     *
     * @param threadFactory
     *         The thread factory to use.
     */
    public Learner(LearnerThreadFactory threadFactory) {
        this(threadFactory, new ConnectorContextHandlerFactory());
    }

    /**
     * Constructor that initialises only the LearnerThreadFactory.
     *
     * @param learnThreadFactory
     *         The thread factory to use.
     * @param contextHandlerFactory
     *         The factory that will be used to create new context handler.
     */
    public Learner(LearnerThreadFactory learnThreadFactory, ConnectorContextHandlerFactory contextHandlerFactory) {
        this.learnThreadFactory = learnThreadFactory;
        this.contextHandlerFactory = contextHandlerFactory;
    }

    /**
     * Start a learning process by activating a LearningThread.
     *
     * @param project
     *         The project the learning process runs in.
     * @param configuration
     *         The configuration to use for the learning process.
     * @throws IllegalArgumentException
     *         If the configuration was invalid.
     * @throws IllegalStateException
     *         If a learning process is already active.
     */
    public void start(Project project, LearnerConfiguration configuration)
            throws IllegalArgumentException, IllegalStateException {
        if (isActive()) {
            throw new IllegalStateException("You can only start the learning if no other learning is active");
        }

        // TODO: make it nicer than this instanceof stuff, because you have to somehow tell the eq oracle that the
        //       learner started and not resumed
        if (configuration.getEqOracle() instanceof SampleEQOracleProxy) {
            SampleEQOracleProxy oracle = (SampleEQOracleProxy) configuration.getEqOracle();
            if (!oracle.getCounterExamples().isEmpty()) {
                throw new IllegalArgumentException("You cannot start with predefined counterexamples");
            }
        } else {
            configuration.checkConfiguration(); // throws IllegalArgumentException if something is wrong
        }

        contextHandler = contextHandlerFactory.createContext(project);
        learnThread = learnThreadFactory.createThread(contextHandler, project, configuration);
        Thread thread = Executors.defaultThreadFactory().newThread(learnThread);
        thread.start();
    }
{'fraction_non_alphanumeric': 0.07292464878671776, 'fraction_numerical': 0.0, 'mean_word_length': 3.232972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5934831', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1872, 'n_words': 561}