From f4ba889debcd344aeac1f85b9ca635d98a359c6b Mon Sep 17 00:00:00 2001 From: mdb Date: Sat, 7 Jun 2008 10:22:14 +0000 Subject: [PATCH] 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 --- src/java/com/samskivert/swing/RadialMenu.java | 3 +-- .../com/samskivert/util/ObserverList.java | 27 +++++++++++++++++++ .../util/tests/ObserverListTest.java | 6 +++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/java/com/samskivert/swing/RadialMenu.java b/src/java/com/samskivert/swing/RadialMenu.java index 2e18029f..9201736e 100644 --- a/src/java/com/samskivert/swing/RadialMenu.java +++ b/src/java/com/samskivert/swing/RadialMenu.java @@ -673,6 +673,5 @@ public class RadialMenu protected MouseHijacker _hijacker; /** Maintains a list of action listeners. */ - protected ObserverList _actlist = - new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY); + protected ObserverList _actlist = ObserverList.createSafeInOrder(); } diff --git a/src/java/com/samskivert/util/ObserverList.java b/src/java/com/samskivert/util/ObserverList.java index b7b62f53..f522d332 100644 --- a/src/java/com/samskivert/util/ObserverList.java +++ b/src/java/com/samskivert/util/ObserverList.java @@ -120,6 +120,33 @@ public class ObserverList extends ArrayList * 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 ObserverList createSafeInOrder () + { + return new ObserverList(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 ObserverList createFastUnsafe () + { + return new ObserverList(FAST_UNSAFE_NOTIFY); + } + + /** + * A convenience method for creating an observer list that avoids duplicating the type + * parameter on the right hand side. + */ + public static ObserverList create (int notifyPolicy, boolean allowDups) + { + return new ObserverList(notifyPolicy, allowDups); + } + /** * Creates an empty observer list with the supplied notification * policy and that only allows observers to observe the list once. diff --git a/src/java/com/samskivert/util/tests/ObserverListTest.java b/src/java/com/samskivert/util/tests/ObserverListTest.java index 655a55b0..e04a9ca8 100644 --- a/src/java/com/samskivert/util/tests/ObserverListTest.java +++ b/src/java/com/samskivert/util/tests/ObserverListTest.java @@ -38,10 +38,12 @@ public class ObserverListTest extends TestCase public void runTest () { // Log.info("Testing safe list."); - testList(new ObserverList(ObserverList.SAFE_IN_ORDER_NOTIFY)); + ObserverList list = ObserverList.createSafeInOrder(); + testList(list); // Log.info("Testing unsafe list."); - testList(new ObserverList(ObserverList.FAST_UNSAFE_NOTIFY)); + list = ObserverList.createFastUnsafe(); + testList(list); } public void testList (final ObserverList list)