Removed the ability to allow duplicates. That was introduced in a fit of
waffling ages ago and has never been used, and for good reason.
This commit is contained in:
@@ -127,38 +127,35 @@ public abstract class ObserverList<T>
|
||||
@Deprecated public static final int FAST_UNSAFE_NOTIFY = 2;
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates an observer list with {@link Policy.SAFE_IN_ORDER} notification policy.
|
||||
*/
|
||||
public static <T> ObserverList<T> newSafeInOrder ()
|
||||
{
|
||||
return newList(Policy.SAFE_IN_ORDER, false);
|
||||
return newList(Policy.SAFE_IN_ORDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates an observer list with {@link Policy.FAST_UNSAFE} notification policy.
|
||||
*/
|
||||
public static <T> ObserverList<T> newFastUnsafe ()
|
||||
{
|
||||
return newList(Policy.FAST_UNSAFE, false);
|
||||
return newList(Policy.FAST_UNSAFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates an observer list with the specified notification policy.
|
||||
*/
|
||||
public static <T> ObserverList<T> newList (Policy notifyPolicy, boolean allowDups)
|
||||
public static <T> ObserverList<T> newList (Policy notifyPolicy)
|
||||
{
|
||||
return new Impl<T>(notifyPolicy, allowDups);
|
||||
return new Impl<T>(notifyPolicy);
|
||||
}
|
||||
|
||||
/** @deprecated Switch to {@link Policy} constants. */
|
||||
@Deprecated public static <T> ObserverList<T> newList (int notifyPolicy, boolean allowDups)
|
||||
@Deprecated public static <T> ObserverList<T> newList (int notifyPolicy)
|
||||
{
|
||||
switch (notifyPolicy) {
|
||||
case SAFE_IN_ORDER_NOTIFY: return newList(Policy.SAFE_IN_ORDER, allowDups);
|
||||
case FAST_UNSAFE_NOTIFY: return newList(Policy.FAST_UNSAFE, allowDups);
|
||||
case SAFE_IN_ORDER_NOTIFY: return newList(Policy.SAFE_IN_ORDER);
|
||||
case FAST_UNSAFE_NOTIFY: return newList(Policy.FAST_UNSAFE);
|
||||
default: throw new IllegalArgumentException("Unknown policy " + notifyPolicy);
|
||||
}
|
||||
}
|
||||
@@ -206,9 +203,8 @@ public abstract class ObserverList<T>
|
||||
}
|
||||
|
||||
protected static class Impl<T> extends ObserverList<T> {
|
||||
protected Impl (Policy notifyPolicy, boolean allowDups) {
|
||||
protected Impl (Policy notifyPolicy) {
|
||||
_policy = notifyPolicy;
|
||||
_allowDups = allowDups;
|
||||
_list = (_policy == Policy.SAFE_IN_ORDER) ?
|
||||
new CopyOnWriteArrayList<T>() : new ArrayList<T>();
|
||||
}
|
||||
@@ -278,12 +274,11 @@ public abstract class ObserverList<T>
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Returns true and issues a warning if this list does not allow duplicates and the
|
||||
* supplied observer is already in the list. Returns false if the supplied observer is not
|
||||
* a duplicate. */
|
||||
/** Returns true and issues a warning if the supplied observer is already in the list.
|
||||
* Returns false if the supplied observer is not a duplicate. */
|
||||
protected boolean isDuplicate (T obs) {
|
||||
// make sure we're not violating the list constraints
|
||||
if (!_allowDups && (indexOf(obs) >= 0)) {
|
||||
if (indexOf(obs) >= 0) {
|
||||
log.warning("Observer attempted to observe list it's already observing!", "obs", obs,
|
||||
new Exception());
|
||||
return true;
|
||||
@@ -294,9 +289,6 @@ public abstract class ObserverList<T>
|
||||
/** The notification policy. */
|
||||
protected Policy _policy;
|
||||
|
||||
/** Whether to allow observers to observe more than once simultaneously. */
|
||||
protected boolean _allowDups;
|
||||
|
||||
/** Our list of observers. */
|
||||
protected List<T> _list;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ResultListenerList<T> extends ObserverList.Impl<ResultListener<T>>
|
||||
*/
|
||||
public ResultListenerList ()
|
||||
{
|
||||
super(Policy.FAST_UNSAFE, false);
|
||||
super(Policy.FAST_UNSAFE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +39,7 @@ public class ResultListenerList<T> extends ObserverList.Impl<ResultListener<T>>
|
||||
*/
|
||||
public ResultListenerList (Policy notifyPolicy)
|
||||
{
|
||||
super(notifyPolicy, false);
|
||||
super(notifyPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,30 +33,27 @@ import com.samskivert.util.ObserverList.ObserverOp;
|
||||
public class WeakObserverList<T> extends ObserverList<T>
|
||||
{
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates a weak observer list with {@link Policy.SAFE_IN_ORDER} notification policy.
|
||||
*/
|
||||
public static <T> WeakObserverList<T> newSafeInOrder ()
|
||||
{
|
||||
return newList(Policy.SAFE_IN_ORDER, false);
|
||||
return newList(Policy.SAFE_IN_ORDER);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates a weak observer list with {@link Policy.FAST_UNSAFE} notification policy.
|
||||
*/
|
||||
public static <T> WeakObserverList<T> newFastUnsafe ()
|
||||
{
|
||||
return newList(Policy.FAST_UNSAFE, false);
|
||||
return newList(Policy.FAST_UNSAFE);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
* Creates a weak observer list with the specified notification policy.
|
||||
*/
|
||||
public static <T> WeakObserverList<T> newList (Policy notifyPolicy, boolean allowDups)
|
||||
public static <T> WeakObserverList<T> newList (Policy notifyPolicy)
|
||||
{
|
||||
return new WeakObserverList<T>(notifyPolicy, allowDups);
|
||||
return new WeakObserverList<T>(notifyPolicy);
|
||||
}
|
||||
|
||||
@Override public boolean add (int index, T element)
|
||||
@@ -103,9 +100,9 @@ public class WeakObserverList<T> extends ObserverList<T>
|
||||
});
|
||||
}
|
||||
|
||||
protected WeakObserverList (Policy notifyPolicy, boolean allowDups)
|
||||
protected WeakObserverList (Policy notifyPolicy)
|
||||
{
|
||||
_delegate = new WrappedList<T>(notifyPolicy, allowDups);
|
||||
_delegate = new WrappedList<T>(notifyPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,8 +130,8 @@ public class WeakObserverList<T> extends ObserverList<T>
|
||||
*/
|
||||
protected static class WrappedList<T> extends ObserverList.Impl<WeakReference<T>>
|
||||
{
|
||||
public WrappedList (Policy notifyPolicy, boolean allowDups) {
|
||||
super(notifyPolicy, allowDups);
|
||||
public WrappedList (Policy notifyPolicy) {
|
||||
super(notifyPolicy);
|
||||
}
|
||||
|
||||
@Override protected int indexOf (WeakReference<T> ref) {
|
||||
|
||||
Reference in New Issue
Block a user