From 24f406aae293903543e9008521565e1aa76c3cc9 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 5 Apr 2011 14:44:44 -0700 Subject: [PATCH] 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. --- .../com/samskivert/util/ObserverList.java | 36 ++++++++----------- .../samskivert/util/ResultListenerList.java | 4 +-- .../com/samskivert/util/WeakObserverList.java | 25 ++++++------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/samskivert/util/ObserverList.java b/src/main/java/com/samskivert/util/ObserverList.java index 10de6da7..a2fe7c9c 100644 --- a/src/main/java/com/samskivert/util/ObserverList.java +++ b/src/main/java/com/samskivert/util/ObserverList.java @@ -127,38 +127,35 @@ public abstract class ObserverList @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 ObserverList 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 ObserverList 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 ObserverList newList (Policy notifyPolicy, boolean allowDups) + public static ObserverList newList (Policy notifyPolicy) { - return new Impl(notifyPolicy, allowDups); + return new Impl(notifyPolicy); } /** @deprecated Switch to {@link Policy} constants. */ - @Deprecated public static ObserverList newList (int notifyPolicy, boolean allowDups) + @Deprecated public static ObserverList 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 } protected static class Impl extends ObserverList { - protected Impl (Policy notifyPolicy, boolean allowDups) { + protected Impl (Policy notifyPolicy) { _policy = notifyPolicy; - _allowDups = allowDups; _list = (_policy == Policy.SAFE_IN_ORDER) ? new CopyOnWriteArrayList() : new ArrayList(); } @@ -278,12 +274,11 @@ public abstract class ObserverList 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 /** 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 _list; } diff --git a/src/main/java/com/samskivert/util/ResultListenerList.java b/src/main/java/com/samskivert/util/ResultListenerList.java index a5a38b14..ec354edd 100644 --- a/src/main/java/com/samskivert/util/ResultListenerList.java +++ b/src/main/java/com/samskivert/util/ResultListenerList.java @@ -31,7 +31,7 @@ public class ResultListenerList extends ObserverList.Impl> */ public ResultListenerList () { - super(Policy.FAST_UNSAFE, false); + super(Policy.FAST_UNSAFE); } /** @@ -39,7 +39,7 @@ public class ResultListenerList extends ObserverList.Impl> */ public ResultListenerList (Policy notifyPolicy) { - super(notifyPolicy, false); + super(notifyPolicy); } /** diff --git a/src/main/java/com/samskivert/util/WeakObserverList.java b/src/main/java/com/samskivert/util/WeakObserverList.java index 74143a29..be889378 100644 --- a/src/main/java/com/samskivert/util/WeakObserverList.java +++ b/src/main/java/com/samskivert/util/WeakObserverList.java @@ -33,30 +33,27 @@ import com.samskivert.util.ObserverList.ObserverOp; public class WeakObserverList extends ObserverList { /** - * 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 WeakObserverList 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 WeakObserverList 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 WeakObserverList newList (Policy notifyPolicy, boolean allowDups) + public static WeakObserverList newList (Policy notifyPolicy) { - return new WeakObserverList(notifyPolicy, allowDups); + return new WeakObserverList(notifyPolicy); } @Override public boolean add (int index, T element) @@ -103,9 +100,9 @@ public class WeakObserverList extends ObserverList }); } - protected WeakObserverList (Policy notifyPolicy, boolean allowDups) + protected WeakObserverList (Policy notifyPolicy) { - _delegate = new WrappedList(notifyPolicy, allowDups); + _delegate = new WrappedList(notifyPolicy); } /** @@ -133,8 +130,8 @@ public class WeakObserverList extends ObserverList */ protected static class WrappedList extends ObserverList.Impl> { - public WrappedList (Policy notifyPolicy, boolean allowDups) { - super(notifyPolicy, allowDups); + public WrappedList (Policy notifyPolicy) { + super(notifyPolicy); } @Override protected int indexOf (WeakReference ref) {