mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 23:32:16 +00:00
Delete EventListenerInvoker, it is no longer needed.
This commit is contained in:
parent
971c9c5999
commit
b2ab3e1c43
@ -16,12 +16,10 @@
|
|||||||
|
|
||||||
package com.google.bitcoin.core;
|
package com.google.bitcoin.core;
|
||||||
|
|
||||||
import com.google.bitcoin.utils.EventListenerInvoker;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Google Inc.
|
|
||||||
*
|
|
||||||
* 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.google.bitcoin.utils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A utility class that makes it easier to run lists of event listeners that are allowed to
|
|
||||||
* delete themselves during their execution. Event listeners are locked during execution. <p>
|
|
||||||
*
|
|
||||||
* Use like this:<p>
|
|
||||||
*
|
|
||||||
* <tt><pre>
|
|
||||||
* final Foo myself = this;
|
|
||||||
* final Bar change = ...;
|
|
||||||
* EventListenerInvoker.invoke(myEventListeners, new EventListenerInvoker<FooEventListener, Void>() {
|
|
||||||
* public void invoke(FooEventListener listener) {
|
|
||||||
* listener.onSomethingChanged(myself, change);
|
|
||||||
* }
|
|
||||||
* });
|
|
||||||
* </pre></tt>
|
|
||||||
*/
|
|
||||||
public abstract class EventListenerInvoker<E> {
|
|
||||||
public abstract void invoke(E listener);
|
|
||||||
|
|
||||||
public static <E> void invoke(List<E> listeners,
|
|
||||||
EventListenerInvoker<E> invoker) {
|
|
||||||
if (listeners == null) return;
|
|
||||||
synchronized (listeners) {
|
|
||||||
for (int i = 0; i < listeners.size(); i++) {
|
|
||||||
E l = listeners.get(i);
|
|
||||||
synchronized (l) {
|
|
||||||
invoker.invoke(l);
|
|
||||||
}
|
|
||||||
if (i == listeners.size()) {
|
|
||||||
break; // Listener removed itself and it was the last one.
|
|
||||||
} else if (listeners.get(i) != l) {
|
|
||||||
i--; // Listener removed itself and it was not the last one.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user