<commit_before>/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bmd.jrt.android.runner;

import android.os.Handler;
import android.os.Looper;

import com.bmd.jrt.runner.Execution;
import com.bmd.jrt.runner.Runner;
import com.bmd.jrt.runner.Runners;

import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

/**
 * Implementation of a runner employing the Android {@link android.os.Looper} queue to execute
 * the routine invocations.
 * <p/>
 * Created by davide on 9/28/14.
 */
class LooperRunner implements Runner {

    private final Handler mHandler;

    private final Runner mQueuedRunner;

    private final Thread mThread;

    /**
     * Constructor.
     *
     * @param looper the looper to employ.
     * @throws NullPointerException if the specified looper is null.
     */
    LooperRunner(@Nonnull final Looper looper) {

        mThread = looper.getThread();
        mHandler = new Handler(looper);
        mQueuedRunner = Runners.queuedRunner();
    }

    @Override
    public void run(@Nonnull final Execution execution, final long delay,
            @Nonnull final TimeUnit timeUnit) {

        if (Thread.currentThread().equals(mThread)) {

            mQueuedRunner.run(execution, delay, timeUnit);

        } else {

            if (delay > 0) {

                mHandler.postDelayed(execution, timeUnit.toMillis(delay));

            } else {

                mHandler.post(execution);
            }
        }
    }
}<commit_msg>Fixed looper runner<commit_after>/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bmd.jrt.android.runner;

import android.os.Handler;
import android.os.Looper;

import com.bmd.jrt.runner.Execution;
import com.bmd.jrt.runner.Runner;
import com.bmd.jrt.runner.Runners;

import java.util.concurrent.TimeUnit;

import javax.annotation.Nonnull;

/**
 * Implementation of a runner employing the Android {@link android.os.Looper} queue to execute
 * the routine invocations.
 * <p/>
 * Created by davide on 9/28/14.
 */
class LooperRunner implements Runner {

    private final Handler mHandler;

    private final Runner mQueuedRunner;

    private final Thread mThread;

    /**
     * Constructor.
     *
     * @param looper the looper to employ.
     * @throws NullPointerException if the specified looper is null.
     */
    LooperRunner(@Nonnull final Looper looper) {

        mThread = looper.getThread();
        mHandler = new Handler(looper);
        mQueuedRunner = Runners.queuedRunner();
    }

    @Override
    public void run(@Nonnull final Execution execution, final long delay,
            @Nonnull final TimeUnit timeUnit) {

        if (delay > 0) {

            mHandler.postDelayed(execution, timeUnit.toMillis(delay));

        } else if (Thread.currentThread().equals(mThread)) {

            mQueuedRunner.run(execution, delay, timeUnit);

        } else {

            mHandler.post(execution);
        }
    }
}
{'fraction_non_alphanumeric': 0.09120851279452749, 'fraction_numerical': 0.005067139599695972, 'mean_word_length': 2.908910891089109, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5629714', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1086, 'n_words': 372}