From a06c6e26d52b8c0f1f3881d664bd85170959300b Mon Sep 17 00:00:00 2001 From: ray Date: Sat, 14 Aug 2004 03:18:17 +0000 Subject: [PATCH] It's an ObserverList! It's a ResultListener! It multiplexes results to many ResultListeners and still has time to keep your code clean! git-svn-id: https://samskivert.googlecode.com/svn/trunk@1487 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../samskivert/util/ResultListenerList.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/util/ResultListenerList.java diff --git a/projects/samskivert/src/java/com/samskivert/util/ResultListenerList.java b/projects/samskivert/src/java/com/samskivert/util/ResultListenerList.java new file mode 100644 index 00000000..46741666 --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/util/ResultListenerList.java @@ -0,0 +1,55 @@ +// +// $Id$ + +package com.samskivert.util; + +/** + * Multiplexes ResultListener responses to multiple ResultListeners. + */ +public class ResultListenerList extends ObserverList + implements ResultListener +{ + /** + * Create a ResultListenerList with the FAST_UNSAFE_NOTIFY policy. + */ + public ResultListenerList () + { + super(FAST_UNSAFE_NOTIFY); + } + + /** + * Create a ResultListenerList with your own notifyPolicy. + */ + public ResultListenerList (int notifyPolicy) + { + super(notifyPolicy); + } + + /** + * Multiplex a requestCompleted response to all the ResultListeners in + * this list. + */ + public void requestCompleted (final Object result) + { + apply(new ObserverOp() { + public boolean apply (Object observer) { + ((ResultListener) observer).requestCompleted(result); + return true; + } + }); + } + + /** + * Multiplex a requestFailed response to all the ResultListeners in + * this list. + */ + public void requestFailed (final Exception cause) + { + apply(new ObserverOp() { + public boolean apply (Object observer) { + ((ResultListener) observer).requestFailed(cause); + return true; + } + }); + } +}