//# 0 errors, 63 messages
//#
/*
    //#WeakMapList.java:1:1: class: com.dmdirc.util.WeakMapList
    //#WeakMapList.java:1:1: method: com.dmdirc.util.WeakMapList.com.dmdirc.util.WeakMapList__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;

/**
 * Wraps a Map&lt;S, List&lt;T&gt;&gt; with various convenience methods for
 * accessing the data. Implements a Map-like interface for easier transition.
 * This implementation uses WeakLists (i.e., lists of weak references) - all
 * references to values are wrapped in WeakReferences.
 * 
 * @param <S> the type of keys maintained by this map
 * @param <T> the type of mapped values
 * @author chris
 */
public class WeakMapList<S,T> extends MapList<S,T> {
    //#WeakMapList.java:37: method: void com.dmdirc.util.WeakMapList.com.dmdirc.util.WeakMapList()
    //#input(void com.dmdirc.util.WeakMapList()): this
    //#output(void com.dmdirc.util.WeakMapList()): new HashMap(MapList#1) num objects
    //#output(void com.dmdirc.util.WeakMapList()): this.map
    //#new obj(void com.dmdirc.util.WeakMapList()): new HashMap(MapList#1)
    //#post(void com.dmdirc.util.WeakMapList()): this.map == &new HashMap(MapList#1)
    //#post(void com.dmdirc.util.WeakMapList()): new HashMap(MapList#1) num objects == 1
    //#unanalyzed(void com.dmdirc.util.WeakMapList()): Effects-of-calling:java.util.HashMap
    //#WeakMapList.java:37: end of method: void com.dmdirc.util.WeakMapList.com.dmdirc.util.WeakMapList()
    
    /**
     * Retrieves the list of values associated with the specified key, creating
     * the key if neccessary.
     * 
     * @param key The key to retrieve
     * @return A list of the specified key's values
     */
    @Override
    public List<T> safeGet(final S key) {
        if (!map.containsKey(key)) {
    //#WeakMapList.java:48: method: List com.dmdirc.util.WeakMapList.safeGet(Object)
    //#input(List safeGet(Object)): key
    //#input(List safeGet(Object)): this
    //#input(List safeGet(Object)): this.map
    //#output(List safeGet(Object)): return_value
    //#pre[3] (List safeGet(Object)): this.map != null
    //#post(List safeGet(Object)): init'ed(return_value)
    //#unanalyzed(List safeGet(Object)): Effects-of-calling:java.util.ArrayList
    //#test_vector(List safeGet(Object)): java.util.Map:containsKey(...)@48: {1}, {0}
            map.put(key, new WeakList<T>());
        }
        
        return map.get(key);
    //#WeakMapList.java:52: end of method: List com.dmdirc.util.WeakMapList.safeGet(Object)
    }
}
    //#output(com.dmdirc.util.WeakMapList__static_init): __Descendant_Table[com/dmdirc/util/WeakMapList]
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;Ljava/util/Collection;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.clear()V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.clear(Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.containsKey(Ljava/lang/Object;)Z
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.containsValue(Ljava/lang/Object;Ljava/lang/Object;)Z
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.entrySet()Ljava/util/Set;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.get(Ljava/lang/Object;I)Ljava/lang/Object;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.getMap()Ljava/util/Map;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.isEmpty()Z
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.keySet()Ljava/util/Set;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.remove(Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.removeFromAll(Ljava/lang/Object;)V
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List;
    //#output(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.values(Ljava/lang/Object;)Ljava/util/Collection;
    //#output(com.dmdirc.util.WeakMapList__static_init): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList]
    //#post(com.dmdirc.util.WeakMapList__static_init): __Descendant_Table[com/dmdirc/util/WeakMapList] == &__Dispatch_Table
    //#post(com.dmdirc.util.WeakMapList__static_init): com/dmdirc/util/MapList.__Descendant_Table[com/dmdirc/util/WeakMapList] == &__Dispatch_Table
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;)V == &com/dmdirc/util/MapList.add
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;Ljava/lang/Object;)V == &com/dmdirc/util/MapList.add
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.add(Ljava/lang/Object;Ljava/util/Collection;)V == &com/dmdirc/util/MapList.add
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.clear()V == &com/dmdirc/util/MapList.clear
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.clear(Ljava/lang/Object;)V == &com/dmdirc/util/MapList.clear
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.containsKey(Ljava/lang/Object;)Z == &com/dmdirc/util/MapList.containsKey
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.containsValue(Ljava/lang/Object;Ljava/lang/Object;)Z == &com/dmdirc/util/MapList.containsValue
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.entrySet()Ljava/util/Set; == &com/dmdirc/util/MapList.entrySet
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.get(Ljava/lang/Object;)Ljava/util/List; == &com/dmdirc/util/MapList.get
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.get(Ljava/lang/Object;I)Ljava/lang/Object; == &com/dmdirc/util/MapList.get
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.getMap()Ljava/util/Map; == &com/dmdirc/util/MapList.getMap
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.isEmpty()Z == &com/dmdirc/util/MapList.isEmpty
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.keySet()Ljava/util/Set; == &com/dmdirc/util/MapList.keySet
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.remove(Ljava/lang/Object;)V == &com/dmdirc/util/MapList.remove
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.remove(Ljava/lang/Object;Ljava/lang/Object;)V == &com/dmdirc/util/MapList.remove
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.removeFromAll(Ljava/lang/Object;)V == &com/dmdirc/util/MapList.removeFromAll
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.safeGet(Ljava/lang/Object;)Ljava/util/List; == &safeGet
    //#post(com.dmdirc.util.WeakMapList__static_init): __Dispatch_Table.values(Ljava/lang/Object;)Ljava/util/Collection; == &com/dmdirc/util/MapList.values
    //#WeakMapList.java:: end of method: com.dmdirc.util.WeakMapList.com.dmdirc.util.WeakMapList__static_init
    //#WeakMapList.java:: end of class: com.dmdirc.util.WeakMapList
