<commit_before>package edu.illinois.strollsafe.util.timer;

/**
 * A Timed Thread that runs the specified runnable over and over until the specified amount of time
 * has elapsed or the thread is stopped.
 *
 * @author <NAME>
 */
public class TimedThread {

    private final Runnable runnable;
    private final Thread thread;
    private volatile boolean isRunning = false;

    /**
     * Creates a new Timed Thread
     * @param runnable the runnable to execute over and over until the time has elapsed
     * @param millis the duration of the timed thread
     * @param waitMillis the time the thread should wait between executing the runnable
     */
    public TimedThread(Runnable runnable, long millis, long waitMillis) {
        this.runnable = createTimedRunnable(runnable, millis, waitMillis);
        thread = new Thread(runnable);
    }

    /**
     * Starts the timed thread
     */
    public void start() {
        thread.start();
        isRunning = true;
    }

    /**
     * Stops the thread
     */
    public void stop() {
        isRunning = false;
    }

    /**
     * Unsafely stops the thread
     */
    public void forciblyStop() {
        isRunning = false;
        thread.interrupt();
    }

    /**
     * @return true if the thread is running
     */
    public boolean isRunning() {
        return isRunning;
    }

    private Runnable createTimedRunnable(final Runnable runnable, final long millis, final long waitMillis) {
        return new Runnable() {
            @Override
            public void run() {
                long startTime = System.nanoTime();
                while((System.nanoTime() - startTime) > (millis * 1000000L))
                {
                    if(!isRunning)
                        return;

                    runnable.run();
                    try {
                        Thread.sleep(waitMillis);
                    } catch (InterruptedException e) {
                        // do nothing since forciblyStop could cause this
                    }
                }
                isRunning = false;
            }
        };
    }
}
<commit_msg>made TimedThread take a timer instead of milli duration<commit_after>package edu.illinois.strollsafe.util.timer;

/**
 * A Timed Thread that runs the specified runnable over and over until the specified amount of time
 * has elapsed or the thread is stopped.
 *
 * @author <NAME>
 */
public class TimedThread {

    private final Runnable runnable;
    private final Thread thread;
    private volatile boolean isRunning = false;

    /**
     * Creates a new Timed Thread
     * @param runnable the runnable to execute over and over until the time has elapsed
     * @param timer a Timer that holds the duration of the timed thread
     * @param waitMillis the time the thread should wait between executing the runnable
     */
    public TimedThread(Runnable runnable, Timer timer, long waitMillis) {
        this.runnable = createTimedRunnable(runnable, timer, waitMillis);
        thread = new Thread(runnable);
    }

    /**
     * Starts the timed thread
     */
    public void start() {
        thread.start();
        isRunning = true;
    }

    /**
     * Stops the thread
     */
    public void stop() {
        isRunning = false;
    }

    /**
     * Unsafely stops the thread
     */
    public void forciblyStop() {
        isRunning = false;
        thread.interrupt();
    }

    /**
     * @return true if the thread is running
     */
    public boolean isRunning() {
        return isRunning;
    }

    private Runnable createTimedRunnable(final Runnable runnable, final Timer timer, final long waitMillis) {
        return new Runnable() {
            @Override
            public void run() {
                timer.reset();
                timer.start();
                while(!timer.hasElapsed())
                {
                    if(!isRunning)
                        return;

                    runnable.run();
                    try {
                        Thread.sleep(waitMillis);
                    } catch (InterruptedException e) {
                        // do nothing since forciblyStop could cause this
                    }
                }
                isRunning = false;
            }
        };
    }
}

{'fraction_non_alphanumeric': 0.07821620359561056, 'fraction_numerical': 0.001634368433341116, 'mean_word_length': 1.6658369632856254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3835977', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1077, 'n_words': 366}