<commit_before>package com.tagmycode.plugin.operation;

import com.tagmycode.plugin.AbstractTaskFactory;
import com.tagmycode.plugin.gui.IOnErrorCallback;
import com.tagmycode.sdk.exception.TagMyCodeException;

public abstract class TagMyCodeAsynchronousOperation<T> {
    protected IOnErrorCallback onErrorCallback;
    private Thread thread;

    public TagMyCodeAsynchronousOperation(IOnErrorCallback onErrorCallback) {
        this.onErrorCallback = onErrorCallback;
    }

    public final void run() {
        Runnable runnable = createRunnable();
        thread = new Thread(runnable);
        thread.start();
    }

    public void stop() {
        if (thread != null) {
            thread.interrupt();
        }
    }

    public void runWithTask(AbstractTaskFactory task, String title) {
        task.create(createRunnable(), title);
    }

    private Runnable createRunnable() {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    beforePerformOperation();
                    final T result = performOperation();
                    onComplete();
                    onSuccess(result);
                } catch (final InterruptedException e) {
                    onInterrupted();
                    e.printStackTrace();
                } catch (final Throwable e) {
                    onComplete();
                    onFailure(e);
                    e.printStackTrace();
                }
            }
        };
    }

    protected void onInterrupted() {
        onComplete();
    }

    protected void beforePerformOperation() {

    }

    protected abstract T performOperation() throws Exception;

    protected void onComplete() {<commit_msg>reverted TagMyCodeAsynchronousOperation<commit_after>package com.tagmycode.plugin.operation;

import com.tagmycode.plugin.AbstractTaskFactory;
import com.tagmycode.plugin.gui.IOnErrorCallback;
import com.tagmycode.sdk.exception.TagMyCodeException;

import javax.swing.*;

public abstract class TagMyCodeAsynchronousOperation<T> {
    protected IOnErrorCallback onErrorCallback;
    private Thread thread;

    public TagMyCodeAsynchronousOperation(IOnErrorCallback onErrorCallback) {
        this.onErrorCallback = onErrorCallback;
    }

    public final void run() {
        Runnable runnable = createRunnable();
        thread = new Thread(runnable);
        thread.start();
    }

    public void stop() {
        if (thread != null) {
            thread.interrupt();
        }
    }

    public void runWithTask(AbstractTaskFactory task, String title) {
        task.create(createRunnable(), title);
    }

    private Runnable createRunnable() {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            beforePerformOperation();
                        }
                    });
                    final T result = performOperation();
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            onComplete();
                            onSuccess(result);
                        }
                    });
                } catch (final InterruptedException e) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            onInterrupted();
                            e.printStackTrace();
                        }
                    });
                } catch (final Throwable e) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            onComplete();
                            onFailure(e);
                            e.printStackTrace();
                        }
                    });
                }
            }
        };
    }

    protected void onInterrupted() {
        onComplete();
    }

    protected void beforePerformOperation() {

    }

    protected abstract T performOperation() throws Exception;

    protected void onComplete() {
{'fraction_non_alphanumeric': 0.08130465610966675, 'fraction_numerical': 0.0, 'mean_word_length': 1.5326152004787552, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2147203', 'n_tokens_mistral': 1028, 'n_tokens_neox': 959, 'n_words': 215}