|
| 1 | +package net.sharksystem.asap.listenermanager; |
| 2 | + |
| 3 | +import net.sharksystem.asap.*; |
| 4 | + |
| 5 | +import java.util.HashMap; |
| 6 | + |
| 7 | +public class ASAPChannelContentChangedListenerManager implements ASAPChannelContentChangedListenerManagement { |
| 8 | + private HashMap<CharSequence, GenericListenerImplementation<ASAPChannelContentChangedListener>> listenerMap = |
| 9 | + new HashMap(); |
| 10 | + |
| 11 | + @Override |
| 12 | + public void addASAPChannelContentChangedListener(CharSequence format, ASAPChannelContentChangedListener listener) { |
| 13 | + GenericListenerImplementation<ASAPChannelContentChangedListener> listenerList = this.listenerMap.get(format); |
| 14 | + if(listenerList == null) { |
| 15 | + listenerList = new GenericListenerImplementation<ASAPChannelContentChangedListener>(); |
| 16 | + this.listenerMap.put(format, listenerList); |
| 17 | + } |
| 18 | + |
| 19 | + listenerList.addListener(listener); |
| 20 | + } |
| 21 | + |
| 22 | + @Override |
| 23 | + public void removeASAPChannelContentChangedListener(CharSequence format, ASAPChannelContentChangedListener listener) { |
| 24 | + GenericListenerImplementation<ASAPChannelContentChangedListener> listenerList = this.listenerMap.get(format); |
| 25 | + if(listenerList != null) { |
| 26 | + listenerList.removeListener(listener); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public int getNumberListener() { |
| 31 | + if(this.listenerMap == null) return 0; |
| 32 | + return this.listenerMap.size(); |
| 33 | + } |
| 34 | + |
| 35 | + public void removeAllListeners() { |
| 36 | + // reset |
| 37 | + this.listenerMap = new HashMap(); |
| 38 | + } |
| 39 | + |
| 40 | + public void notifyChanged(CharSequence format, CharSequence uri, int era) { |
| 41 | + |
| 42 | + this.notifyChanged(format, uri, era, false); |
| 43 | + } |
| 44 | + |
| 45 | + public void notifyChanged(CharSequence format, CharSequence uri, int era, boolean useThreads) { |
| 46 | + |
| 47 | + GenericListenerImplementation<ASAPChannelContentChangedListener> listenerList = this.listenerMap.get(format); |
| 48 | + if(listenerList != null) { |
| 49 | + ASAPChannelContentChangedListenerManager.ASAPChannelContentChangedNotifier notifier |
| 50 | + = new ASAPChannelContentChangedListenerManager.ASAPChannelContentChangedNotifier(format, uri, era); |
| 51 | + |
| 52 | + listenerList.notifyAll(notifier, useThreads); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public class ASAPChannelContentChangedNotifier implements GenericNotifier<ASAPChannelContentChangedListener> { |
| 57 | + private CharSequence format; |
| 58 | + private CharSequence uri; |
| 59 | + private int era; |
| 60 | + |
| 61 | + ASAPChannelContentChangedNotifier(CharSequence format, CharSequence uri, int era) { |
| 62 | + this.format = format; |
| 63 | + this.uri = uri; |
| 64 | + this.era = era; |
| 65 | + } |
| 66 | + |
| 67 | + public void doNotify(ASAPChannelContentChangedListener listener) { |
| 68 | + listener.asapChannelContentChanged(this.format, this.uri, this.era); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments