/*
 * CollectionHash.java
 *
 * Copyright (C) 2002-2006 Alexei Drummond and Andrew Rambaut
 *
 * This file is part of BEAST.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership and licensing.
 *
 * BEAST is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 *  BEAST is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with BEAST; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

package dr.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Hashtable;


public class CollectionHash {

    private Hashtable table;
    
    public CollectionHash() { table = new Hashtable(); }

    public void put(Object key, Object o) {
		Collection c = (Collection)table.get(key);

		if (c != null) {
		    c.add(o);
		} else {
		    Collection newc = new ArrayList();
		    newc.add(o);
		    table.put(key, newc);
		}
    }

    public Object get(Object key) {
		Collection c = (Collection)table.get(key);

		if (c == null) return null;

		return c.iterator().next();
    }

    public Enumeration keys() {
		return table.keys();
    }

    public Object[] getAll(Object key) {
		return getCollection(key).toArray();
    }

    public Collection getCollection(Object key) {
		return (Collection)table.get(key);
    }

    public int getSize(Object key) {
        Collection collection = (Collection)table.get(key);
        if (collection == null) return 0;
        return collection.size();
    }

    public void remove(Object key) {
    	table.remove(key);
    }
}

@@ -1107,16 +1107,39 @@
 able;%0A%0A%0A
+// todo not used?%0A//%0A//
 public c
@@ -1160,17 +1160,21 @@
 nHash %7B%0A
-%0A
+//%0A//
     priv
@@ -1177,16 +1177,22 @@
 private 
+final 
 Hashtabl
@@ -1204,13 +1204,13 @@
 le;%0A
-    %0A
+//%0A//
     
@@ -1262,17 +1262,21 @@
 le(); %7D%0A
-%0A
+//%0A//
     publ
@@ -1307,24 +1307,26 @@
 Object o) %7B%0A
+//
 %09%09Collection
@@ -1350,33 +1350,37 @@
 table.get(key);%0A
-%0A
+//%0A//
 %09%09if (c != null)
@@ -1382,16 +1382,18 @@
 null) %7B%0A
+//
 %09%09    c.
@@ -1400,16 +1400,18 @@
 add(o);%0A
+//
 %09%09%7D else
@@ -1413,16 +1413,18 @@
  else %7B%0A
+//
 %09%09    Co
@@ -1456,16 +1456,18 @@
 List();%0A
+//
 %09%09    ne
@@ -1477,16 +1477,18 @@
 add(o);%0A
+//
 %09%09    ta
@@ -1511,19 +1511,27 @@
 c);%0A
+//
 %09%09%7D%0A
+//
     %7D%0A
-%0A
+//%0A//
     
@@ -1562,16 +1562,18 @@
  key) %7B%0A
+//
 %09%09Collec
@@ -1609,17 +1609,21 @@
 t(key);%0A
-%0A
+//%0A//
 %09%09if (c 
@@ -1644,17 +1644,21 @@
 n null;%0A
-%0A
+//%0A//
 %09%09return
@@ -1675,31 +1675,37 @@
 r().next();%0A
+//
     %7D%0A
-%0A
+//%0A//
     public E
@@ -1720,24 +1720,26 @@
 on keys() %7B%0A
+//
 %09%09return tab
@@ -1745,31 +1745,37 @@
 ble.keys();%0A
+//
     %7D%0A
-%0A
+//%0A//
     public O
@@ -1795,32 +1795,34 @@
 l(Object key) %7B%0A
+//
 %09%09return getColl
@@ -1840,31 +1840,37 @@
 .toArray();%0A
+//
     %7D%0A
-%0A
+//%0A//
     public C
@@ -1907,16 +1907,18 @@
  key) %7B%0A
+//
 %09%09return
@@ -1946,23 +1946,29 @@
 t(key);%0A
+//
     %7D%0A
-%0A
+//%0A//
     publ
@@ -1992,24 +1992,26 @@
 ject key) %7B%0A
+//
         Coll
@@ -2054,24 +2054,26 @@
 e.get(key);%0A
+//
         if (
@@ -2102,16 +2102,18 @@
 turn 0;%0A
+//
         
@@ -2142,15 +2142,21 @@
 ();%0A
+//
     %7D%0A
-%0A
+//%0A//
     
@@ -2188,16 +2188,18 @@
  key) %7B%0A
+//
     %09tab
@@ -2214,16 +2214,20 @@
 e(key);%0A
+//
     %7D%0A
+//
 %7D%0A

comment out unused code