Added static constructor methods that make ObserverList construction
substantially less keystroke intensive. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2322 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -673,6 +673,5 @@ public class RadialMenu
|
||||
protected MouseHijacker _hijacker;
|
||||
|
||||
/** Maintains a list of action listeners. */
|
||||
protected ObserverList<ActionListener> _actlist =
|
||||
new ObserverList<ActionListener>(ObserverList.SAFE_IN_ORDER_NOTIFY);
|
||||
protected ObserverList<ActionListener> _actlist = ObserverList.createSafeInOrder();
|
||||
}
|
||||
|
||||
@@ -120,6 +120,33 @@ public class ObserverList<T> extends ArrayList<T>
|
||||
* in the list during a notification call. */
|
||||
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.
|
||||
*/
|
||||
public static <T> ObserverList<T> createSafeInOrder ()
|
||||
{
|
||||
return new ObserverList<T>(SAFE_IN_ORDER_NOTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
*/
|
||||
public static <T> ObserverList<T> createFastUnsafe ()
|
||||
{
|
||||
return new ObserverList<T>(FAST_UNSAFE_NOTIFY);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for creating an observer list that avoids duplicating the type
|
||||
* parameter on the right hand side.
|
||||
*/
|
||||
public static <T> ObserverList<T> create (int notifyPolicy, boolean allowDups)
|
||||
{
|
||||
return new ObserverList<T>(notifyPolicy, allowDups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty observer list with the supplied notification
|
||||
* policy and that only allows observers to observe the list once.
|
||||
|
||||
@@ -38,10 +38,12 @@ public class ObserverListTest extends TestCase
|
||||
public void runTest ()
|
||||
{
|
||||
// Log.info("Testing safe list.");
|
||||
testList(new ObserverList<TestObserver>(ObserverList.SAFE_IN_ORDER_NOTIFY));
|
||||
ObserverList<TestObserver> list = ObserverList.createSafeInOrder();
|
||||
testList(list);
|
||||
|
||||
// Log.info("Testing unsafe list.");
|
||||
testList(new ObserverList<TestObserver>(ObserverList.FAST_UNSAFE_NOTIFY));
|
||||
list = ObserverList.createFastUnsafe();
|
||||
testList(list);
|
||||
}
|
||||
|
||||
public void testList (final ObserverList<TestObserver> list)
|
||||
|
||||
Reference in New Issue
Block a user