//# 0 errors, 190 messages
//#
/*
    //#ListenerList.java:1:1: class: com.dmdirc.util.ListenerList
    //#ListenerList.java:1:1: method: com.dmdirc.util.ListenerList.com.dmdirc.util.ListenerList__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.util;

import java.util.List;

/**
 * Represents a list of event listeners, similar to EventListenerList, but
 * not swing specific.
 * 
 * @author chris
 */
public class ListenerList {
    
    /** The map of class->listener or string->listener that we're using. */
    private final MapList<Object, Object> listeners
            = new MapList<Object, Object>();
    
    /**
     * Creates a new instance of ListenerList.
     */
    public ListenerList() {
    //#ListenerList.java:42: method: void com.dmdirc.util.ListenerList.com.dmdirc.util.ListenerList()
    //#input(void com.dmdirc.util.ListenerList()): this
    //#output(void com.dmdirc.util.ListenerList()): new HashMap(MapList#1) num objects
    //#output(void com.dmdirc.util.ListenerList()): new MapList(ListenerList#1) num objects
    //#output(void com.dmdirc.util.ListenerList()): this.listeners.__Tag
    //#output(void com.dmdirc.util.ListenerList()): this.listeners.map
    //#output(void com.dmdirc.util.ListenerList()): this.listeners
    //#new obj(void com.dmdirc.util.ListenerList()): new HashMap(MapList#1)
    //#new obj(void com.dmdirc.util.ListenerList()): new MapList(ListenerList#1)
    //#post(void com.dmdirc.util.ListenerList()): this.listeners == &new MapList(ListenerList#1)
    //#post(void com.dmdirc.util.ListenerList()): new HashMap(MapList#1) num objects == 1
    //#post(void com.dmdirc.util.ListenerList()): new MapList(ListenerList#1) num objects == 1
    //#post(void com.dmdirc.util.ListenerList()): this.listeners.__Tag == com/dmdirc/util/MapList
    //#post(void com.dmdirc.util.ListenerList()): this.listeners.map == &new HashMap(MapList#1)
    //#unanalyzed(void com.dmdirc.util.ListenerList()): Effects-of-calling:java.util.HashMap
        // Do nothing
    }
    //#ListenerList.java:44: end of method: void com.dmdirc.util.ListenerList.com.dmdirc.util.ListenerList()
    
    /**
     * Adds a new listener of the specified type to this listener list.
     * 
     * @param listenerType The type of listener to be added
     * @param listener The listener to be added
     */
    public <T> void add(final Class<T> listenerType, final T listener) {
        listeners.add(listenerType, listener);
    //#ListenerList.java:53: method: void com.dmdirc.util.ListenerList.add(Class, Object)
    //#ListenerList.java:53: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: void add(Class, Object)
    //#    suspicious precondition index: [5]
    //#input(void add(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(void add(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(void add(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(void add(Class, Object)): com/dmdirc/util/MapList.__Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void add(Class, Object)): com/dmdirc/util/MapList.__Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List;
    //#input(void add(Class, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void add(Class, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List;
    //#input(void add(Class, Object)): listener
    //#input(void add(Class, Object)): listenerType
    //#input(void add(Class, Object)): this
    //#input(void add(Class, Object)): this.listeners
    //#input(void add(Class, Object)): this.listeners.__Tag
    //#input(void add(Class, Object)): this.listeners.map
    //#pre[4] (void add(Class, Object)): this.listeners != null
    //#pre[5] (void add(Class, Object)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[6] (void add(Class, Object)): this.listeners.map != null
    //#unanalyzed(void add(Class, Object)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(void add(Class, Object)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void add(Class, Object)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void add(Class, Object)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(void add(Class, Object)): Effects-of-calling:java.util.List:add
    }
    //#ListenerList.java:54: end of method: void com.dmdirc.util.ListenerList.add(Class, Object)
    
    /**
     * Adds a new listener of the specified type to this listener list.
     * 
     * @param listenerType The name of the type of listener that's being added
     * @param listener The listener to be added
     */
    public void add(final String listenerType, final Object listener) {
        listeners.add(listenerType, listener);
    //#ListenerList.java:63: method: void com.dmdirc.util.ListenerList.add(String, Object)
    //#ListenerList.java:63: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: void add(String, Object)
    //#    suspicious precondition index: [5]
    //#input(void add(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(void add(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(void add(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(void add(String, Object)): com/dmdirc/util/MapList.__Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void add(String, Object)): com/dmdirc/util/MapList.__Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List;
    //#input(void add(String, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void add(String, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List;
    //#input(void add(String, Object)): listener
    //#input(void add(String, Object)): listenerType
    //#input(void add(String, Object)): this
    //#input(void add(String, Object)): this.listeners
    //#input(void add(String, Object)): this.listeners.__Tag
    //#input(void add(String, Object)): this.listeners.map
    //#pre[4] (void add(String, Object)): this.listeners != null
    //#pre[5] (void add(String, Object)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[6] (void add(String, Object)): this.listeners.map != null
    //#unanalyzed(void add(String, Object)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(void add(String, Object)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void add(String, Object)): Effects-of-calling:java.util.ArrayList
    //#unanalyzed(void add(String, Object)): Effects-of-calling:java.util.Map:put
    //#unanalyzed(void add(String, Object)): Effects-of-calling:java.util.List:add
    }
    //#ListenerList.java:64: end of method: void com.dmdirc.util.ListenerList.add(String, Object)
    
    /**
     * Removes the specified listener from the list of listeners for the
     * specified type.
     * 
     * @param listenerType The type that the listener should be removed from
     * @param listener The listener to be removed
     */
    public <T> void remove(final Class<T> listenerType, final T listener) {
        listeners.remove(listenerType, listener);
    //#ListenerList.java:74: method: void com.dmdirc.util.ListenerList.remove(Class, Object)
    //#ListenerList.java:74: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: void remove(Class, Object)
    //#    suspicious precondition index: [5]
    //#input(void remove(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(void remove(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(void remove(Class, Object)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(void remove(Class, Object)): com/dmdirc/util/MapList.__Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void remove(Class, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void remove(Class, Object)): listener
    //#input(void remove(Class, Object)): listenerType
    //#input(void remove(Class, Object)): this
    //#input(void remove(Class, Object)): this.listeners
    //#input(void remove(Class, Object)): this.listeners.__Tag
    //#input(void remove(Class, Object)): this.listeners.map
    //#pre[4] (void remove(Class, Object)): this.listeners != null
    //#pre[5] (void remove(Class, Object)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[6] (void remove(Class, Object)): this.listeners.map != null
    //#unanalyzed(void remove(Class, Object)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(void remove(Class, Object)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void remove(Class, Object)): Effects-of-calling:java.util.List:remove
    }
    //#ListenerList.java:75: end of method: void com.dmdirc.util.ListenerList.remove(Class, Object)
    
    /**
     * Removes the specified listener from the list of listeners for the
     * specified type.
     * 
     * @param listenerType The name of the type that the listener should be
     * removed from
     * @param listener The listener to be removed
     */
    public void remove(final String listenerType, final Object listener) {
        listeners.remove(listenerType, listener);
    //#ListenerList.java:86: method: void com.dmdirc.util.ListenerList.remove(String, Object)
    //#ListenerList.java:86: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: void remove(String, Object)
    //#    suspicious precondition index: [5]
    //#input(void remove(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(void remove(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(void remove(String, Object)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(void remove(String, Object)): com/dmdirc/util/MapList.__Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void remove(String, Object)): com/dmdirc/util/WeakMapList.__Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V
    //#input(void remove(String, Object)): listener
    //#input(void remove(String, Object)): listenerType
    //#input(void remove(String, Object)): this
    //#input(void remove(String, Object)): this.listeners
    //#input(void remove(String, Object)): this.listeners.__Tag
    //#input(void remove(String, Object)): this.listeners.map
    //#pre[4] (void remove(String, Object)): this.listeners != null
    //#pre[5] (void remove(String, Object)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[6] (void remove(String, Object)): this.listeners.map != null
    //#unanalyzed(void remove(String, Object)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(void remove(String, Object)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(void remove(String, Object)): Effects-of-calling:java.util.List:remove
    }
    //#ListenerList.java:87: end of method: void com.dmdirc.util.ListenerList.remove(String, Object)
    
    /**
     * Retrieves the list of listeners for the specified type.
     * 
     * @param listenerType The type of listener that's being retrieved
     * @return A list of listeners for the specified type
     */
    @SuppressWarnings("unchecked")
    public <T> List<T> get(final Class<T> listenerType) {
        if (listeners.containsKey(listenerType)) {
    //#ListenerList.java:97: method: List com.dmdirc.util.ListenerList.get(Class)
    //#ListenerList.java:97: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: List get(Class)
    //#    suspicious precondition index: [4]
    //#input(List get(Class)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(List get(Class)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(List get(Class)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(List get(Class)): com/dmdirc/util/MapList.__Dispatch_Table.containsKey(Ljava/lang/Object;)Z
    //#input(List get(Class)): com/dmdirc/util/MapList.__Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List;
    //#input(List get(Class)): com/dmdirc/util/WeakMapList.__Dispatch_Table.containsKey(Ljava/lang/Object;)Z
    //#input(List get(Class)): com/dmdirc/util/WeakMapList.__Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List;
    //#input(List get(Class)): listenerType
    //#input(List get(Class)): this
    //#input(List get(Class)): this.listeners
    //#input(List get(Class)): this.listeners.__Tag
    //#input(List get(Class)): this.listeners.map
    //#output(List get(Class)): new ArrayList(WeakList#1) num objects
    //#output(List get(Class)): new WeakList(get#1) num objects
    //#output(List get(Class)): new WeakList(get#1).__Tag
    //#output(List get(Class)): new WeakList(get#1).list
    //#output(List get(Class)): return_value
    //#new obj(List get(Class)): new ArrayList(WeakList#1)
    //#new obj(List get(Class)): new WeakList(get#1)
    //#pre[3] (List get(Class)): this.listeners != null
    //#pre[4] (List get(Class)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[5] (List get(Class)): this.listeners.map != null
    //#post(List get(Class)): init'ed(return_value)
    //#post(List get(Class)): new ArrayList(WeakList#1) num objects <= 1
    //#post(List get(Class)): new WeakList(get#1) num objects <= 1
    //#post(List get(Class)): new WeakList(get#1).__Tag == com/dmdirc/util/WeakList
    //#post(List get(Class)): new WeakList(get#1).list == &new ArrayList(WeakList#1)
    //#unanalyzed(List get(Class)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(List get(Class)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(List get(Class)): Effects-of-calling:java.util.ArrayList
    //#test_vector(List get(Class)): java.util.Map:containsKey(...)@84: {0}, {1}
            return (List<T>) listeners.get(listenerType);
        } else {
            return new WeakList<T>();
    //#ListenerList.java:100: end of method: List com.dmdirc.util.ListenerList.get(Class)
        }
    }
    
    /**
     * Retrieves the list of listeners for the specified type.
     * 
     * @param listenerType The type of listener to be retrieved
     * @return A list of listeners for the specified type
     */
    public List<Object> get(final String listenerType) {
        if (listeners.containsKey(listenerType)) {
    //#ListenerList.java:111: method: List com.dmdirc.util.ListenerList.get(String)
    //#ListenerList.java:111: Warning: suspicious precondition
    //#    The precondition for this.listeners.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.util.ListenerList
    //#    method: List get(String)
    //#    suspicious precondition index: [4]
    //#input(List get(String)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/MapList]
    //#input(List get(String)): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#input(List get(String)): com/dmdirc/util/MapList.__Descendant_Table[others]
    //#input(List get(String)): com/dmdirc/util/MapList.__Dispatch_Table.containsKey(Ljava/lang/Object;)Z
    //#input(List get(String)): com/dmdirc/util/MapList.__Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List;
    //#input(List get(String)): com/dmdirc/util/WeakMapList.__Dispatch_Table.containsKey(Ljava/lang/Object;)Z
    //#input(List get(String)): com/dmdirc/util/WeakMapList.__Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List;
    //#input(List get(String)): listenerType
    //#input(List get(String)): this
    //#input(List get(String)): this.listeners
    //#input(List get(String)): this.listeners.__Tag
    //#input(List get(String)): this.listeners.map
    //#output(List get(String)): new ArrayList(WeakList#1) num objects
    //#output(List get(String)): new WeakList(get#1) num objects
    //#output(List get(String)): new WeakList(get#1).__Tag
    //#output(List get(String)): new WeakList(get#1).list
    //#output(List get(String)): return_value
    //#new obj(List get(String)): new ArrayList(WeakList#1)
    //#new obj(List get(String)): new WeakList(get#1)
    //#pre[3] (List get(String)): this.listeners != null
    //#pre[4] (List get(String)): this.listeners.__Tag in {com/dmdirc/util/MapList, com/dmdirc/util/WeakMapList}
    //#pre[5] (List get(String)): this.listeners.map != null
    //#post(List get(String)): init'ed(return_value)
    //#post(List get(String)): new ArrayList(WeakList#1) num objects <= 1
    //#post(List get(String)): new WeakList(get#1) num objects <= 1
    //#post(List get(String)): new WeakList(get#1).__Tag == com/dmdirc/util/WeakList
    //#post(List get(String)): new WeakList(get#1).list == &new ArrayList(WeakList#1)
    //#unanalyzed(List get(String)): Effects-of-calling:java.util.Map:containsKey
    //#unanalyzed(List get(String)): Effects-of-calling:java.util.Map:get
    //#unanalyzed(List get(String)): Effects-of-calling:java.util.ArrayList
    //#test_vector(List get(String)): java.util.Map:containsKey(...)@84: {0}, {1}
            return listeners.get(listenerType);
        } else {
            return new WeakList<Object>();
    //#ListenerList.java:114: end of method: List com.dmdirc.util.ListenerList.get(String)
        }
    }

}
    //#output(com.dmdirc.util.ListenerList__static_init): __Descendant_Table[com/dmdirc/util/ListenerList]
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.add(Ljava/lang/Class;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.add(Ljava/lang/String;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.get(Ljava/lang/Class;)Ljava/util/List;
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.get(Ljava/lang/String;)Ljava/util/List;
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.remove(Ljava/lang/Class;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.remove(Ljava/lang/String;Ljava/lang/Object;)V
    //#post(com.dmdirc.util.ListenerList__static_init): __Descendant_Table[com/dmdirc/util/ListenerList] == &__Dispatch_Table
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.add(Ljava/lang/Class;Ljava/lang/Object;)V == &add
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.add(Ljava/lang/String;Ljava/lang/Object;)V == &add
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.get(Ljava/lang/Class;)Ljava/util/List; == &get
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.get(Ljava/lang/String;)Ljava/util/List; == &get
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.remove(Ljava/lang/Class;Ljava/lang/Object;)V == &remove
    //#post(com.dmdirc.util.ListenerList__static_init): __Dispatch_Table.remove(Ljava/lang/String;Ljava/lang/Object;)V == &remove
    //#ListenerList.java:: end of method: com.dmdirc.util.ListenerList.com.dmdirc.util.ListenerList__static_init
    //#ListenerList.java:: end of class: com.dmdirc.util.ListenerList
