mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 10:15:52 +00:00
Check for and reject null event listeners.
This commit is contained in:
parent
2879f7bb9b
commit
24d38cdba4
@ -19,19 +19,23 @@ package com.google.bitcoin.utils;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple wrapper around a listener and an executor, with some utility methods.
|
* A simple wrapper around a listener and an executor, with some utility methods.
|
||||||
*/
|
*/
|
||||||
public class ListenerRegistration<T> {
|
public class ListenerRegistration<T> {
|
||||||
public T listener;
|
public final T listener;
|
||||||
public Executor executor;
|
public final Executor executor;
|
||||||
|
|
||||||
public ListenerRegistration(T listener, Executor executor) {
|
public ListenerRegistration(T listener, Executor executor) {
|
||||||
this.listener = listener;
|
this.listener = checkNotNull(listener);
|
||||||
this.executor = executor;
|
this.executor = checkNotNull(executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> boolean removeFromList(T listener, List<? extends ListenerRegistration<T>> list) {
|
public static <T> boolean removeFromList(T listener, List<? extends ListenerRegistration<T>> list) {
|
||||||
|
checkNotNull(listener);
|
||||||
|
|
||||||
ListenerRegistration<T> item = null;
|
ListenerRegistration<T> item = null;
|
||||||
for (ListenerRegistration<T> registration : list) {
|
for (ListenerRegistration<T> registration : list) {
|
||||||
if (registration.listener == listener) {
|
if (registration.listener == listener) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user