<commit_before>//
//  HandlerDispatchQueue.java
//
//  Lunar Unity Mobile Console
//  https://github.com/SpaceMadness/lunar-unity-console
//
//  Copyright 2017 <NAME>, SpaceMadness.
//
//  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.apptentive.android.sdk.util.threading;

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

import static com.apptentive.android.sdk.debug.Assert.assertNotNull;

/**
 * {@link DispatchQueue} implementation using {@link Handler}
 */
class HandlerDispatchQueue extends DispatchQueue {
	private final Handler handler;
	private final HandlerThread handlerThread;

	/**
	 * Creates a private queue with specified <code>name</code>
	 */
	public HandlerDispatchQueue(String name) {
		handlerThread = new HandlerThread(name);
		handlerThread.start();
		handler = new Handler(handlerThread.getLooper());
	}

	/**
	 * Creates a queue with specified <code>looper</code>
	 */
	public HandlerDispatchQueue(Looper looper) {
		if (looper == null) {
			throw new NullPointerException("Looper is null");
		}
		handler = new Handler(looper);
		handlerThread = null; // non-private queue (no explicit thread)
	}

	@Override
	protected void dispatch(DispatchTask task, long delayMillis) {
		handler.post(task);
	}

	@Override
	public void stop() {
		assertNotNull(handlerThread, "Attempted to stop a non-private queue '%s'", handler.getLooper().getThread());
		if (handlerThread != null) {
			handler.removeCallbacks(null);
			handlerThread.quit();
		}
	}
}<commit_msg>Fixed scheduling delayed tasks on dispatch queue<commit_after>//
//  HandlerDispatchQueue.java
//
//  Lunar Unity Mobile Console
//  https://github.com/SpaceMadness/lunar-unity-console
//
//  Copyright 2017 <NAME>, SpaceMadness.
//
//  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.apptentive.android.sdk.util.threading;

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

import static com.apptentive.android.sdk.debug.Assert.assertNotNull;

/**
 * {@link DispatchQueue} implementation using {@link Handler}
 */
class HandlerDispatchQueue extends DispatchQueue {
	private final Handler handler;
	private final HandlerThread handlerThread;

	/**
	 * Creates a private queue with specified <code>name</code>
	 */
	public HandlerDispatchQueue(String name) {
		handlerThread = new HandlerThread(name);
		handlerThread.start();
		handler = new Handler(handlerThread.getLooper());
	}

	/**
	 * Creates a queue with specified <code>looper</code>
	 */
	public HandlerDispatchQueue(Looper looper) {
		if (looper == null) {
			throw new NullPointerException("Looper is null");
		}
		handler = new Handler(looper);
		handlerThread = null; // non-private queue (no explicit thread)
	}

	@Override
	protected void dispatch(DispatchTask task, long delayMillis) {
		if (delayMillis > 0) {
			handler.postDelayed(task, delayMillis);
		} else {
			handler.post(task);
		}
	}

	@Override
	public void stop() {
		assertNotNull(handlerThread, "Attempted to stop a non-private queue '%s'", handler.getLooper().getThread());
		if (handlerThread != null) {
			handler.removeCallbacks(null);
			handlerThread.quit();
		}
	}
}
{'fraction_non_alphanumeric': 0.1124021816457197, 'fraction_numerical': 0.004031301873369694, 'mean_word_length': 3.933333333333333, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 2, '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': '6207475', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1202, 'n_words': 388}