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;
|
@Deprecated public static final int FAST_UNSAFE_NOTIFY = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience method for creating an observer list that avoids duplicating the type
|
* Creates an observer list with {@link Policy.SAFE_IN_ORDER} notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
public static <T> ObserverList<T> newSafeInOrder ()
|
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
|
* Creates an observer list with {@link Policy.FAST_UNSAFE} notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
public static <T> ObserverList<T> newFastUnsafe ()
|
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
|
* Creates an observer list with the specified notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
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 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) {
|
switch (notifyPolicy) {
|
||||||
case SAFE_IN_ORDER_NOTIFY: return newList(Policy.SAFE_IN_ORDER, allowDups);
|
case SAFE_IN_ORDER_NOTIFY: return newList(Policy.SAFE_IN_ORDER);
|
||||||
case FAST_UNSAFE_NOTIFY: return newList(Policy.FAST_UNSAFE, allowDups);
|
case FAST_UNSAFE_NOTIFY: return newList(Policy.FAST_UNSAFE);
|
||||||
default: throw new IllegalArgumentException("Unknown policy " + notifyPolicy);
|
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 static class Impl<T> extends ObserverList<T> {
|
||||||
protected Impl (Policy notifyPolicy, boolean allowDups) {
|
protected Impl (Policy notifyPolicy) {
|
||||||
_policy = notifyPolicy;
|
_policy = notifyPolicy;
|
||||||
_allowDups = allowDups;
|
|
||||||
_list = (_policy == Policy.SAFE_IN_ORDER) ?
|
_list = (_policy == Policy.SAFE_IN_ORDER) ?
|
||||||
new CopyOnWriteArrayList<T>() : new ArrayList<T>();
|
new CopyOnWriteArrayList<T>() : new ArrayList<T>();
|
||||||
}
|
}
|
||||||
@@ -278,12 +274,11 @@ public abstract class ObserverList<T>
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true and issues a warning if this list does not allow duplicates and the
|
/** Returns true and issues a warning if the supplied observer is already in the list.
|
||||||
* supplied observer is already in the list. Returns false if the supplied observer is not
|
* Returns false if the supplied observer is not a duplicate. */
|
||||||
* a duplicate. */
|
|
||||||
protected boolean isDuplicate (T obs) {
|
protected boolean isDuplicate (T obs) {
|
||||||
// make sure we're not violating the list constraints
|
// 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,
|
log.warning("Observer attempted to observe list it's already observing!", "obs", obs,
|
||||||
new Exception());
|
new Exception());
|
||||||
return true;
|
return true;
|
||||||
@@ -294,9 +289,6 @@ public abstract class ObserverList<T>
|
|||||||
/** The notification policy. */
|
/** The notification policy. */
|
||||||
protected Policy _policy;
|
protected Policy _policy;
|
||||||
|
|
||||||
/** Whether to allow observers to observe more than once simultaneously. */
|
|
||||||
protected boolean _allowDups;
|
|
||||||
|
|
||||||
/** Our list of observers. */
|
/** Our list of observers. */
|
||||||
protected List<T> _list;
|
protected List<T> _list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ResultListenerList<T> extends ObserverList.Impl<ResultListener<T>>
|
|||||||
*/
|
*/
|
||||||
public ResultListenerList ()
|
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)
|
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>
|
public class WeakObserverList<T> extends ObserverList<T>
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A convenience method for creating an observer list that avoids duplicating the type
|
* Creates a weak observer list with {@link Policy.SAFE_IN_ORDER} notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
public static <T> WeakObserverList<T> newSafeInOrder ()
|
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
|
* Creates a weak observer list with {@link Policy.FAST_UNSAFE} notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
public static <T> WeakObserverList<T> newFastUnsafe ()
|
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
|
* Creates a weak observer list with the specified notification policy.
|
||||||
* parameter on the right hand side.
|
|
||||||
*/
|
*/
|
||||||
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)
|
@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>>
|
protected static class WrappedList<T> extends ObserverList.Impl<WeakReference<T>>
|
||||||
{
|
{
|
||||||
public WrappedList (Policy notifyPolicy, boolean allowDups) {
|
public WrappedList (Policy notifyPolicy) {
|
||||||
super(notifyPolicy, allowDups);
|
super(notifyPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected int indexOf (WeakReference<T> ref) {
|
@Override protected int indexOf (WeakReference<T> ref) {
|
||||||
|
|||||||
Reference in New Issue
Block a user