//# 0 errors, 78 messages
//#
/*
    //#DoubleMap.java:1:1: class: com.dmdirc.util.DoubleMap
    //#DoubleMap.java:1:1: method: com.dmdirc.util.DoubleMap.com.dmdirc.util.DoubleMap__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.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * An object that maps keys to values, and values back to keys. Currently
 * does no checking for duplicates. Does not allow null values.
 * 
 * @param <A> The first type of data to be mapped
 * @param <B> The second type of data to be mapped 
 * @author chris
 */
public class DoubleMap<A,B> {
    //#DoubleMap.java:37: method: void com.dmdirc.util.DoubleMap.com.dmdirc.util.DoubleMap()
    //#input(void com.dmdirc.util.DoubleMap()): this
    //#output(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#1) num objects
    //#output(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#2) num objects
    //#output(void com.dmdirc.util.DoubleMap()): this.keys
    //#output(void com.dmdirc.util.DoubleMap()): this.values
    //#new obj(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#1)
    //#new obj(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#2)
    //#post(void com.dmdirc.util.DoubleMap()): this.keys == &new ArrayList(DoubleMap#1)
    //#post(void com.dmdirc.util.DoubleMap()): this.values == &new ArrayList(DoubleMap#2)
    //#post(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#1) num objects == 1
    //#post(void com.dmdirc.util.DoubleMap()): new ArrayList(DoubleMap#2) num objects == 1
    
    /** The keys in this map. */
    protected final List<A> keys = new ArrayList<A>();
    /** The values in this map. */
    protected final List<B> values = new ArrayList<B>();
    //#DoubleMap.java:42: end of method: void com.dmdirc.util.DoubleMap.com.dmdirc.util.DoubleMap()
    
    /**
     * Adds the specified pair to this map.
     * 
     * @param key The key for the map
     * @param value The value for the map
     */
    public void put(final A key, final B value) {
        if (key == null || value == null) {
    //#DoubleMap.java:51: method: void com.dmdirc.util.DoubleMap.put(Object, Object)
    //#input(void put(Object, Object)): key
    //#input(void put(Object, Object)): this
    //#input(void put(Object, Object)): this.keys
    //#input(void put(Object, Object)): this.values
    //#input(void put(Object, Object)): value
    //#pre[1] (void put(Object, Object)): key != null
    //#pre[3] (void put(Object, Object)): this.keys != null
    //#pre[4] (void put(Object, Object)): this.values != null
    //#pre[5] (void put(Object, Object)): value != null
            throw new NullPointerException();
        }
        
        keys.add(key);
        values.add(value);
    }
    //#DoubleMap.java:57: end of method: void com.dmdirc.util.DoubleMap.put(Object, Object)
    
    /**
     * Retrieves the value associated with the specified key.
     * 
     * @param key The key to search for 
     * @return The value of the specified key
     */
    public B getValue(final A key) {
        return values.get(keys.indexOf(key));
    //#DoubleMap.java:66: method: Object com.dmdirc.util.DoubleMap.getValue(Object)
    //#input(Object getValue(Object)): key
    //#input(Object getValue(Object)): this
    //#input(Object getValue(Object)): this.keys
    //#input(Object getValue(Object)): this.values
    //#output(Object getValue(Object)): return_value
    //#pre[3] (Object getValue(Object)): this.keys != null
    //#pre[4] (Object getValue(Object)): this.values != null
    //#post(Object getValue(Object)): init'ed(return_value)
    //#DoubleMap.java:66: end of method: Object com.dmdirc.util.DoubleMap.getValue(Object)
    }
    
    /**
     * Retrieves the key associated with the specified value.
     * 
     * @param value The value to search for
     * @return The key of the specified value
     */
    public A getKey(final B value) {
        return keys.get(values.indexOf(value));
    //#DoubleMap.java:76: method: Object com.dmdirc.util.DoubleMap.getKey(Object)
    //#input(Object getKey(Object)): this
    //#input(Object getKey(Object)): this.keys
    //#input(Object getKey(Object)): this.values
    //#input(Object getKey(Object)): value
    //#output(Object getKey(Object)): return_value
    //#pre[2] (Object getKey(Object)): this.keys != null
    //#pre[3] (Object getKey(Object)): this.values != null
    //#post(Object getKey(Object)): init'ed(return_value)
    //#DoubleMap.java:76: end of method: Object com.dmdirc.util.DoubleMap.getKey(Object)
    }
    
    /**
     * Retrieves the set of keys in this double map.
     * 
     * @return This map's key set
     */
    public Set<A> keySet() {
        return new HashSet<A>(keys);
    //#DoubleMap.java:85: method: Set com.dmdirc.util.DoubleMap.keySet()
    //#input(Set keySet()): this
    //#input(Set keySet()): this.keys
    //#output(Set keySet()): new HashSet(keySet#1) num objects
    //#output(Set keySet()): return_value
    //#new obj(Set keySet()): new HashSet(keySet#1)
    //#post(Set keySet()): return_value == &new HashSet(keySet#1)
    //#post(Set keySet()): new HashSet(keySet#1) num objects == 1
    //#DoubleMap.java:85: end of method: Set com.dmdirc.util.DoubleMap.keySet()
    }
    
    /**
     * Retrieves the set of values in this double map.
     * 
     * @return This map's value set
     */
    public Set<B> valueSet() {
        return new HashSet<B>(values);
    //#DoubleMap.java:94: method: Set com.dmdirc.util.DoubleMap.valueSet()
    //#input(Set valueSet()): this
    //#input(Set valueSet()): this.values
    //#output(Set valueSet()): new HashSet(valueSet#1) num objects
    //#output(Set valueSet()): return_value
    //#new obj(Set valueSet()): new HashSet(valueSet#1)
    //#post(Set valueSet()): return_value == &new HashSet(valueSet#1)
    //#post(Set valueSet()): new HashSet(valueSet#1) num objects == 1
    //#DoubleMap.java:94: end of method: Set com.dmdirc.util.DoubleMap.valueSet()
    }

}
    //#output(com.dmdirc.util.DoubleMap__static_init): __Descendant_Table[com/dmdirc/util/DoubleMap]
    //#output(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.getKey(Ljava/lang/Object;)Ljava/lang/Object;
    //#output(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.getValue(Ljava/lang/Object;)Ljava/lang/Object;
    //#output(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.keySet()Ljava/util/Set;
    //#output(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.put(Ljava/lang/Object;Ljava/lang/Object;)V
    //#output(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.valueSet()Ljava/util/Set;
    //#post(com.dmdirc.util.DoubleMap__static_init): __Descendant_Table[com/dmdirc/util/DoubleMap] == &__Dispatch_Table
    //#post(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.getKey(Ljava/lang/Object;)Ljava/lang/Object; == &getKey
    //#post(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.getValue(Ljava/lang/Object;)Ljava/lang/Object; == &getValue
    //#post(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.keySet()Ljava/util/Set; == &keySet
    //#post(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.put(Ljava/lang/Object;Ljava/lang/Object;)V == &put
    //#post(com.dmdirc.util.DoubleMap__static_init): __Dispatch_Table.valueSet()Ljava/util/Set; == &valueSet
    //#DoubleMap.java:: end of method: com.dmdirc.util.DoubleMap.com.dmdirc.util.DoubleMap__static_init
    //#DoubleMap.java:: end of class: com.dmdirc.util.DoubleMap
