1 package org.catacomb.interlish.content; 2 3 import org.catacomb.interlish.structure.IDd; 4 import org.catacomb.report.E; 5 6 import java.util.ArrayList; 7 import java.util.HashMap; 8 9 10 public class KeyedMultiList<V> { 11 12 ArrayList<V> items; 13 HashMap<String, ArrayList<V>> listHM; 14 15 Class itemClass; 16 17 public KeyedMultiList() { 18 items = new ArrayList<V>(); 19 listHM = new HashMap<String, ArrayList<V>>(); 20 } 21 22 public KeyedMultiList(Class c) { 23 this(); 24 itemClass = c; 25 } 26 27 28 public KeyedMultiList(String s) { 29 this(); 30 try { 31 itemClass = Class.forName(s); 32 } catch (Exception ex) { 33 E.error("cant find class " + s + " " + ex); 34 } 35 } 36 37 38 39 40 41 public ArrayList<V> getItems() { 42 return items; 43 } 44 45 public boolean hasItems(String s) { 46 return listHM.containsKey(s); 47 } 48 49 public ArrayList<V> getItems(String s) { 50 ArrayList<V> ret = null; 51 if (listHM.containsKey(s)) { 52 ret = listHM.get(s); 53 } 54 return ret; 55 } 56 57 58 59 60 public void add(V obj) { 61 items.add(obj); 62 String sid = ""; 63 if (obj instanceof IDd) { 64 sid = ((IDd)obj).getID(); 65 } else { 66 sid = obj.toString(); 67 } 68 add(sid, obj); 69 } 70 71 72 73 public void add(String sid, V obj) { 74 75 if (listHM.containsKey(sid)) { 76 (listHM.get(sid)).add(obj); 77 } else { 78 ArrayList<V> alv = new ArrayList<V>(); 79 alv.add(obj); 80 listHM.put(sid, alv); 81 } 82 } 83 84 85 }