<commit_before>/**
 * Copyright 2013 <NAME>
 * 
 * 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 org.droidparts.bus;

import static java.lang.String.format;
import static org.droidparts.inner.ClassSpecRegistry.getReceiveEventsSpecs;

import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;

import org.droidparts.inner.ann.MethodSpec;
import org.droidparts.inner.ann.bus.ReceiveEventsAnn;
import org.droidparts.util.L;

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

public class EventBus {

	private static final String ALL = "_all_";

	private static final ConcurrentHashMap<String, ConcurrentHashMap<EventReceiver<Object>, Boolean>> eventNameToReceivers = new ConcurrentHashMap<String, ConcurrentHashMap<EventReceiver<Object>, Boolean>>();
	private static final ConcurrentHashMap<String, Object> stickyEvents = new ConcurrentHashMap<String, Object>();

	public static void postEvent(String name) {
		postEvent(name, null);
	}

	public static void postEvent(String name, Object data) {
		runOnUiThread(new PostEventRunnable(name, data));
	}

	public static void postEventSticky(String name) {
		postEventSticky(name, null);
	}

	public static void postEventSticky(String name, Object data) {
		stickyEvents.put(name, data);
		postEvent(name, data);
	}

	public void clearStickyEvents(String... eventNames) {
		boolean allEvents = (eventNames.length == 0);
		if (allEvents) {
			stickyEvents.clear();
		} else {
			HashSet<String> nameSet = new HashSet<String>(
					Arrays.asList(eventNames));
			for (String eventName : stickyEvents.keySet()) {
				if (nameSet.contains(eventName)) {
					stickyEvents.remove(eventName);
					break;
				}
			}
		}
	}

	public static void registerReceiver(EventReceiver<?> receiver,
			String... eventNames) {
		@SuppressWarnings("unchecked")
		EventReceiver<Object> rec = (EventReceiver<Object>) receiver;
		boolean allEvents = (eventNames.length == 0);
		if (allEvents) {
			for (String name : stickyEvents.keySet()) {
				notifyReceiver(rec, name, stickyEvents.get(name));
			}<commit_msg>EventBus: made clearStickyEvents() static. #17<commit_after>/**
 * Copyright 2013 <NAME>
 * 
 * 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 org.droidparts.bus;

import static java.lang.String.format;
import static org.droidparts.inner.ClassSpecRegistry.getReceiveEventsSpecs;

import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;

import org.droidparts.inner.ann.MethodSpec;
import org.droidparts.inner.ann.bus.ReceiveEventsAnn;
import org.droidparts.util.L;

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

public class EventBus {

	private static final String ALL = "_all_";

	private static final ConcurrentHashMap<String, ConcurrentHashMap<EventReceiver<Object>, Boolean>> eventNameToReceivers = new ConcurrentHashMap<String, ConcurrentHashMap<EventReceiver<Object>, Boolean>>();
	private static final ConcurrentHashMap<String, Object> stickyEvents = new ConcurrentHashMap<String, Object>();

	public static void postEvent(String name) {
		postEvent(name, null);
	}

	public static void postEvent(String name, Object data) {
		runOnUiThread(new PostEventRunnable(name, data));
	}

	public static void postEventSticky(String name) {
		postEventSticky(name, null);
	}

	public static void postEventSticky(String name, Object data) {
		stickyEvents.put(name, data);
		postEvent(name, data);
	}

	public static void clearStickyEvents(String... eventNames) {
		boolean allEvents = (eventNames.length == 0);
		if (allEvents) {
			stickyEvents.clear();
		} else {
			HashSet<String> nameSet = new HashSet<String>(
					Arrays.asList(eventNames));
			for (String eventName : stickyEvents.keySet()) {
				if (nameSet.contains(eventName)) {
					stickyEvents.remove(eventName);
					break;
				}
			}
		}
	}

	public static void registerReceiver(EventReceiver<?> receiver,
			String... eventNames) {
		@SuppressWarnings("unchecked")
		EventReceiver<Object> rec = (EventReceiver<Object>) receiver;
		boolean allEvents = (eventNames.length == 0);
		if (allEvents) {
			for (String name : stickyEvents.keySet()) {
				notifyReceiver(rec, name, stickyEvents.get(name));
			}
{'fraction_non_alphanumeric': 0.10414312617702448, 'fraction_numerical': 0.004143126177024482, 'mean_word_length': 4.75406283856988, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '1207987', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1538, 'n_words': 449}